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:

  1. Get document-editing-sample
  2. 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
  3. Set autoSave to afterDelay in settings
  4. Open a new document, type “Hello”, and save it as “hello.txt” on the desktop
  5. Press Ctrl+Shift+P and run “Reverse Word”
  6. Note how the message the pops up shows the content of the file before the reverse took place!
  7. 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

Most upvoted comments

Ah slight correction. The execCommand does not return until the listeners of the paste event return. However, there is an await there which is effectively an early return with the remaining work put on the task queue with a low priority.

image

image

image