Skip to content

Commit

Permalink
Correct fix for diagnostics silencing (the offset was ok), see:
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Aug 28, 2023
1 parent 1763d75 commit 412d849
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/jupyterlab-lsp/src/features/diagnostics/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TODO
document.virtualLines
.get(start.line - 1)!
.skipInspect.indexOf(document.idPath) !== -1
.get(start.line)!
.skipInspect.includes(document.idPath)
) {
this.console.log(
'Ignoring inspections silenced for this document:',
Expand Down
61 changes: 61 additions & 0 deletions packages/jupyterlab-lsp/src/virtual/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,67 @@ export class VirtualDocument extends VirtualDocumentBase {
return { lines, foreignDocumentsMap, skipInspect };
}

appendCodeBlock(
block: Document.ICodeBlockOptions,
editorShift: CodeEditor.IPosition = { line: 0, column: 0 },
virtualShift?: CodeEditor.IPosition
): void {
let cellCode = block.value;
let ceEditor = block.ceEditor;

if (this.isDisposed) {
console.warn('Cannot append code block: document disposed');
return;
}
let sourceCellLines = cellCode.split('\n');
let { lines, foreignDocumentsMap, skipInspect } = this.prepareCodeBlock(
block,
editorShift
);

for (let i = 0; i < lines.length; i++) {
this.virtualLines.set(this.lastVirtualLine + i, {
skipInspect: skipInspect[i],
editor: ceEditor,
// TODO this is incorrect, wont work if something was extracted
sourceLine: this.lastSourceLine + i
});
}
for (let i = 0; i < sourceCellLines.length; i++) {
this.sourceLines.set(this.lastSourceLine + i, {
editorLine: i,
editorShift: {
line: editorShift.line - (virtualShift?.line || 0),
column: i === 0 ? editorShift.column - (virtualShift?.column || 0) : 0
},
// TODO: move those to a new abstraction layer (DocumentBlock class)
editor: ceEditor,
foreignDocumentsMap,
// TODO this is incorrect, wont work if something was extracted
virtualLine: this.lastVirtualLine + i
});
}

this.lastVirtualLine += lines.length;

// one empty line is necessary to separate code blocks, next 'n' lines are to silence linters;
// the final cell does not get the additional lines (thanks to the use of join, see below)

this.lineBlocks.push(lines.join('\n') + '\n');

// adding the virtual lines for the blank lines
for (let i = 0; i < this.blankLinesBetweenCells; i++) {
this.virtualLines.set(this.lastVirtualLine + i, {
skipInspect: [this.idPath],
editor: ceEditor,
sourceLine: null
});
}

this.lastVirtualLine += this.blankLinesBetweenCells;
this.lastSourceLine += sourceCellLines.length;
}

/**
* @experimental
*/
Expand Down

0 comments on commit 412d849

Please sign in to comment.