feat: Syntax-colour Find in Files and Show Usages result lines (#143)

Result lines in the Find in Files popup and tool window and in the Show Usages popup and Usages tool window are coloured like the editor, using the whole file as context, so a line inside a block comment or a multi-line string gets the right colour. The colouring lives in editor/lineTokens and all four lists share it; each file is parsed once and cached, and the parse runs in 8 ms time slices so large files don't block the UI thread. Lines that moved since the search, and files over 500k characters, are coloured on their own.

Claude-Session: https://claude.ai/code/session_01Dq6jQQn8ZhRfkkyj3PRutA
Co-authored-by: jaw52 <[email protected]>
Цей коміт міститься в:
Jaw authored and GitHub committed 2026-10-29 00:18:02 +08:00
1 джерело 1d383e608c
коміт 811da13a76
15 files changed
+466 -44

No files matched your search

+29
Переглянути файл
@@ -0,0 +1,29 @@
import { describe, expect, it, vi } from "vitest";
import { render, waitFor } from "@testing-library/react";
vi.mock(import("@/platform/ipc"), async (importOriginal) => ({
...(await importOriginal()),
commands: { fsReadText: (path: string) => path } as never,
call: (async () => "/**\n * Uses foo()\n */\n const x = foo();\n") as never,
}));
vi.mock(import("@/editor/api"), async (importOriginal) => ({ ...(await importOriginal()), editorsFor: () => [] }));
const { UsagePreview } = await import("./UsagesView");
describe("UsagePreview", () => {
it("colours the usage line with its file as context", async () => {
const { container } = render(
<UsagePreview usage={{ path: "/p/a.ts", line: 3, col: 12, endCol: 15, text: " const x = foo();" }} />,
);
await waitFor(() => expect(container.querySelector(".tok-keyword")?.textContent).toBe("const"));
expect(container.querySelector("mark")?.textContent).toBe("foo");
expect(container.textContent).toBe("const x = foo();");
});
it("colours a usage inside a doc comment as a comment", async () => {
const { container } = render(
<UsagePreview usage={{ path: "/p/a.ts", line: 1, col: 8, endCol: 11, text: " * Uses foo()" }} />,
);
await waitFor(() => expect(container.querySelector("mark .tok-comment")?.textContent).toBe("foo"));
});
});