microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.32k stars 28.59k forks source link

Custom text editors do not handle extension host restarts or crashes which can lead to data loss #225410

Open segevfiner opened 1 month ago

segevfiner commented 1 month ago

Does this issue occur when all extensions are disabled?: No

Steps to Reproduce:

(This needs to be done with an installed extension rather than in extension development mode as when the extension host is killed in that mode, the process exits)

  1. Clone https://github.com/microsoft/vscode-extension-samples/tree/main/custom-editor-sample
  2. npm i
  3. Modify the publisher in the package.json to be anything else.
  4. Run vsce pack
  5. Install the resulting vsix. e.g. Using code --install-extension
  6. Open a new window.
  7. Open both exampleFiles/example.cscratch & exampleFiles/example.pawDraw.
  8. Edit anything in both files and don't save. Disable auto-save if on.
  9. Run Developer: Restart Extension Host
  10. The cscratch editor (Which is a custom text editor) is left in an orphaned state, any further edits in it are non-responsive. pawdraw (Which is a custom editor) seems to try and save on normal extension host restart and continues working.
  11. Edit anything in both files again and don't save. Disable auto-save if on.
  12. Force kill the extension host, e.g. kill -9 using the PID printed in the developer tools or using the VS Code process explorer.
  13. The same happens, but pawdraw is now orphaned as well, and you are unable to save any unsaved changes.

There doesn't seem to be an API for an extension or webview to detect and warn the user in such a case, and when this happens, it can often lead to data loss, as when it happens it is silent, and some editors might even continue to function, e.g. pawdraw, but you are unable to save!

Related: https://github.com/microsoft/vscode/issues/180514 (Which isn't exposed to users, and seems to not be used in custom text editor, only on custom editor, also it doesn't handle crashes, only clean restarts) https://github.com/microsoft/vscode/issues/188257 https://github.com/microsoft/vscode/issues/209967

ShaulAmranS commented 4 weeks ago

Because of this bug, our users of Swimm Documentation plugin lose their work sometimes. Can you please prioritise this?

segevfiner commented 3 weeks ago

Might be a duplicate of https://github.com/microsoft/vscode/issues/184142, though this issue has more details.