Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore unsaved buffers on restart #13546

Merged
merged 39 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8192157
WIP: Backup unpersisted changes in in buffers
mrnugget Jun 26, 2024
1c1488b
Fix moving of dependency in Cargo.toml
mrnugget Jun 26, 2024
1e2a4ef
Fix wrong query
mrnugget Jun 27, 2024
2f9a138
Remove bincode after rebase
mrnugget Jul 11, 2024
a1cc0ed
workspace: Wait for items to be serialized on close
mrnugget Jul 11, 2024
f9128f7
Clean up unloaded items on start
mrnugget Jul 11, 2024
7e67904
Remove unused method
mrnugget Jul 11, 2024
76b605f
Delete serialized contents when discarding a file
mrnugget Jul 11, 2024
c2c5975
Fix save-or-discard prompt appearing with 1 item left
mrnugget Jul 11, 2024
63e4789
WIP: Do not serialize content in unnamed workspaces
mrnugget Jul 11, 2024
8630985
Decentralize cleaning up of unloaded items
mrnugget Jul 12, 2024
33f8cba
Serialize loaded items again after loading
mrnugget Jul 12, 2024
b87fea2
Introduce SerializableItemRegistry
mrnugget Jul 12, 2024
726cc0b
Introduce SerializableItem trait and rework structure
mrnugget Jul 12, 2024
2e5f45a
Update Cargo.lock after rebase
mrnugget Jul 15, 2024
58f6cea
Bandaid get the tests to run before deciding on strategy
mrnugget Jul 15, 2024
43cf3ed
Remove `bincode` in root Cargo.toml
mrnugget Jul 15, 2024
8db0d14
Change signature of function to unspice it
mrnugget Jul 15, 2024
62e559c
remove dead, commented-out code
mrnugget Jul 15, 2024
528609c
Implement centralized serialization
mrnugget Jul 15, 2024
89eaf07
Add clean_up for TerminalView/ImageViewer
mrnugget Jul 15, 2024
09e47ad
Fix warning and add comment
mrnugget Jul 15, 2024
c27dd02
Send serialization over channel
mrnugget Jul 15, 2024
88b1150
Put feature behind a feature flag
mrnugget Jul 15, 2024
18a7ab5
Clean up that sqlez method
mrnugget Jul 15, 2024
d49501c
Change all where-not-in queries to use same pattern
mrnugget Jul 15, 2024
549e4fd
Fix after rebase
mrnugget Jul 15, 2024
a62af54
Rename feature flag
mrnugget Jul 16, 2024
497129e
Fix bug that threw away many item serializations
mrnugget Jul 16, 2024
34770d3
Always serialize serializable items after adding to workspace
mrnugget Jul 16, 2024
4069deb
Use single table to store editor contents/language
mrnugget Jul 16, 2024
aa2cb58
Minor cleanup
mrnugget Jul 16, 2024
9840ffa
Merge branch 'main' into persist-unsaved-buffers
mrnugget Jul 17, 2024
7709446
Fix things after rebase/merge
mrnugget Jul 17, 2024
07f6ff0
Fix default value of restore_unsaved_buffers
mrnugget Jul 17, 2024
a6c3352
Fix tests and add more tests to ensure it works
mrnugget Jul 17, 2024
56a0834
More test fixing
mrnugget Jul 17, 2024
01def46
Remove now unused dependency
mrnugget Jul 17, 2024
ac1e498
Simplify persistence code a little bit
mrnugget Jul 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions crates/diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use ui::{h_flex, prelude::*, Icon, IconName, Label};
use util::ResultExt;
use workspace::{
item::{BreadcrumbText, Item, ItemEvent, ItemHandle, TabContentParams},
ItemNavHistory, Pane, ToolbarItemLocation, Workspace,
ItemNavHistory, ToolbarItemLocation, Workspace,
};

