-
Notifications
You must be signed in to change notification settings - Fork 37.9k
Description
Discussion of how to implement hot exit for custom editors (#77131)
Background
With hot exit users can quit VS Code with unsaved file changes and know that those files (in their edited state) will be restored when they open VS Code again.
VS Code can properly restore the user's previous file state even in cases such as the following:
- User edits a file and then exits VS Code without saving
- In a different program, the user then edits the same file and saves it to disk
- Then the user reopens VS Code
In that case, VS Code correctly restores the original file with edits. VS Code implements hot exit by continuously persisting edited files to a backup folder, and then checking that backup folder when restoring VS Code.
If there is an error that would prevent VS Code from hot exiting, such as if the backup fails, VS Code will alert the user and require the the non-backed up files be either saved to disk or have their changes lost.
Hot exit + Custom editors
We would like to support hot exit for custom editors as well. From the user's point of view, hot exit of a custom editor should behave the same way it does for normal text editors.
Goals
- Allow extensions to support hot exit for both text and binary based custom editors
- Don't require transferring binary file data from extensions to VS Code
- Make it possible to implement hot exit for larger files
- Support hot exit for custom editors that are not on disk or that are backed by multiple resources
- Fail gracefully (no data loss)
Big questions
- What part of the file state does VS Code back up? What part of the state do extension back up?
- Edits?
- File contents?
- Where is the backup stored?
- Who cleans up old backups?
- How do extensions know that a backup exists and restore the editors from this?
- How does VS Code know that a given editor is backed up? (i.e. we can hot exit)
- When/how are extension notified that they need to back up? For example, if auto save is enabled, we may not need to backup since the file will be saved shortly anyways
How we implement backup also influences the rest of the custom editor API. For example, does it still make sense to have the concept of edits in the API, or could this be delegated to extensions?