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

@ -14,6 +14,7 @@ export type EditorEvent =
| { kind: "projectOpened" }
| { kind: "projectClosed" }
| { kind: "bufferOpened"; id: number; path: string }
| { kind: "bufferFocused"; id: number }
| { kind: "bufferChanged"; id: number; version: number }
| { kind: "dirtyChanged"; id: number; dirty: boolean }
| { kind: "bufferClosed"; id: number }
@ -41,6 +42,8 @@ export function toEditorEvent(payload: EngineEventPayload): EditorEvent | null {
return id !== null && typeof raw.path === "string"
? { kind: "bufferOpened", id, path: raw.path }
: null;
case "bufferFocused":
return id !== null ? { kind: "bufferFocused", id } : null;
case "bufferChanged": {
const version = num("version");
return id !== null && version !== null ? { kind: "bufferChanged", id, version } : null;

View file

@ -6,7 +6,8 @@
* Keys: Up/Down move the selection, Home/End jump to the first/last row,
* Right expands a folder or moves into it, Left collapses a folder or moves
* to the parent, Enter opens a file or toggles a folder. Double-click does
* the same as Enter. Ignored and excluded entries are dimmed.
* the same as Enter. Ignored and excluded entries are dimmed. A directory
* the engine listed only partly ends with a "listing truncated" note.
*/
import { ChevronDown, ChevronRight, File, FileCode, Folder, FolderOpen } from "@lucide/vue";
import { computed, nextTick, ref } from "vue";
@ -286,6 +287,14 @@ function onFocus(): void {
>
{{ t("project.tree.loading") }}
</div>
<div
v-else-if="row.kind === 'truncated'"
class="tree__row tree__row--note"
:style="{ '--tree-depth': row.depth }"
data-test="tree-truncated"
>
{{ t("project.tree.truncated") }}
</div>
<div
v-else
class="tree__row tree__row--note tree__row--error"

View file

@ -23,6 +23,7 @@
"project.openFolder": "Open Folder…",
"project.toolWindow.title": "Project",
"project.tree.loading": "Loading…",
"project.tree.truncated": "Listing truncated: more entries than can be shown",
"recovery.dialog.changedOnDisk": "The file changed on disk since then",
"recovery.dialog.discard": "Discard",
"recovery.dialog.failed": "{path} could not be restored: {message}",

View file

@ -21,6 +21,7 @@ export type EngineEventPayload =
| { kind: "projectClosed" }
| { kind: "treeChanged"; dir: string }
| { kind: "bufferOpened"; id: number; path: string }
| { kind: "bufferFocused"; id: number }
| { kind: "bufferChanged"; id: number; version: number }
| { kind: "dirtyChanged"; id: number; dirty: boolean }
| { kind: "bufferClosed"; id: number }

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);