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
1 change: 1 addition & 0 deletions news/2 Fixes/16528.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clear Notebook Cell diagnostics when deleting a cell or closing a notebook.
16 changes: 16 additions & 0 deletions src/client/jupyter/languageserver/notebookConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class NotebookConverter implements Disposable {

private onDidChangeCellsEmitter = new EventEmitter<TextDocumentChangeEvent>();

private mapOfConcatDocumentsWithCellUris = new Map<string, string[]>();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing the Uris as strings (don't want to be storing the objects)


constructor(
private api: IVSCodeNotebook,
private fs: IFileSystem,
Expand Down Expand Up @@ -127,9 +129,18 @@ export class NotebookConverter implements Disposable {
if (wrapper) {
// Diagnostics are supposed to be per file and are updated each time
// Make sure to clear out old ones first
const cellUris: string[] = [];
const oldCellUris = this.mapOfConcatDocumentsWithCellUris.get(uri.toString()) || [];
wrapper.notebook.getCells().forEach((c: NotebookCell) => {
result.set(c.document.uri, []);
cellUris.push(c.document.uri.toString());
});
// Possible some cells were deleted, we need to clear the diagnostics of those cells as well.
const currentCellUris = new Set(cellUris);
oldCellUris
.filter((cellUri) => !currentCellUris.has(cellUri))
.forEach((cellUri) => result.set(Uri.parse(cellUri), []));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, if we delete a cell, the diagnostics of deleted cells remains & doesn't go away.

this.mapOfConcatDocumentsWithCellUris.set(uri.toString(), cellUris);

// Then for all the new ones, set their values.
diagnostics.forEach((d) => {
Expand All @@ -141,6 +152,11 @@ export class NotebookConverter implements Disposable {
}
list.push(this.toIncomingDiagnostic(location.uri, d));
});
} else if (this.mapOfConcatDocumentsWithCellUris.has(uri.toString())) {
(this.mapOfConcatDocumentsWithCellUris.get(uri.toString()) || [])
.map((cellUri) => Uri.parse(cellUri))
.forEach((cellUri) => result.set(cellUri, []));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, if a notebook is closed, the diagnostics don't go away.
This is because when a notebook is closed, the wrapper is disposed and we don't have the wrapper document, hence we cannot get the cells to clear the diagnostics.

this.mapOfConcatDocumentsWithCellUris.delete(uri.toString());
} else {
result.set(uri, diagnostics);
}
Expand Down