Skip to content

Commit

Permalink
Fix 0-length or end-of-line diagnostic position
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Sep 24, 2024
1 parent b4bfb86 commit 1a095c1
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ public JavacProblem createJavacProblem(Diagnostic<? extends JavaFileObject> diag
if (diagnosticPosition == null) {
return null;
}
if (diagnosticPosition.length == 0) {
// workaround Eclipse Platform unable to render diagnostics with length=0 or at end of line
// https://github.com/eclipse-platform/eclipse.platform.ui/issues/2321
diagnosticPosition.length++;
try {
String documentText = loadDocumentText(diagnostic);
if (diagnosticPosition.getOffset() >= documentText.length() || documentText.charAt(diagnosticPosition.getOffset()) == '\n') {
diagnosticPosition.offset--;
}
} catch (IOException ex) {
ILog.get().error(ex.getMessage(), ex);
}
}
String[] arguments = getDiagnosticStringArguments(diagnostic);
return new JavacProblem(
diagnostic.getSource().getName().toCharArray(),
Expand Down

0 comments on commit 1a095c1

Please sign in to comment.