Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions client-node-tests/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,39 @@ suite('Full notebook tests', () => {

await revertAllDirty();
}).timeout(5000);

test('Notebook document: reordering cells pulls diagnostics', async(): Promise<void> => {
const notebook = await vscode.workspace.openNotebookDocument('jupyter-notebook', createNotebookData());
await vscode.window.showNotebookDocument(notebook);

const pulled: string[] = [];
client.middleware.provideDiagnostics = async (doc, p, token, next) => {
pulled.push(doc instanceof vscode.Uri ? doc.toString() : doc.uri.toString());
return next(doc, p, token);
};

try {
// Move the first cell down. This only changes the order of the cells.
const firstUri = notebook.cellAt(0).document.uri.toString();
const editor = vscode.window.activeNotebookEditor;
isDefined(editor);
editor.selection = new vscode.NotebookRange(0, 1);
// Let the pulls caused by opening the notebook finish before observing.
await new Promise<void>((resolve) => setTimeout(resolve, 500));
pulled.length = 0;
await vscode.commands.executeCommand('notebook.cell.moveDown');
assert.strictEqual(notebook.cellAt(1).document.uri.toString(), firstUri);
// Wait for a pull of the moved cell, with an upper bound.
const deadline = Date.now() + 3000;
while (!pulled.includes(firstUri) && Date.now() < deadline) {
await new Promise<void>((resolve) => setTimeout(resolve, 50));
}
assert.ok(pulled.includes(firstUri), 'Expected the moved cell to be pulled after the cell order changed');
} finally {
client.middleware.provideDiagnostics = undefined;
await revertAllDirty();
}
}).timeout(8000);
});

suite('Simple notebook tests', () => {
Expand Down
2 changes: 1 addition & 1 deletion client-node-tests/src/servers/fullNotebookServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ connection.onInitialize((_params: InitializeParams): any => {
diagnosticProvider: {
identifier: 'diagnostic-provider',
documentSelector: null,
interFileDependencies: false,
interFileDependencies: true,
workspaceDiagnostics: false
}
};
Expand Down
15 changes: 15 additions & 0 deletions client/src/common/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,10 @@ class DiagnosticFeatureProviderImpl implements DiagnosticProviderShape {
const textEvents = event.cells?.textContent || [];
const changedCells = textEvents.map(
(c) => event.notebook.getCells().find(cell => cell.document.uri.toString() === c.document.uri.toString()));
const pulledUris = new Set<string>();
for (const cell of changedCells) {
if (cell && matchesCell(cell)) {
pulledUris.add(cell.document.uri.toString());
this.diagnosticRequestor.pull(cell.document, () => { this.backgroundScheduler.trigger(); });
}
}
Expand All @@ -1034,9 +1036,22 @@ class DiagnosticFeatureProviderImpl implements DiagnosticProviderShape {
const openedCells = event.cells?.structure?.didOpen || [];
for (const cell of openedCells) {
if (matchesCell(cell)) {
pulledUris.add(cell.document.uri.toString());
this.diagnosticRequestor.pull(cell.document, () => { this.backgroundScheduler.trigger(); });
}
}

// Moving cells changes the order of the notebook without changing the text
// or the URIs of the cells. Cell order can change the diagnostics of other
// cells when the server reports inter file dependencies.
if (options.interFileDependencies && event.cells?.structure !== undefined) {
for (const cell of event.notebook.getCells()) {
// Cells pulled above for this event do not need a second pull.
if (matchesCell(cell) && !pulledUris.has(cell.document.uri.toString())) {
this.diagnosticRequestor.pull(cell.document, () => { this.backgroundScheduler.trigger(); });
}
}
}
}));
}

Expand Down
Loading