Skip to content
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

Draft
wants to merge 54 commits into
base: master
Choose a base branch
from

Conversation

RadCod3
Copy link

@RadCod3 RadCod3 commented Feb 28, 2024

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 in SyntaxDiagnostic.java.

Samples

Missing tokens and keywords

These type of errors are rendered as below,
Screenshot from 2024-02-28 10-02-50
Screenshot from 2024-02-28 10-03-10
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.
Screenshot from 2024-02-28 10-04-01
Screenshot from 2024-02-28 10-06-19

Other errors

Other errors in general are underlined by ^ symbols.
Screenshot from 2024-02-28 09-50-57
Screenshot from 2024-02-28 09-52-25

Multi-lined diagnostics are rendered as below. If it's more than 2 lines, the lines in between are hidden.
Screenshot from 2024-02-28 09-55-39
Screenshot from 2024-02-28 09-51-28
Screenshot from 2024-02-28 09-54-06

Remarks

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@CLAassistant
Copy link

CLAassistant commented Feb 28, 2024

CLA assistant check
All committers have signed the CLA.

@RadCod3 RadCod3 force-pushed the improved-diagnostic-rendering branch 2 times, most recently from 7e60e7e to c6fabf7 Compare March 1, 2024 04:10
@nipunayf nipunayf added the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Mar 1, 2024
@RadCod3 RadCod3 force-pushed the improved-diagnostic-rendering branch 2 times, most recently from 8c1e4d1 to d20fec1 Compare March 5, 2024 08:31
Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 92.42424% with 15 lines in your changes missing coverage. Please review.

Project coverage is 76.60%. Comparing base (148286d) to head (876501f).
Report is 459 commits behind head on master.

Current head 876501f differs from pull request most recent head 12e70f6

Please upload reports for the commit 12e70f6 to get more accurate results.

Files Patch % Lines
...ballerina/cli/diagnostics/AnnotateDiagnostics.java 89.88% 3 Missing and 6 partials ⚠️
...internal/diagnostics/StringDiagnosticProperty.java 60.00% 4 Missing ⚠️
...c/main/java/io/ballerina/cli/task/CompileTask.java 77.77% 0 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Jun 8, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Jun 8, 2024
@pcnfernando pcnfernando removed the Stale label Jun 8, 2024
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Jun 24, 2024
@nipunayf nipunayf removed the Stale label Jun 25, 2024
Copy link
Contributor

@Shadow-Devil Shadow-Devil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix checkstyle


/**
* Represents a result of truncating a line.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*
* @param needsWrap If the result needs to be wrapped

Comment on lines +192 to +194
}
else {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
else {
} else {

Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Jul 10, 2024
Copy link

Closed PR due to inactivity for more than 18 days.

@github-actions github-actions bot closed this Jul 13, 2024
@gimantha gimantha removed the Stale label Sep 6, 2024
@gimantha gimantha reopened this Sep 6, 2024
Comment on lines +6 to +10
if (a < 0) {
return 0;
} else (b < 0) {
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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";
Copy link
Contributor

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') {
Copy link
Contributor

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

@gimantha gimantha marked this pull request as draft September 10, 2024 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Diagnostics Issues related Diagnostics reported by the Compiler. #Compiler Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times.
Projects
None yet
Development

Successfully merging this pull request may close these issues.