Skip to content

Commit 75a5187

Browse files
authored
Merge pull request #732 from jupyter-lsp/squash-warnings
Squash warnings and errors in web console
2 parents 01214e4 + f6b65f5 commit 75a5187

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

packages/jupyterlab-lsp/src/adapters/adapter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,11 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
722722

723723
abstract context_from_active_document(): ICommandContext | null;
724724

725-
get_context(root_position: IRootPosition): ICommandContext {
725+
get_context(root_position: IRootPosition): ICommandContext | null {
726+
// ignore premature calls and calls after disposal
727+
if (!this.virtual_editor) {
728+
return null;
729+
}
726730
let document = this.virtual_editor.document_at_root_position(root_position);
727731
let virtual_position =
728732
this.virtual_editor.root_position_to_virtual_position(root_position);
@@ -738,7 +742,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
738742
};
739743
}
740744

741-
get_context_from_context_menu(): ICommandContext {
745+
get_context_from_context_menu(): ICommandContext | null {
742746
let root_position = this.get_position_from_context_menu();
743747
return this.get_context(root_position);
744748
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
620620
connection: LSPConnection,
621621
response: lsProtocol.PublishDiagnosticsParams
622622
) => {
623-
if (!uris_equal(response.uri, this.virtual_document.document_info.uri)) {
623+
// use optional chaining operator because the diagnostics message may come late (after the document was disposed)
624+
if (!uris_equal(response.uri, this.virtual_document?.document_info?.uri)) {
624625
return;
625626
}
626627

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,9 @@ export class CodeMirrorVirtualEditor
537537
forEveryBlockEditor(
538538
callback: (cm_editor: CodeMirror.Editor) => any,
539539
monitor_for_new_blocks = true,
540-
on_editor_removed_callback: (cm_editor: CodeMirror.Editor) => any = null
540+
on_editor_removed_callback: (
541+
cm_editor: CodeMirror.Editor
542+
) => any | null = null
541543
) {
542544
const editors_with_handlers = new Set<CodeMirror.Editor>();
543545

@@ -568,6 +570,9 @@ export class CodeMirrorVirtualEditor
568570
adapter: WidgetAdapter<IDocumentWidget>,
569571
data: IEditorChangedData
570572
) => {
573+
if (on_editor_removed_callback == null) {
574+
return;
575+
}
571576
let { editor } = data;
572577
if (editor == null) {
573578
return;

0 commit comments

Comments
 (0)