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

@ -1,6 +1,7 @@
/**
* Tests for the Project tool window: empty state, lazy expansion, keyboard
* navigation, refresh on `TreeChanged` and error display. The engine is
* navigation, refresh on `TreeChanged`, error display and the truncated
* listing note. The engine is
* mocked: `invoke` answers `project.children` from an in-memory folder and
* events go through the local dispatcher in `engineEvents.ts`.
*/
@ -14,6 +15,7 @@ vi.mock("@tauri-apps/api/core", () => ({ invoke }));
import { emitEngineEvent } from "../../src/components/project/engineEvents";
import ProjectToolWindow from "../../src/components/project/ProjectToolWindow.vue";
import { useProjectStore } from "../../src/stores/project";
import { t } from "../../src/i18n";
/** An entry as the engine's `project.children` returns it. */
interface EngineEntry {
@ -32,6 +34,9 @@ interface EngineEntry {
/** In-memory folder listings by directory, as `project.children` returns them. */
let folder: Record<string, EngineEntry[]>;
/** Directories whose mock listing reports `truncated: true`. */
let truncatedDirs: Set<string>;
/**
* Builds an entry.
*
@ -54,7 +59,7 @@ function engine(command: string, args: { command: string; params: { dir?: string
const dir = args.params.dir ?? "";
const entries = folder[dir];
return entries
? Promise.resolve({ dir, entries, truncated: false })
? Promise.resolve({ dir, entries, truncated: truncatedDirs.has(dir) })
: Promise.reject(Object.assign(new Error(`cannot list ${dir}`), { code: "not_found" }));
}
return Promise.resolve(null);
@ -104,6 +109,7 @@ describe("ProjectToolWindow", () => {
setActivePinia(createPinia());
invoke.mockReset();
invoke.mockImplementation(engine);
truncatedDirs = new Set();
folder = {
"": [entry("src", "dir"), entry("vendor", "dir"), entry("node_modules", "dir", true), entry("index.php", "file")],
src: [entry("src/Controller", "dir"), entry("src/App.php", "file")],
@ -233,6 +239,24 @@ describe("ProjectToolWindow", () => {
expect(paths(wrapper)).toEqual(["src", "vendor", "node_modules", "index.php"]);
});
it("shows a truncated note after a directory the engine listed only partly", async () => {
truncatedDirs = new Set(["src"]);
wrapper = await mountOpen();
expect(wrapper.find("[data-test=tree-truncated]").exists()).toBe(false);
await wrapper.findAll("[data-test=tree-chevron]")[0]?.trigger("click");
await flushPromises();
const notes = wrapper.findAll("[data-test=tree-truncated]");
expect(notes).toHaveLength(1);
expect(notes[0]?.text()).toBe(t("project.tree.truncated"));
expect(notes[0]?.attributes("role")).toBeUndefined();
const order = wrapper
.findAll("[data-test=tree-row], [data-test=tree-truncated]")
.map((row) => row.attributes("data-path") ?? "note");
expect(order).toEqual(["src", "src/Controller", "src/App.php", "note", "vendor", "node_modules", "index.php"]);
await press(wrapper, "End");
expect(selectedPath(wrapper)).toBe("index.php");
});
it("returns to the empty state on ProjectClosed and unsubscribes on unmount", async () => {
wrapper = await mountOpen();
emitEngineEvent({ kind: "projectClosed" });