M1.13: watch open buffers' folders, bufferFocused, truncated tree row

- The parent directory of every open buffer is pinned in the project
  watcher (workspace::sync_buffer_dirs after every command): it counts
  against the cap but is never evicted while a buffer in it is open, so
  reloads and fileChangedOnDisk arrive for never-expanded folders.
- file.open on an already-open buffer emits the new bufferFocused {id};
  the editor activates that tab and it outranks pending adoptions.
- The project tree shows a "Listing truncated" note row
  (project.tree.truncated) after a partly listed directory.
- Tests: engine (pinning, eviction, focus), control channel
  (bufferFocused), Vitest (tab switch, race, truncated row).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-16 16:20:11 +02:00
parent 7b7273a947
commit 8a71f7bd08
19 changed files with 312 additions and 30 deletions

View file

@ -18,8 +18,9 @@ struct OpenParams {
path: String,
}
/// `file.open`: opens a file into a buffer, or returns the buffer that
/// already holds it.
/// `file.open`: opens a file into a buffer and emits
/// [`Event::BufferOpened`], or returns the buffer that already holds it and
/// emits [`Event::BufferFocused`] so clients switch to it.
pub struct Open;
impl Command for Open {
@ -29,7 +30,7 @@ impl Command for Open {
label: "Open File",
menu_path: None,
default_shortcut: None,
params: "{ path: string (project-relative or absolute inside the project) }; returns { id, path, text, version, dirty, lineEnding: lf|crlf|cr }",
params: "{ path: string (project-relative or absolute inside the project) }; returns { id, path, text, version, dirty, lineEnding: lf|crlf|cr }; emits bufferOpened for a new buffer, bufferFocused for one already open",
}
}
@ -42,7 +43,9 @@ impl Command for Open {
let p: OpenParams = parse(id, params)?;
let rel = project_path(state, id, &p.path)?;
if let Some(existing) = state.buffers.find(&rel) {
return describe(state, id, existing).map(Outcome::value);
let value = describe(state, id, existing)?;
state.emit(Event::BufferFocused { id: existing });
return Ok(Outcome::value(value));
}
let abs = absolute(state, id, &rel)?;
let file = lutra_vfs::read_text(&abs).map_err(vfs_error)?;