Repository navigation
Description
Description
A diagnostic that LSP4IJ marks in an editor before it has connected the file's document stays in the editor after the connected document's own reports clear it.
When a report reaches a file whose editor is open but whose document LSP4IJ has not connected yet (a workspace diagnostic report, or a related document's report in another document's pull), updateDiagnostics takes the file as open and stores the report in an opened document that has no synchronizer:
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java
Lines 2550 to 2552 in df2fa63
| boolean isOpen = getOpenedDocument(fileUri, false) != null | |
| || FileEditorManager.getInstance(getProject()).isFileOpen(file); | |
| final LSPDocumentBase openedOrClosedDocument = isOpen ? getOpenedDocument(fileUri, true) : getClosedDocument(fileUri, true); |
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java
Lines 1825 to 1826 in df2fa63
| openedDocument = new OpenedDocument(new LanguageServerItem(languageServer, this), file, null); | |
| openedDocuments.put(fileUri, openedDocument); |
Its diagnostics changed, so LSPDiagnosticsApplier marks them in the editor:
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/OpenedDocument.java
Lines 73 to 78 in df2fa63
| if (diagnosticsForServer.update(identifier, diagnostics)) { | |
| // LSP diagnostics has changed | |
| // Schedule reactive diagnostics refresh (apply immediately without daemon restart) | |
| var project = diagnosticsForServer.getClientFeatures().getProject(); | |
| LSPDiagnosticsApplier.getInstance(project).scheduleRefresh(file, synchronizer != null ? synchronizer.getDocument() : null); |
When the file is connected, a new opened document replaces that one, with no diagnostics, and nothing refreshes the editor's marks:
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java
Lines 1448 to 1450 in df2fa63
| OpenedDocument data = new OpenedDocument(new LanguageServerItem(languageServer, this), file, synchronizer); | |
| // It replaces an opened document which held only the diagnostics published before the connection | |
| var replaced = LanguageServerWrapper.this.openedDocuments.put(fileUri, data); |
The server's later reports for the connected document are empty, which is no change to that document's (empty) diagnostics, so scheduleRefresh is never called for it; and LSPDiagnosticsPassFactory.createHighlightingPass makes no editor pass that could re-mark the file:
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsPassFactory.java
Lines 53 to 56 in df2fa63
| public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull Editor editor) { | |
| // In normal editor mode, diagnostics are applied by LSPDiagnosticsApplier (reactive) | |
| return null; | |
| } |
So the editor keeps the placeholder's error until the file's diagnostics change again, although LSP4IJ itself no longer holds it, and the Problems view no longer shows it.
Steps to reproduce
- A language server that supports workspace diagnostics (or reports related documents) answers a report that gives file
Ban error, at a moment whenB's editor is open but LSP4IJ has not yet connectedB's document, for example right after the editor opens. - The server's next reports for
B, after LSP4IJ has connected it, have no diagnostics, because the error was fixed in the meantime.
Expected: the error's mark leaves B's editor once the connected document's report is empty.
Actual: the mark stays in the editor; LSP4IJ holds no diagnostic for B, and only a later change of B's diagnostics takes the mark away.
Suggested fix
When the connection replaces an opened document that held diagnostics (replaced above), schedule a refresh of the file's marks for the new document, LSPDiagnosticsApplier.getInstance(project).scheduleRefresh(file, document), so that the editor shows what the connected document holds.
Context
Found with the Ecstasy language server's IntelliJ tests: a workspace report, asked while a dependent file was closed and its dependency broken, reached the file just as its editor opened; the dependency was fixed 150 ms later, and every report of the connected document after that was empty, but the editor kept "Dependencies unavailable". Until this is fixed, the Ecstasy plugin refreshes a file's marks as LSP4IJ sends the file's didOpen.
Seen with LSP4IJ 0.30.1; the code is unchanged on main at df2fa63.
Activity
fix: refresh a file's marks on its connected document's first diagnos…
Take back an editor's marks that LSP4IJ made before it connected the …
Record the tour's two Diagnostics failures of run-tour-11649425361568…
Take back an editor's marks that LSP4IJ made before it connected the …
fix: refresh a file's marks on its connected document's first diagnos…
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Record the tour's two Diagnostics failures of run-tour-11649425361568…
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Record the tour's two Diagnostics failures of run-tour-11649425361568…
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Record the tour's two Diagnostics failures of run-tour-11649425361568…
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Record the tour's two Diagnostics failures of run-tour-11649425361568…
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Record the tour's two Diagnostics failures of run-tour-11649425361568…
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Record the tour's two Diagnostics failures of run-tour-11649425361568…
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …
Take back an editor's marks that LSP4IJ made before it connected the …