vscode: vscode.workspace.saveAll doesn't work if autoSave set to afterDelay
The bug is that if autoSave is used, using saveAll doesn’t save files which are still pending to be saved, probably because they’re not marked as “dirty” (no unsaved indicator on the tab) but are not yet saved.
This causes problems for me. I have a setup which does operations on a file with Ctrl+Q. If I press Ctr+V and Ctrl+Q quickly, my workflow reads the old contents, even though I run saveAll!
Below is a deterministic way to reproduce.
Steps to Reproduce:
- Get document-editing-sample
- Replace extension.ts file with this content: https://gist.github.com/justanotheranonymoususer/016f6ada29d6c43487e68fbd066442fe, then open the extension folder in VSCode and run it with F5
- Set
autoSave
toafterDelay
in settings - Open a new document, type “Hello”, and save it as “hello.txt” on the desktop
- Press Ctrl+Shift+P and run “Reverse Word”
- Note how the message the pops up shows the content of the file before the reverse took place!
- See the commented code blocks for more weird behavior: saving a document before saveAll fixes it (but not a good fix to manually reimplement saveAll), saving a document after saveAll fails for some reason which looks like a bug
Does this issue occur when all extensions are disabled?: Yes
Version: 1.83.1 (Universal) Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc Date: 2023-10-10T23:46:55.789Z Electron: 25.8.4 ElectronBuildId: 24154031 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Darwin x64 23.0.0
But buggy in all OSes.
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Comments: 15 (14 by maintainers)
Commits related to this issue
- Wait for paste to finish in paste command (fixes #196161) — committed to r3m0t/vscode by r3m0t 8 months ago
- Wait for paste to finish in paste command (fixes #196161) (#196516) * Wait for paste to finish in paste command (fixes #196161) * :lipstick: --------- Co-authored-by: Alexandru Dima <alexdim... — committed to microsoft/vscode by r3m0t 7 months ago
Ah slight correction. The
execCommand
does not return until the listeners of the paste event return. However, there is anawait
there which is effectively an early return with the remaining work put on the task queue with a low priority.