-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve workspace API for Notebook lifecycle to support (at least) saving events #130799
Comments
This comment has been minimized.
This comment has been minimized.
Is there any workaround for this? I currently can easily see if a text file has been saved, but not have an event to tap into when a notebook has been saved. 😤😭 vscode.workspace.onDidSaveTextDocument(e => {
vscode.window.showInformationMessage('did' + e.fileName)
})
vscode.workspace.onWillSaveTextDocument(e => {
vscode.window.showInformationMessage('will' + e.document.fileName)
}) |
Re #157844 |
We introduced a proposed api export interface NotebookDocumentWillSaveEvent {
/**
* A cancellation token.
*/
readonly token: CancellationToken;
/**
* The document that will be saved.
*/
readonly document: NotebookDocument;
/**
* The reason why save was triggered.
*/
readonly reason: NotebookDocumentSaveReason;
waitUntil(thenable: Thenable<readonly WorkspaceEdit[]>): void;
waitUntil(thenable: Thenable<any>): void;
} Additional edits before save can be returned through |
We already have |
@francisco-perez-sorrosal @reggi you can follow #157844 on where we are with the |
This can be now tested against VS Code Insiders using the latest vscode.d.ts file from main branch. A sample extension with following content can help you test this feature: import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
vscode.workspace.onWillSaveNotebookDocument(event => {
if (event.reason === vscode.TextDocumentSaveReason.Manual) {
event.waitUntil(new Promise((resolve) => {
const notebookEdit = new vscode.NotebookEdit(new vscode.NotebookRange(0, 0), [new vscode.NotebookCellData(vscode.NotebookCellKind.Code, 'print(1)', 'python')]);
const edit = new vscode.WorkspaceEdit();
edit.set(event.notebook.uri, [notebookEdit]);
resolve(edit);
}));
}
});
}
export function deactivate() {} With this extension
|
There are certain VSCode extensions that are devoted to allow users to define shell commands that are executed when files are saved. These include, among others, the following:
The extensions above rely on events currently available in the VSCode
workspace
API such asonWillSaveTextDocument
andonDidSaveTextDocument
.In the recently added native support for notebooks in VSCode, it looks like notebooks are treated in a different way than text documents. The new
workspace
API has included some events specifically targeted to the notebook lifecycle, such asonDidOpenNotebookDocument
andonDidCloseNotebookDocument
. However, the API currently lacks other useful notebook lifecycle events such asonWillSaveNotebookDocument
andonDidSaveNotebookDocument
, so the extensions above can't work properly when save-related events happen on notebooks.Would it be possible to extend the workspace API with at least
onWillSaveNotebookDocument
andonDidSaveNotebookDocument
(and other useful methods for the notebook lifecycle if possible)?Thanks in advance!!!
Note: I've just stumbled upon a similar request for those APIs in an issue related to LiveShare: #102503
The text was updated successfully, but these errors were encountered: