diff --git a/packages/jupyterlab-lsp/src/features/completion.ts b/packages/jupyterlab-lsp/src/features/completion.ts index ea4068d01..a770508cd 100644 --- a/packages/jupyterlab-lsp/src/features/completion.ts +++ b/packages/jupyterlab-lsp/src/features/completion.ts @@ -94,7 +94,10 @@ export class CompletionLabIntegration implements IFeatureLabIntegration { ) { if (this.current_adapter) { // disconnect signals from the old adapter - this.current_adapter.activeEditorChanged.disconnect(this.set_connector, this); + this.current_adapter.activeEditorChanged.disconnect( + this.set_connector, + this + ); this.current_adapter.adapterConnected.disconnect( this.connect_completion, this @@ -107,7 +110,7 @@ export class CompletionLabIntegration implements IFeatureLabIntegration { this.connect_completion, this ); - this.set_connector(adapter, {editor: adapter.activeEditor}); + this.set_connector(adapter, { editor: adapter.activeEditor }); } connect_completion( diff --git a/packages/jupyterlab-lsp/src/features/diagnostics.ts b/packages/jupyterlab-lsp/src/features/diagnostics.ts index 12795770b..2840c9b3d 100644 --- a/packages/jupyterlab-lsp/src/features/diagnostics.ts +++ b/packages/jupyterlab-lsp/src/features/diagnostics.ts @@ -288,12 +288,25 @@ export class DiagnosticsCM extends CodeMirrorIntegration { const end = PositionConverter.lsp_to_cm( range.end ) as IVirtualPosition; - if (start.line > this.virtual_document.last_virtual_line) { + const last_line_number = this.virtual_document.last_virtual_line; + if (start.line > last_line_number) { console.log( - 'Malformed diagnostic was skipped (out of lines) ', + `Out of range diagnostic (${start.line} line > ${last_line_number}) was skipped `, diagnostics ); return; + } else { + let last_line = this.virtual_document.last_line; + if ( + start.line == this.virtual_document.last_virtual_line && + start.ch > last_line.length + ) { + console.log( + `Out of range diagnostic (${start.ch} character > ${last_line.length} at line ${last_line_number}) was skipped `, + diagnostics + ); + return; + } } let document: VirtualDocument; diff --git a/packages/jupyterlab-lsp/src/virtual/codemirror_editor.ts b/packages/jupyterlab-lsp/src/virtual/codemirror_editor.ts index a3da0959f..f84fe83d6 100644 --- a/packages/jupyterlab-lsp/src/virtual/codemirror_editor.ts +++ b/packages/jupyterlab-lsp/src/virtual/codemirror_editor.ts @@ -2,7 +2,12 @@ import * as CodeMirror from 'codemirror'; import { CodeMirrorEditor } from '@jupyterlab/codemirror'; import { CodeEditor } from '@jupyterlab/codeeditor'; import { IEditorName } from '../feature'; -import { IBlockAddedInfo, ICodeBlockOptions, UpdateManager, VirtualDocument } from './document'; +import { + IBlockAddedInfo, + ICodeBlockOptions, + UpdateManager, + VirtualDocument +} from './document'; import { IForeignCodeExtractorsRegistry } from '../extractors/types'; import { create_console, EditorLogConsole } from './console'; import { Signal } from '@lumino/signaling'; @@ -115,7 +120,10 @@ export class CodeMirrorVirtualEditor } }); // this is not thee most efficient, but probably the most reliable way - this.virtual_document.update_manager.update_began.connect(this.onEditorsUpdated, this); + this.virtual_document.update_manager.update_began.connect( + this.onEditorsUpdated, + this + ); this.virtual_document.update_manager.block_added.connect( this.save_block_position, @@ -165,7 +173,10 @@ export class CodeMirrorVirtualEditor return this.getDoc().getCursor('end') as IRootPosition; } - private onEditorsUpdated(update_manager: UpdateManager, blocks: ICodeBlockOptions[]): void { + private onEditorsUpdated( + update_manager: UpdateManager, + blocks: ICodeBlockOptions[] + ): void { this.cm_editor_to_ce_editor.clear(); this.ce_editor_to_cm_editor.clear(); this.editor_to_source_line_new = new Map(); diff --git a/packages/jupyterlab-lsp/src/virtual/document.ts b/packages/jupyterlab-lsp/src/virtual/document.ts index cddfc601a..2549ae25c 100644 --- a/packages/jupyterlab-lsp/src/virtual/document.ts +++ b/packages/jupyterlab-lsp/src/virtual/document.ts @@ -642,6 +642,10 @@ export class VirtualDocument { return this.lines.join(lines_padding); } + get last_line() { + return this.lines[this.lines.length]; + } + close_expired_documents() { for (let document of this.unused_documents.values()) { document.remaining_lifetime -= 1; @@ -816,8 +820,9 @@ export class UpdateManager { */ private document_updated: Signal; public block_added: Signal; - // possibly redundant - update_done: Promise = new Promise(() => {}); + update_done: Promise = new Promise(resolve => { + resolve(); + }); update_began: Signal; update_finished: Signal;