M1.7: crash-recovery journal and restore dialog
Dirty buffers are written atomically to <data_dir>/recovery/<project-id>/ about 1 s after the last edit (at most 2 s while typing), from pump_vfs, never per keystroke. Entries are removed on save, close (also force), forced project close/open and recovery.discard. project.open emits recoveryAvailable; recovery.list/restore/discard; restored buffers are dirty and keep line ending and BOM. Corrupt entries are moved aside and reported as warning notifications. UI: restore dialog in ui/src/components/recovery (Restore all, Restore selected, Discard, time, changed-on-disk hint), catalog keys and runtime allow-list. Tests: crash/restore with CRLF + BOM, corrupt entries, removal paths, property test of random edits, headless control-channel test, Vitest for the dialog. Docs: architecture, parity, gaps, ROADMAP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6d976ed03e
commit
0b40eb90f8
27 changed files with 2222 additions and 27 deletions
|
|
@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
|
|||
use serde_json::{Value, json};
|
||||
|
||||
use super::params::{parse, project_path};
|
||||
use crate::journal::{self, Journal};
|
||||
use crate::workspace::{Workspace, path_string, vfs_error};
|
||||
use crate::{Command, CommandSpec, Effect, EngineError, Event, Outcome, State};
|
||||
|
||||
|
|
@ -51,9 +52,11 @@ pub fn close_project(state: &mut State, force: bool) -> Result<(), EngineError>
|
|||
return Err(EngineError::UnsavedChanges(what));
|
||||
}
|
||||
for id in state.buffers.ids() {
|
||||
journal::forget(state, id);
|
||||
state.buffers.remove(id);
|
||||
state.emit(Event::BufferClosed { id });
|
||||
}
|
||||
state.journal = None;
|
||||
state.project = None;
|
||||
state.emit(Event::ProjectClosed);
|
||||
Ok(())
|
||||
|
|
@ -70,7 +73,9 @@ struct OpenParams {
|
|||
force: bool,
|
||||
}
|
||||
|
||||
/// `project.open`: opens a folder as the project, closing the current one.
|
||||
/// `project.open`: opens a folder as the project, closing the current one,
|
||||
/// and offers the unsaved texts its recovery journal holds with
|
||||
/// [`Event::RecoveryAvailable`] (only when there are any).
|
||||
pub struct Open;
|
||||
|
||||
impl Command for Open {
|
||||
|
|
@ -80,7 +85,7 @@ impl Command for Open {
|
|||
label: "Open Folder",
|
||||
menu_path: None,
|
||||
default_shortcut: None,
|
||||
params: "{ path: string (absolute folder), force?: bool (discard unsaved changes of the open project) }; returns { root, name }",
|
||||
params: "{ path: string (absolute folder), force?: bool (discard unsaved changes of the open project) }; returns { root, name }; emits recoveryAvailable when the recovery journal holds unsaved texts",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,6 +94,10 @@ impl Command for Open {
|
|||
let (workspace, events) = Workspace::open(std::path::Path::new(&p.path))?;
|
||||
close_project(state, p.force)?;
|
||||
let root = workspace.project.root().to_path_buf();
|
||||
state.journal = state
|
||||
.config
|
||||
.as_ref()
|
||||
.map(|c| Journal::new(&c.data_dir, &root));
|
||||
state.project = Some(workspace);
|
||||
let mut name = String::new();
|
||||
for event in events {
|
||||
|
|
@ -97,6 +106,10 @@ impl Command for Open {
|
|||
}
|
||||
state.emit(event);
|
||||
}
|
||||
let entries = super::recovery::infos(state);
|
||||
if !entries.is_empty() {
|
||||
state.emit(Event::RecoveryAvailable { entries });
|
||||
}
|
||||
Ok(Outcome::value(json!({
|
||||
"root": root.to_string_lossy(),
|
||||
"name": name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue