Skip to content

Commit d84ecb5

Browse files
committed
Fix diagnostics not being cleared upon foreign document closure
1 parent 6defe87 commit d84ecb5

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

atest/04_Interface/DiagnosticsPanel.robot

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Test Teardown Clean Up
99
${EXPECTED_COUNT} 1
1010
${DIAGNOSTIC} W291 trailing whitespace (pycodestyle)
1111
${DIAGNOSTIC MESSAGE} trailing whitespace
12+
${DIAGNOSTIC MESSAGE R} Closing curly-braces should always be on their own line
13+
${R CELL} %%R\n{}
1214
${MENU COLUMNS} xpath://div[contains(@class, 'lm-Menu-itemLabel')][contains(text(), "columns")]
1315
${LAB MENU} css:.lm-Menu
1416

@@ -78,6 +80,22 @@ Diagnostic Message Can Be Copied
7880
Close Diagnostics Panel
7981
Wait Until Element Contains css:.lsp-statusbar-item Successfully copied timeout=10s
8082

83+
Diagnostics Panel Works After Removing Foreign Document
84+
Enter Cell Editor 2
85+
Lab Command Insert Cell Below
86+
Enter Cell Editor 3
87+
Press Keys None ${R CELL}
88+
Wait Until Keyword Succeeds 10 x 1s Element Should Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE}
89+
Wait Until Keyword Succeeds 10 x 1s Element Should Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE R}
90+
Lab Command Delete Cells
91+
# regain focus by entering cell
92+
Enter Cell Editor 2
93+
# trigger 7 document updates to trigger the garbage collector that removes unused documents
94+
# (search for VirtualDocument.remainining_lifetime for more)
95+
Press Keys None 1234567
96+
Wait Until Keyword Succeeds 10 x 1s Element Should Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE}
97+
Wait Until Keyword Succeeds 10 x 1s Element Should Not Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE R}
98+
8199
*** Keywords ***
82100
Expand Menu Entry
83101
[Arguments] ${label}

packages/jupyterlab-lsp/src/features/diagnostics/diagnostics.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,18 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
279279
this.adapter.adapterConnected.connect(() =>
280280
this.switchDiagnosticsPanelSource()
281281
);
282+
this.virtual_document.foreign_document_closed.connect(
283+
(document, context) => {
284+
this.clearDocumentDiagnostics(context.foreign_document);
285+
}
286+
);
282287
super.register();
283288
}
284289

290+
clearDocumentDiagnostics(document: VirtualDocument) {
291+
this.diagnostics_db.set(document, []);
292+
}
293+
285294
private unique_editor_ids: DefaultMap<CodeMirror.Editor, number>;
286295
private marked_diagnostics: Map<string, CodeMirror.TextMarker> = new Map();
287296
/**

packages/jupyterlab-lsp/src/virtual/document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class VirtualDocument {
252252
this.unused_standalone_documents = new DefaultMap(
253253
() => new Array<VirtualDocument>()
254254
);
255-
this._remaining_lifetime = 10;
255+
this._remaining_lifetime = 6;
256256
this.foreign_document_closed = new Signal(this);
257257
this.foreign_document_opened = new Signal(this);
258258
this.changed = new Signal(this);

0 commit comments

Comments
 (0)