Skip to content

Commit

Permalink
refact: improve LSPDiagnosticsToMarkers#accept
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Aug 16, 2024
1 parent 9fed5c3 commit c104a96
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
Expand All @@ -49,6 +50,7 @@
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.texteditor.MarkerUtilities;

public class LSPDiagnosticsToMarkers implements Consumer<PublishDiagnosticsParams> {
Expand Down Expand Up @@ -90,14 +92,12 @@ public void accept(PublishDiagnosticsParams diagnostics) {
if (resource != null && resource.isAccessible()) {
updateMarkers(diagnostics, resource);
} else {
LSPEclipseUtils.findOpenEditorsFor(LSPEclipseUtils.toUri(uri)).stream()
.map(reference -> reference.getEditor(true))
.filter(Objects::nonNull)
.map(LSPEclipseUtils::getTextViewer)
.filter(Objects::nonNull)
.filter(ISourceViewer.class::isInstance)
.map(ISourceViewer.class::cast)
.forEach(sourceViewer -> updateEditorAnnotations(sourceViewer, diagnostics));
for (final IEditorReference editorRef : LSPEclipseUtils.findOpenEditorsFor(LSPEclipseUtils.toUri(uri))) {
final ITextViewer textViewer = LSPEclipseUtils.getTextViewer(editorRef.getEditor(true));
if (textViewer instanceof ISourceViewer sourceViewer) {
updateEditorAnnotations(sourceViewer, diagnostics);
}
}
}
} catch (Exception ex) {
LanguageServerPlugin.logError(ex);
Expand Down

0 comments on commit c104a96

Please sign in to comment.