File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed
packages/jupyterlab-lsp/src Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -722,7 +722,11 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
722
722
723
723
abstract context_from_active_document ( ) : ICommandContext | null ;
724
724
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
+ }
726
730
let document = this . virtual_editor . document_at_root_position ( root_position ) ;
727
731
let virtual_position =
728
732
this . virtual_editor . root_position_to_virtual_position ( root_position ) ;
@@ -738,7 +742,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
738
742
} ;
739
743
}
740
744
741
- get_context_from_context_menu ( ) : ICommandContext {
745
+ get_context_from_context_menu ( ) : ICommandContext | null {
742
746
let root_position = this . get_position_from_context_menu ( ) ;
743
747
return this . get_context ( root_position ) ;
744
748
}
Original file line number Diff line number Diff line change @@ -620,7 +620,8 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
620
620
connection : LSPConnection ,
621
621
response : lsProtocol . PublishDiagnosticsParams
622
622
) => {
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 ) ) {
624
625
return ;
625
626
}
626
627
Original file line number Diff line number Diff line change @@ -537,7 +537,9 @@ export class CodeMirrorVirtualEditor
537
537
forEveryBlockEditor (
538
538
callback : ( cm_editor : CodeMirror . Editor ) => any ,
539
539
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
541
543
) {
542
544
const editors_with_handlers = new Set < CodeMirror . Editor > ( ) ;
543
545
@@ -568,6 +570,9 @@ export class CodeMirrorVirtualEditor
568
570
adapter : WidgetAdapter < IDocumentWidget > ,
569
571
data : IEditorChangedData
570
572
) => {
573
+ if ( on_editor_removed_callback == null ) {
574
+ return ;
575
+ }
571
576
let { editor } = data ;
572
577
if ( editor == null ) {
573
578
return ;
You can’t perform that action at this time.
0 commit comments