Skip to content

Commit

Permalink
GroovyServices: when creating Diagnostic for SyntaxException, create …
Browse files Browse the repository at this point in the history
…fallback Range when SyntaxException doesn't have a valid line (closes #91)
  • Loading branch information
joshtynjala committed Jun 28, 2024
1 parent 6b6a8a2 commit 7be0244
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/prominic/groovyls/GroovyServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ private Set<PublishDiagnosticsParams> handleErrorCollector(ErrorCollector collec
SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message;
SyntaxException cause = syntaxErrorMessage.getCause();
Range range = GroovyLanguageServerUtils.syntaxExceptionToRange(cause);
if (range == null) {
// range can't be null in a Diagnostic, so we need
// a fallback
range = new Range(new Position(0, 0), new Position(0, 0));
}
Diagnostic diagnostic = new Diagnostic();
diagnostic.setRange(range);
diagnostic.setSeverity(cause.isFatal() ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning);
Expand Down

0 comments on commit 7be0244

Please sign in to comment.