Skip to content

Commit b1cc4ba

Browse files
authored
(fix) empty diagnostics on close (#395)
When a document is closed by the user, make its diagnostics disappear from the Problems tab #316
1 parent f9385cc commit b1cc4ba

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/language-server/src/lib/DiagnosticsManager.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export class DiagnosticsManager {
88
constructor(
99
private sendDiagnostics: SendDiagnostics,
1010
private docManager: DocumentManager,
11-
private getDiagnostics: GetDiagnostics
12-
) { }
11+
private getDiagnostics: GetDiagnostics,
12+
) {}
1313

1414
updateAll() {
1515
this.docManager.getAllOpenedByClient().forEach((doc) => {
@@ -24,4 +24,11 @@ export class DiagnosticsManager {
2424
diagnostics,
2525
});
2626
}
27+
28+
removeDiagnostics(document: Document) {
29+
this.sendDiagnostics({
30+
uri: document.getURL(),
31+
diagnostics: [],
32+
});
33+
}
2734
}

packages/language-server/src/server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ export function startServer(options?: LSOptions) {
259259
'documentChange',
260260
_.debounce(async (document: Document) => diagnosticsManager.update(document), 500),
261261
);
262+
docManager.on('documentClose', (document: Document) =>
263+
diagnosticsManager.removeDiagnostics(document),
264+
);
262265

263266
// The language server protocol does not have a specific "did rename/move files" event,
264267
// so we create our own in the extension client and handle it here

0 commit comments

Comments
 (0)