zed/crates
Thorsten Ball 9241b11e1f
Restore unsaved buffers on restart (#13546)
This adds the ability for Zed to restore unsaved buffers on restart. The
user is no longer prompted to save/discard/cancel when trying to close a
Zed window with dirty buffers in it. Instead those dirty buffers are
stored and restored on restart.

It does this by saving the contents of dirty buffers to the internal
SQLite database in which Zed stores other data too. On restart, if there
are dirty buffers in the database, they are restored.

On certain events (buffer changed, file saved, ...) Zed will serialize
these buffers, throttled to a 100ms, so that we don't overload the
machine by saving on every keystroke. When Zed quits, it waits until all
the buffers are serialized.


### Current limitations
- It does not persist undo-history (right now we don't persist/restore
undo-history regardless of dirty buffers or not)
- It does not restore buffers in windows without projects/worktrees.
Example: if you open a new window with `cmd-shift-n` and type something
in a buffer, this will _not_ be stored and you will be asked whether to
save/discard on quit. In the future, we want to fix this by also
restoring windows without projects/worktrees.

### Demo



https://github.com/user-attachments/assets/45c63237-8848-471f-8575-ac05496bba19



### Related tickets

I'm unsure about closing them, without also fixing the 2nd limitation:
restoring of worktree-less windows. So let's wait until that.

- https://github.com/zed-industries/zed/issues/4985
- https://github.com/zed-industries/zed/issues/4683

### Note on performance

- Serializing editing buffer (asynchronously on background thread) with
500k lines takes ~200ms on M3 Max. That's an extreme case and that
performance seems acceptable.

Release Notes:

- Added automatic restoring of unsaved buffers. Zed can now be closed
even if there are unsaved changes in buffers. One current limitation is
that this only works when having projects open, not single files or
empty windows with unsaved buffers. The feature can be turned off by
setting `{"session": {"restore_unsaved_buffers": false}}`.

---------

Co-authored-by: Bennet <bennet@zed.dev>
Co-authored-by: Antonio <antonio@zed.dev>
2024-07-17 18:10:20 +02:00
..
activity_indicator
anthropic
assets
assistant Add an experimental, WIP diagnostics grouping panel (#14515) 2024-07-15 22:58:18 +03:00
assistant_slash_command
assistant_tooling
audio
auto_update
breadcrumbs
call
channel
cli Open URIs from the CLI, support for the zed:// URI scheme on Linux (#14104) 2024-07-16 14:49:15 -06:00
client Extract a BufferStore object from Project (#14037) 2024-07-12 15:25:54 -07:00
clock
collab collab: Fix exact extension filtering (#14591) 2024-07-16 15:18:48 -04:00
collab_ui Introduce following for assistant panel (#14479) 2024-07-15 11:36:27 +02:00
collections
command_palette
command_palette_hooks
copilot
db
dev_server_projects remoting: Allow Add/Remove remote folder (#14532) 2024-07-16 12:01:59 -06:00
diagnostics Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
editor Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
extension Allow Zed Nightly to use v0.0.7 of the Zed extension API (#14209) 2024-07-11 10:54:15 -04:00
extension_api
extension_cli
extensions_ui Rank exact extension ID matches higher in search results (#14588) 2024-07-16 12:33:28 -06:00
feature_flags Add an experimental, WIP diagnostics grouping panel (#14515) 2024-07-15 22:58:18 +03:00
feedback
file_finder remoting: Allow Add/Remove remote folder (#14532) 2024-07-16 12:01:59 -06:00
file_icons
fs Add support for projects managed with Yarn (#13644) 2024-07-11 14:56:07 +02:00
fsevent
fuzzy
git
git_hosting_providers
go_to_line
google_ai
gpui Fix text appearing twice after Chinese character input (#14558) 2024-07-16 10:54:53 -07:00
gpui_macros Upsell built-in features on the extensions page (#14516) 2024-07-15 17:10:01 -04:00
headless remoting: Allow Add/Remove remote folder (#14532) 2024-07-16 12:01:59 -06:00
html_to_markdown
http
image_viewer Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
indexed_docs assistant: Add basic glob support for expanding items in /docs (#14370) 2024-07-12 17:57:50 -04:00
inline_completion_button Change the context menu and Copilot settings icon (#14501) 2024-07-16 09:40:40 -03:00
install_cli
journal
language Introduce /symbols command in assistant panel (#14360) 2024-07-15 11:51:32 +02:00
language_selector
language_tools
languages Respect user preference for JS/TS on_type formatting (#14536) 2024-07-17 11:11:00 +02:00
live_kit_client linux: Panic less on window init (#14255) 2024-07-11 16:04:46 -06:00
live_kit_server
lsp Support dynamic formatting capabilities [un]registration (#14478) 2024-07-15 12:27:33 +03:00
markdown Selectable popover text (#12918) 2024-07-10 21:14:34 -06:00
markdown_preview
media
menu open picker (#14524) 2024-07-15 17:04:15 -06:00
multi_buffer Add an experimental, WIP diagnostics grouping panel (#14515) 2024-07-15 22:58:18 +03:00
node_runtime
notifications
ollama
open_ai
outline
outline_panel Do not fold excerpts by default in the outline panel (#14378) 2024-07-13 04:08:21 +03:00
paths
picker open picker (#14524) 2024-07-15 17:04:15 -06:00
prettier Lookup prettier more leniently (#14403) 2024-07-13 21:59:14 +03:00
project Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
project_panel remoting: Allow Add/Remove remote folder (#14532) 2024-07-16 12:01:59 -06:00
project_symbols
proto remoting: Allow Add/Remove remote folder (#14532) 2024-07-16 12:01:59 -06:00
quick_action_bar Refactor repl context menu (#14587) 2024-07-16 12:18:06 -07:00
recent_projects Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
refineable
release_channel
repl repl: Don't send KernelInfoRequest on launch (#14608) 2024-07-16 15:51:23 -07:00
rich_text
rope
rpc Rank exact extension ID matches higher in search results (#14588) 2024-07-16 12:33:28 -06:00
search Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
semantic_index
semantic_version
settings Show an initial empty keymap (#14609) 2024-07-16 20:24:13 -06:00
snippet
snippet_provider
sqlez
sqlez_macros
story
storybook linux: Panic less on window init (#14255) 2024-07-11 16:04:46 -06:00
sum_tree
supermaven
supermaven_api
tab_switcher
task
tasks_ui open picker (#14524) 2024-07-15 17:04:15 -06:00
telemetry_events
terminal Revert hold: true for macOS tasks (#14376) 2024-07-13 04:02:38 +03:00
terminal_view Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
text
theme linux: Indicate when the window is focused (#14266) 2024-07-12 14:20:58 -07:00
theme_importer linux: Panic less on window init (#14255) 2024-07-11 16:04:46 -06:00
theme_selector
time_format
title_bar Fix context in command palette from application menu (#14599) 2024-07-16 15:14:18 -06:00
ui Change the context menu and Copilot settings icon (#14501) 2024-07-16 09:40:40 -03:00
ui_input
util
vcs_menu Adjust list item & pickers spacing (#14250) 2024-07-15 10:23:18 -03:00
vim vim: Add :bd/:bp/:bn (#14623) 2024-07-16 23:06:08 -06:00
welcome linux: Hide Install CLI from welcome (#14506) 2024-07-15 12:08:37 -06:00
workspace Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
worktree Extract a BufferStore object from Project (#14037) 2024-07-12 15:25:54 -07:00
zed Restore unsaved buffers on restart (#13546) 2024-07-17 18:10:20 +02:00
zed_actions