H3: Phpactor UX: fast tick while indexing, progress, messages, php -l

- Session tick: 1 ms while Phpactor reports work-done progress and in a
  session's first 120 s, otherwise 25 ms as before. Fast intervals use
  thread::sleep, because recv_timeout wakes at most ~64/s on Windows.
  First useful completion on 2,000 classes: 71.6 s -> 20.7-26.9 s.
- $/progress -> lspProgress {active, title?, message?, percentage?},
  progress in lsp.status, a status-bar item (LspProgressItem).
- window/showMessage -> notification.lsp.message (repeats within 30 s and
  the known Windows lint-provider complaint only logged); showMessage,
  logMessage and stderr in a 1,000-line log, new command lsp.log.
- Lutra's own php -l on Windows (lsp/php_lint.rs): on open and save, one
  worker thread, lutra_proc::spawn, stdin, 10 s timeout, output caps;
  merged into diagnosticsChanged with source "php -l".
- editor.completion.delayMs stays 0 (measured: 100 ms only delays the
  list; Phpactor marks every list incomplete).
- Fake server: scripted notifications after initialized.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-25 17:33:26 +01:00
parent 8701f50d37
commit e128400246
21 changed files with 1752 additions and 48 deletions

View file

@ -49,6 +49,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",

View 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();
});
});