Avoid blocking event loop when saving nb (#207381)

This commit is contained in:
Don Jayamanne 2024-03-12 18:18:20 +11:00 committed by GitHub
parent 30f1a7103b
commit 7696df9026
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,36 +81,31 @@ export class AttachmentCleaner implements vscode.CodeActionProvider {
this._disposables.push(vscode.workspace.onWillSaveNotebookDocument(e => {
if (e.reason === vscode.TextDocumentSaveReason.Manual) {
this._delayer.dispose();
e.waitUntil(new Promise((resolve) => {
if (e.notebook.getCells().length === 0) {
return;
if (e.notebook.getCells().length === 0) {
return;
}
const notebookEdits: vscode.NotebookEdit[] = [];
for (const cell of e.notebook.getCells()) {
if (cell.kind !== vscode.NotebookCellKind.Markup) {
continue;
}
const notebookEdits: vscode.NotebookEdit[] = [];
for (const cell of e.notebook.getCells()) {
if (cell.kind !== vscode.NotebookCellKind.Markup) {
continue;
}
const metadataEdit = this.cleanNotebookAttachments({
notebook: e.notebook,
cell: cell,
document: cell.document
});
const metadataEdit = this.cleanNotebookAttachments({
notebook: e.notebook,
cell: cell,
document: cell.document
});
if (metadataEdit) {
notebookEdits.push(metadataEdit);
}
if (metadataEdit) {
notebookEdits.push(metadataEdit);
}
if (!notebookEdits.length) {
return;
}
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(e.notebook.uri, notebookEdits);
resolve(workspaceEdit);
}));
}
if (!notebookEdits.length) {
return;
}
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(e.notebook.uri, notebookEdits);
e.waitUntil(Promise.resolve(workspaceEdit));
}
}));