Skip to content

Commit f324c69

Browse files
authored
Merge pull request #522 from krassowski/fix/diagnostics-panel-crash
Fix/diagnostics panel crash
2 parents a7f07c6 + 4b53956 commit f324c69

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
- user-invoked completion in strings works again ([#521])
1616
- completer documentation will now consistently show up after filtering the completion items ([#520])
1717
- completions containing HTML-like syntax will be displayed properly (an upstream issue) ([#520])
18+
- diagnostics panel will no longer break when foreign documents (e.g. `%%R` cell magics) are removed ([#522])
1819

1920
[#520]: https://github.com/krassowski/jupyterlab-lsp/pull/520
2021
[#521]: https://github.com/krassowski/jupyterlab-lsp/pull/521
22+
[#522]: https://github.com/krassowski/jupyterlab-lsp/pull/522
2123

2224
### `@krassowski/jupyterlab-lsp 3.3.1` (2020-02-07)
2325

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/components/utils.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ export function DocumentLocator(props: {
6565
let target: HTMLElement = null;
6666
if (adapter.has_multiple_editors) {
6767
let first_line = document.virtual_lines.get(0);
68-
target = adapter.get_editor_wrapper(first_line.editor);
68+
if (first_line) {
69+
target = adapter.get_editor_wrapper(first_line.editor);
70+
} else {
71+
console.warn('Could not get first line of ', document);
72+
}
6973
}
7074
let breadcrumbs = get_breadcrumbs(document, adapter);
7175
return (

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)