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
Have workspace.save
and workspace.saveAs
methods that return the URI
#178713
Comments
Follow up question: how can one know the URI of the file after save? |
Here's the workaround we're currently using: const deferred = createDeferred<Uri>();
this.documentManager.onDidSaveTextDocument((e) => deferred.resolve(e.uri));
const commandManager = this.serviceContainer.get<ICommandManager>(ICommandManager);
await commandManager.executeCommand('workbench.action.files.save', file);
const savedFileUri = await deferred.promise; |
The uri of a document doesn't change and it is expected that saving an untitled documented emits a close event for it. There is unfortunately no easy way to know what the new uri is, using the save or open events is the best you have. To double-check you can compare the contents |
Related: #124117 We could still make this a bit easier on extensions and return a As for the underlying issue: code editor text models cannot change their model |
That would be great.
Gotcha. Right now from a user's perspective |
@jrieken Intiutively it feels like Ideally, I would have expected it to return something like |
Btw, it is possible for a user to cancel the dialog to pick a save location for an untitled file, so you almost need 3 states (error, success, cancelled). But anyway, API changes like this are not in the cards and would require new methods. I can see if the command can return the |
save()
API closes the Untitled document which is savedURI
from commands that save the active editor
The APIs works perfectly for me 👍 |
@karrtikr the |
Verification:
|
Does this issue occur when all extensions are disabled?: Yes
Version: 1.77.0-insider (user setup)
Commit: 7f329fe
Date: 2023-03-29T09:56:00.839Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Windows_NT x64 10.0.22518
Sandboxed: Yes
Steps to Reproduce:
save()
API here: https://code.visualstudio.com/api/references/vscode-api#TextDocumentTextdocument.isClosed
property is set totrue
Also
TextDocument.uri
object is not updated to point to the updated saved URI. For Python extension it leads to issues like the following where wrong URI is sent to terminal, also notice that the file disappears:The text was updated successfully, but these errors were encountered: