Skip to content

Commit

Permalink
Lint and improve out-of-range diagnostics guard
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Aug 20, 2020
1 parent f8c11a8 commit 4421ce7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/jupyterlab-lsp/src/features/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
17 changes: 15 additions & 2 deletions packages/jupyterlab-lsp/src/features/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 14 additions & 3 deletions packages/jupyterlab-lsp/src/virtual/codemirror_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions packages/jupyterlab-lsp/src/virtual/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -816,8 +820,9 @@ export class UpdateManager {
*/
private document_updated: Signal<UpdateManager, VirtualDocument>;
public block_added: Signal<UpdateManager, IBlockAddedInfo>;
// possibly redundant
update_done: Promise<void> = new Promise<void>(() => {});
update_done: Promise<void> = new Promise<void>(resolve => {
resolve();
});
update_began: Signal<UpdateManager, ICodeBlockOptions[]>;
update_finished: Signal<UpdateManager, ICodeBlockOptions[]>;

Expand Down

0 comments on commit 4421ce7

Please sign in to comment.