actions!(diagnostics, [Deploy, ToggleWarnings]);
Expand Down Expand Up @@ -786,20 +786,6 @@ impl Item for ProjectDiagnosticsEditor {
self.editor
.update(cx, |editor, cx| editor.added_to_workspace(workspace, cx));
}

fn serialized_item_kind() -> Option<&'static str> {
Some("diagnostics")
}

fn deserialize(
project: Model<Project>,
workspace: WeakView<Workspace>,
_workspace_id: workspace::WorkspaceId,
_item_id: workspace::ItemId,
cx: &mut ViewContext<Pane>,
) -> Task<Result<View<Self>>> {
Task::ready(Ok(cx.new_view(|cx| Self::new(project, workspace, cx))))
}
}

const DIAGNOSTIC_HEADER: &'static str = "diagnostic header";
Expand Down
16 changes: 1 addition & 15 deletions crates/diagnostics/src/grouped_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use ui::{h_flex, prelude::*, Icon, IconName, Label};
use util::{debug_panic, ResultExt};
use workspace::{
item::{BreadcrumbText, Item, ItemEvent, ItemHandle, TabContentParams},
ItemNavHistory, Pane, ToolbarItemLocation, Workspace,
ItemNavHistory, ToolbarItemLocation, Workspace,
};

use crate::project_diagnostics_settings::ProjectDiagnosticsSettings;
Expand Down Expand Up @@ -603,20 +603,6 @@ impl Item for GroupedDiagnosticsEditor {
self.editor
.update(cx, |editor, cx| editor.added_to_workspace(workspace, cx));
}

fn serialized_item_kind() -> Option<&'static str> {
Some("diagnostics")
}

fn deserialize(
project: Model<Project>,
workspace: WeakView<Workspace>,
_workspace_id: workspace::WorkspaceId,
_item_id: workspace::ItemId,
cx: &mut ViewContext<Pane>,
) -> Task<Result<View<Self>>> {
Task::ready(Ok(cx.new_view(|cx| Self::new(project, workspace, cx))))
}
}

fn compare_data_locations(
Expand Down
12 changes: 10 additions & 2 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ pub fn init(cx: &mut AppContext) {

workspace::register_project_item::<Editor>(cx);
workspace::FollowableViewRegistry::register::<Editor>(cx);
workspace::register_deserializable_item::<Editor>(cx);
workspace::register_serializable_item::<Editor>(cx);

cx.observe_new_views(
|workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>| {
workspace.register_action(Editor::new_file);
Expand Down Expand Up @@ -550,6 +551,7 @@ pub struct Editor {
show_git_blame_inline: bool,
show_git_blame_inline_delay_task: Option<Task<()>>,
git_blame_inline_enabled: bool,
serialize_dirty_buffers: bool,
show_selection_menu: Option<bool>,
blame: Option<Model<GitBlame>>,
blame_subscription: Option<Subscription>,
Expand Down Expand Up @@ -1876,6 +1878,9 @@ impl Editor {
show_selection_menu: None,
show_git_blame_inline_delay_task: None,
git_blame_inline_enabled: ProjectSettings::get_global(cx).git.inline_blame_enabled(),
serialize_dirty_buffers: ProjectSettings::get_global(cx)
.session
.restore_unsaved_buffers,
blame: None,
blame_subscription: None,
file_header_size,
Expand Down Expand Up @@ -11250,8 +11255,11 @@ impl Editor {
self.scroll_manager.vertical_scroll_margin = editor_settings.vertical_scroll_margin;
self.show_breadcrumbs = editor_settings.toolbar.breadcrumbs;

let project_settings = ProjectSettings::get_global(cx);
self.serialize_dirty_buffers = project_settings.session.restore_unsaved_buffers;

if self.mode == EditorMode::Full {
let inline_blame_enabled = ProjectSettings::get_global(cx).git.inline_blame_enabled();
let inline_blame_enabled = project_settings.git.inline_blame_enabled();
if self.git_blame_inline_enabled != inline_blame_enabled {
self.toggle_git_blame_inline_internal(false, cx);
}
Expand Down
Loading
Loading