PM: merge H3 Phpactor UX: fast indexing tick, progress, messages, php -l
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ac007a7d59
21 changed files with 1752 additions and 48 deletions
|
|
@ -50,6 +50,7 @@ const usedKeys = sourceFiles(SRC).flatMap((file) =>
|
|||
const RUNTIME_KEYS = new Set([
|
||||
"notification.command.failed",
|
||||
"notification.lsp.failed",
|
||||
"notification.lsp.message",
|
||||
"notification.lsp.renamed",
|
||||
"notification.project.notLocal",
|
||||
"notification.project.openFailed",
|
||||
|
|
|
|||
140
ui/tests/problems/LspProgressItem.test.ts
Normal file
140
ui/tests/problems/LspProgressItem.test.ts
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/**
|
||||
* Tests of the language server progress (H3): reading untrusted
|
||||
* `lspProgress` payloads, the store loading `progress` from `lsp.status`
|
||||
* and following `lspProgress`, `lspStatus` and project close, and the
|
||||
* status-bar item showing title and percentage with the message as its
|
||||
* tooltip. The engine is a fake behind the mocked Tauri `invoke` and
|
||||
* `listen`.
|
||||
*/
|
||||
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||
import { createPinia, setActivePinia, type Pinia } from "pinia";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const invoke = vi.hoisted(() => vi.fn());
|
||||
const listen = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||
vi.mock("@tauri-apps/api/event", () => ({ listen }));
|
||||
|
||||
import StatusBar from "../../src/components/StatusBar.vue";
|
||||
import { toProgress, useProblemsStore } from "../../src/components/problems/problems";
|
||||
|
||||
/** Engine event callbacks of every subscription. */
|
||||
let listeners: ((event: { payload: unknown }) => void)[];
|
||||
/** What `lsp.status` answers. */
|
||||
let status: unknown;
|
||||
/** Pinia of the current test. */
|
||||
let pinia: Pinia;
|
||||
/** Mounted components, unmounted after each test. */
|
||||
let mounted: VueWrapper[];
|
||||
|
||||
/**
|
||||
* Sends an engine event to every subscription.
|
||||
*
|
||||
* @param payload - the event.
|
||||
*/
|
||||
async function emit(payload: unknown): Promise<void> {
|
||||
for (const listener of [...listeners]) {
|
||||
listener({ payload });
|
||||
}
|
||||
await flushPromises();
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
listeners = [];
|
||||
mounted = [];
|
||||
status = { state: "ready" };
|
||||
invoke.mockReset();
|
||||
listen.mockReset();
|
||||
listen.mockImplementation((_name: string, callback: (event: { payload: unknown }) => void) => {
|
||||
listeners.push(callback);
|
||||
return Promise.resolve(() => {
|
||||
listeners = listeners.filter((l) => l !== callback);
|
||||
});
|
||||
});
|
||||
invoke.mockImplementation((cmd: string, args?: { command: string }) => {
|
||||
if (cmd !== "engine_execute" || !args) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
if (args.command === "diagnostics.list") {
|
||||
return Promise.resolve({ files: [] });
|
||||
}
|
||||
if (args.command === "lsp.status") {
|
||||
return Promise.resolve(status);
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
for (const wrapper of mounted) {
|
||||
wrapper.unmount();
|
||||
}
|
||||
useProblemsStore(pinia).stop();
|
||||
});
|
||||
|
||||
describe("toProgress", () => {
|
||||
it("reads running tasks and rejects the rest", () => {
|
||||
expect(toProgress({ active: true, title: "Indexing workspace", message: "1/2", percentage: 50 })).toEqual({
|
||||
title: "Indexing workspace",
|
||||
message: "1/2",
|
||||
percentage: 50,
|
||||
});
|
||||
expect(toProgress({ active: true, percentage: 400 })).toEqual({ title: "", message: null, percentage: 100 });
|
||||
expect(toProgress({ active: true, percentage: Number.NaN, title: 3 })).toEqual({
|
||||
title: "",
|
||||
message: null,
|
||||
percentage: null,
|
||||
});
|
||||
expect(toProgress({ active: false, title: "x" })).toBeNull();
|
||||
expect(toProgress({ active: "yes" })).toBeNull();
|
||||
expect(toProgress(null)).toBeNull();
|
||||
expect(toProgress({ active: true, title: "t".repeat(500) })?.title).toHaveLength(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe("language server progress", () => {
|
||||
it("loads, follows events and shows title, percentage and message in the status bar", async () => {
|
||||
status = { state: "ready", progress: { active: true, title: "Indexing workspace", percentage: 0 } };
|
||||
const problems = useProblemsStore();
|
||||
problems.start();
|
||||
const wrapper = mount(StatusBar, { global: { plugins: [pinia] } });
|
||||
mounted.push(wrapper);
|
||||
await flushPromises();
|
||||
expect(wrapper.get("[data-test=lsp-progress]").text()).toBe("Indexing workspace 0%");
|
||||
|
||||
await emit({
|
||||
kind: "lspProgress",
|
||||
active: true,
|
||||
title: "Indexing workspace",
|
||||
message: "500/2001 (24.99%)",
|
||||
percentage: 25,
|
||||
});
|
||||
const item = wrapper.get("[data-test=lsp-progress]");
|
||||
expect(item.text()).toBe("Indexing workspace 25%");
|
||||
expect(item.attributes("title")).toBe("Language server: Indexing workspace 25% (500/2001 (24.99%))");
|
||||
expect(item.attributes("role")).toBe("status");
|
||||
|
||||
await emit({ kind: "lspProgress", active: true, title: "" });
|
||||
expect(wrapper.get("[data-test=lsp-progress]").text()).toBe("Language server working…");
|
||||
|
||||
await emit({ kind: "lspProgress", active: false });
|
||||
expect(wrapper.find("[data-test=lsp-progress]").exists()).toBe(false);
|
||||
});
|
||||
|
||||
it("clears when the server restarts or the project closes", async () => {
|
||||
const problems = useProblemsStore();
|
||||
problems.start();
|
||||
await flushPromises();
|
||||
await emit({ kind: "lspProgress", active: true, title: "Indexing workspace" });
|
||||
expect(problems.progress?.title).toBe("Indexing workspace");
|
||||
await emit({ kind: "lspStatus", state: "ready" });
|
||||
expect(problems.progress).not.toBeNull();
|
||||
await emit({ kind: "lspStatus", state: "restarting", message: "exit 7" });
|
||||
expect(problems.progress).toBeNull();
|
||||
await emit({ kind: "lspProgress", active: true, title: "Indexing workspace" });
|
||||
await emit({ kind: "projectClosed" });
|
||||
expect(problems.progress).toBeNull();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue