Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/diagnostics panel crash #522

Merged
merged 4 commits into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
- user-invoked completion in strings works again ([#521])
- completer documentation will now consistently show up after filtering the completion items ([#520])
- completions containing HTML-like syntax will be displayed properly (an upstream issue) ([#520])
- diagnostics panel will no longer break when foreign documents (e.g. `%%R` cell magics) are removed ([#522])

[#520]: https://github.com/krassowski/jupyterlab-lsp/pull/520
[#521]: https://github.com/krassowski/jupyterlab-lsp/pull/521
[#522]: https://github.com/krassowski/jupyterlab-lsp/pull/522

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

Expand Down
18 changes: 18 additions & 0 deletions atest/04_Interface/DiagnosticsPanel.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Test Teardown Clean Up
${EXPECTED_COUNT} 1
${DIAGNOSTIC} W291 trailing whitespace (pycodestyle)
${DIAGNOSTIC MESSAGE} trailing whitespace
${DIAGNOSTIC MESSAGE R} Closing curly-braces should always be on their own line
${R CELL} %%R\n{}
${MENU COLUMNS} xpath://div[contains(@class, 'lm-Menu-itemLabel')][contains(text(), "columns")]
${LAB MENU} css:.lm-Menu

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

Diagnostics Panel Works After Removing Foreign Document
Enter Cell Editor 2
Lab Command Insert Cell Below
Enter Cell Editor 3
Press Keys None ${R CELL}
Wait Until Keyword Succeeds 10 x 1s Element Should Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE}
Wait Until Keyword Succeeds 10 x 1s Element Should Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE R}
Lab Command Delete Cells
# regain focus by entering cell
Enter Cell Editor 2
# trigger 7 document updates to trigger the garbage collector that removes unused documents
# (search for VirtualDocument.remainining_lifetime for more)
Press Keys None 1234567
Wait Until Keyword Succeeds 10 x 1s Element Should Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE}
Wait Until Keyword Succeeds 10 x 1s Element Should Not Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE R}

*** Keywords ***
Expand Menu Entry
[Arguments] ${label}
Expand Down
6 changes: 5 additions & 1 deletion packages/jupyterlab-lsp/src/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export function DocumentLocator(props: {
let target: HTMLElement = null;
if (adapter.has_multiple_editors) {
let first_line = document.virtual_lines.get(0);
target = adapter.get_editor_wrapper(first_line.editor);
if (first_line) {
target = adapter.get_editor_wrapper(first_line.editor);
} else {
console.warn('Could not get first line of ', document);
}
}
let breadcrumbs = get_breadcrumbs(document, adapter);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,18 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
this.adapter.adapterConnected.connect(() =>
this.switchDiagnosticsPanelSource()
);
this.virtual_document.foreign_document_closed.connect(
(document, context) => {
this.clearDocumentDiagnostics(context.foreign_document);
}
);
super.register();
}

clearDocumentDiagnostics(document: VirtualDocument) {
this.diagnostics_db.set(document, []);
}

private unique_editor_ids: DefaultMap<CodeMirror.Editor, number>;
private marked_diagnostics: Map<string, CodeMirror.TextMarker> = new Map();
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/jupyterlab-lsp/src/virtual/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class VirtualDocument {
this.unused_standalone_documents = new DefaultMap(
() => new Array<VirtualDocument>()
);
this._remaining_lifetime = 10;
this._remaining_lifetime = 6;
this.foreign_document_closed = new Signal(this);
this.foreign_document_opened = new Signal(this);
this.changed = new Signal(this);
Expand Down