2

I am running a callback on the workspace.onWillSaveTextDocument handler. It provides vscode.TextDocument and this is necessary for the work I want to do on this event.

In certain cases, I want to treat other files (that aren't currently open) as if they had just been saved, as well.

It would suffice to be able to create a new instance of vscode.TextDocument, but I was unable to figure that out.

Is there a way to do something like:

workspace.pretendThisWasSavedJustNow('/path/to/other/file.ts');

1 Answer 1

2

I work on VSCode and while I don't know your exact use case, I believe you are looking for workspace.openTextDocument.

To use the same function for workspace.onWillSaveTextDocument and on some other event that your extension triggers, try something like:

// Actual save
workspace.onWillSaveTextDocument(e => onDocumentSave(e.document))

// Emulated save
setInterval(() => {
    workspace.openTextDocument('path/to/other/file.ts')
        .then(document => onDocumentSave(document))
}, 5000)

// Common save handling implementation
function onDocumentSave(document: TextDocument) { ... }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.