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

@ -3,7 +3,7 @@
* dirty state, notices, and the Save / Don't save / Cancel question when a
* dirty tab closes.
*
* Fed by engine events (`bufferOpened`, `bufferChanged`, `dirtyChanged`,
* Fed by engine events (`bufferOpened`, `bufferFocused`, `bufferChanged`, `dirtyChanged`,
* `bufferClosed`, `fileChangedOnDisk`, project open/close) and by command
* results. Text lives in the engine and in one {@link BufferSync} per tab,
* kept outside reactive state. Command failures are stored and shown, never
@ -425,6 +425,18 @@ export const useEditorStore = defineStore("editor", () => {
}
}
/**
* Activates the tab of a buffer that `file.open` found already open
* (`bufferFocused`). It also outranks adoptions still fetching, so the
* most recent open wins.
*
* @param id - buffer id.
*/
function focusOpened(id: number): void {
++openSequence;
activate(id);
}
/**
* Applies one editor event.
*
@ -439,6 +451,9 @@ export const useEditorStore = defineStore("editor", () => {
case "bufferOpened":
void adoptOpened(event.id);
break;
case "bufferFocused":
focusOpened(event.id);
break;
case "bufferChanged":
syncs.get(event.id)?.notifyVersion(event.version);
break;

View file

@ -70,6 +70,14 @@ export type TreeRow =
depth: number;
/** The error to show. */
error: EngineError;
}
| {
/** Note after the entries of a listing the engine cut short. */
kind: "truncated";
/** Directory whose listing is incomplete. */
dir: string;
/** Nesting depth of the note. */
depth: number;
};
/**
@ -300,7 +308,7 @@ export const useProjectStore = defineStore("project", () => {
/**
* The tree flattened into visible rows: entries of the root and of every
* expanded directory, with a loading or error row where a listing is
* pending or failed.
* pending or failed, and a truncated row after an incomplete listing.
*/
const rows = computed<TreeRow[]>(() => {
const out: TreeRow[] = [];
@ -325,6 +333,9 @@ export const useProjectStore = defineStore("project", () => {
visit(entry.path, depth + 1);
}
}
if (state.truncated) {
out.push({ kind: "truncated", dir, depth });
}
};
if (root.value !== null) {
visit("", 0);