-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved diagnostic rendering #42236
base: master
Are you sure you want to change the base?
Improved diagnostic rendering #42236
Conversation
bc654cc
to
4fa5982
Compare
cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
...arser/src/main/java/io/ballerina/compiler/internal/diagnostics/StringDiagnosticProperty.java
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/DiagnosticAnnotation.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/DiagnosticAnnotation.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/DiagnosticAnnotation.java
Outdated
Show resolved
Hide resolved
7e60e7e
to
c6fabf7
Compare
8c1e4d1
to
d20fec1
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42236 +/- ##
============================================
- Coverage 76.80% 76.60% -0.20%
+ Complexity 53972 53574 -398
============================================
Files 2924 2908 -16
Lines 203952 202367 -1585
Branches 26597 26354 -243
============================================
- Hits 156638 155028 -1610
- Misses 38777 38846 +69
+ Partials 8537 8493 -44 ☔ View full report in Codecov by Sentry. |
...src/test/resources/test-resources/diagnostics-test-files/bal-project-error/project2/main.bal
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/diagnostics/AnnotateDiagnostics.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/test/java/io/ballerina/cli/diagnostics/AnnotateDiagnosticsTest.java
Outdated
Show resolved
Hide resolved
Shifted from string concatenation to string builders. Combined some common login in DiagnosticAnnotation for when lines are hidden and not hidden in the multi-line diagnostic case. Also made the amount of lines to be shown before we start hiding lines configurable.
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix checkstyle
cli/ballerina-cli/src/main/java/io/ballerina/cli/diagnostics/DiagnosticAnnotation.java
Outdated
Show resolved
Hide resolved
cli/ballerina-cli/src/main/java/io/ballerina/cli/diagnostics/DiagnosticAnnotation.java
Outdated
Show resolved
Hide resolved
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
Closed PR due to inactivity for more than 18 days. |
if (a < 0) { | ||
return 0; | ||
} else (b < 0) { | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (a < 0) { | |
return 0; | |
} else (b < 0) { | |
return 0; | |
} | |
if (a < 0 || b < 0) { | |
return 0; | |
} |
private static final String INTERNAL_COLOR = "blue"; | ||
private static final String HINT_COLOR = "green"; | ||
private static final String INFO_COLOR = "blue"; | ||
private static final String WARNING_COLOR = "yellow"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option to use orange
private static int countTabChars(String line, int end) { | ||
int count = 0; | ||
for (int i = 0; i < end; i++) { | ||
if (line.charAt(i) == '\t') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can define this as a constant and use
Co-authored-by: Felix Schnabel <[email protected]>
Purpose
The purpose of this PR is to introduce an enhanced diagnostic rendering feature to the Ballerina compiler, aligning it with the standards set by the Rustc compiler. We do this by providing users with more informative and user-friendly error messages.
This addresses task 1 of #42124.
Approach
I've created a separate class to use
Diagnostic
objects and output a better error message. This is to maintain compatibility with anything else that depends on the current diagnostic implementations. Furthermore, I've used a bumped up version of jline to access a library called jansi which was merged into jline, for cross platform supported ANSI rendering.Information about what token is indeed missing was passed using the
properties()
function inSyntaxDiagnostic.java
.Samples
Missing tokens and keywords
These type of errors are rendered as below,
The
+
symbol represents that it should be newly added.Invalid tokens
Invalid tokens are highlighted in red in addition to being pointed by a
^
symbol.Other errors
Other errors in general are underlined by
^
symbols.Multi-lined diagnostics are rendered as below. If it's more than 2 lines, the lines in between are hidden.
Remarks
@|...|@
used in the code are the syntax used by jansi to render the correct ANSI escape codes. See jansi/AnsiRenderer.Check List