Skip to content

Commit

Permalink
Match diagnostics with empty ranges
Browse files Browse the repository at this point in the history
In Eclipse, we set a minimal range of 1 character, even for diagnostics
that have an empty range (just a position); so this fixes ensure such
markers and diagnostics are still matched together upon update, to avoid
re-creating diagnostics.
  • Loading branch information
mickaelistria committed Mar 28, 2023
1 parent a6189f5 commit e6884b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.lsp4e.tests.mock/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mock Language Server to test LSP4E
Bundle-SymbolicName: org.eclipse.lsp4e.tests.mock
Bundle-Version: 0.16.1.qualifier
Bundle-Version: 0.16.2.qualifier
Bundle-Vendor: Eclipse LSP4E
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.lsp4j;bundle-version="[0.20.0,0.21.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,17 @@ public void didOpen(DidOpenTextDocumentParams params) {
}

if (this.diagnostics != null && !this.diagnostics.isEmpty()) {
// 'collect(Collectors.toSet()` is added here in order to prevent a
// ConcurrentModificationException appearance
this.remoteProxies.stream().collect(Collectors.toSet()).forEach(p -> p.publishDiagnostics(
new PublishDiagnosticsParams(params.getTextDocument().getUri(), this.diagnostics)));
// we're not sure which remote proxy to use, but we know we should only use one
// per didOpen
// for proper LS interaction; so a strategy is to use the first one and rotate
// the others
// for further executions
synchronized (this.remoteProxies) {
// and we synchronize to avoid concurrent read/write on the list
this.remoteProxies.get(0).publishDiagnostics(
new PublishDiagnosticsParams(params.getTextDocument().getUri(), this.diagnostics));
Collections.rotate(this.remoteProxies, 1);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private IMarker getExistingMarkerFor(IDocument document, Diagnostic diagnostic,
for (IMarker marker : remainingMarkers) {
try {
if (LSPEclipseUtils.toOffset(diagnostic.getRange().getStart(), document) == MarkerUtilities.getCharStart(marker)
&& LSPEclipseUtils.toOffset(diagnostic.getRange().getEnd(), document) == MarkerUtilities.getCharEnd(marker)
&& (LSPEclipseUtils.toOffset(diagnostic.getRange().getEnd(), document) == MarkerUtilities.getCharEnd(marker) || Objects.equals(diagnostic.getRange().getStart(), diagnostic.getRange().getEnd()))
&& Objects.equals(marker.getAttribute(IMarker.MESSAGE), diagnostic.getMessage())
&& Objects.equals(marker.getAttribute(LANGUAGE_SERVER_ID), this.languageServerId)) {
return marker;
Expand Down

0 comments on commit e6884b1

Please sign in to comment.