Skip to content

[vscode] workspace.onWillSaveTextDocument is not triggered anymore since 1.62 #15770

@rschnekenbu

Description

@rschnekenbu

Discussed in #15692

Originally posted by safisa June 1, 2025
Hi,
I have a vscode extension that uses the vscode.workspace.onWillSaveTextDocument API. I see that in the latest Theia 1.62 this API is not triggered anymore.
NOTE that it is NOT working on custom editors only.

Is it a regression issue in Theia?

I have built a small one that demonstrates it, and you can check it on a text editor where it should work, and on a custom editor where it does not work. When you try it on older Theia versions (I tried 1.57), it worked on both types.

Here is the extension code:

export function activate(context: vscode.ExtensionContext) {
    let channel = vscode.window.createOutputChannel("willSave Test");

    // Register the onWillSaveTextDocument event
    vscode.workspace.onWillSaveTextDocument(event => {
        // Log a message when a document is about to be saved
        channel.appendLine(`Document ${event.document.uri} is about to be saved`);

        let p = new Promise((resolve, reject) => {
            channel.appendLine(`Pre save`);
            let data = event.document.getText();
            // data manipulation...
            resolve(data);
        }).then(res => {
            let textRange = new vscode.Range(0, 0, event.document.lineCount, 0);
            let textEdit = vscode.TextEdit.replace(textRange, `${res}`);
            return [textEdit];
        });
        event.waitUntil(p);

        p.then(res => {
            if (res) {
                channel.appendLine(`Post save`);
                //this.postSave(doc.uri, res[0].newText);
            }
        });

    });
}
And here is the vsix file:

willsavetest-0.0.1.vsix.zip

Metadata

Metadata

Labels

vscodeissues related to VSCode compatibility

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions