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:
parent
8701f50d37
commit
e128400246
21 changed files with 1752 additions and 48 deletions
|
|
@ -1,11 +1,13 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* Status bar along the bottom of the main window. Shows the product name and
|
||||
* version, or the last engine error.
|
||||
* version, or the last engine error, and on the right the language server's
|
||||
* progress (H3).
|
||||
*/
|
||||
import { computed } from "vue";
|
||||
import { t } from "../i18n";
|
||||
import { useAppStore } from "../stores/app";
|
||||
import LspProgressItem from "./problems/LspProgressItem.vue";
|
||||
|
||||
const app = useAppStore();
|
||||
|
||||
|
|
@ -25,6 +27,7 @@ const label = computed(() => {
|
|||
data-test="status-bar"
|
||||
>
|
||||
<span>{{ label }}</span>
|
||||
<LspProgressItem />
|
||||
</footer>
|
||||
</template>
|
||||
|
||||
|
|
|
|||
84
ui/src/components/problems/LspProgressItem.vue
Normal file
84
ui/src/components/problems/LspProgressItem.vue
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* Status-bar item (H3): the language server's running work-done progress
|
||||
* task (`lspProgress`), such as Phpactor indexing the workspace, with its
|
||||
* title and percentage. Its latest message (`500/2001 (24.99%, …)`) is the
|
||||
* tooltip. Hidden while no task runs. State comes from the Problems store.
|
||||
*/
|
||||
import { LoaderCircle } from "@lucide/vue";
|
||||
import { computed } from "vue";
|
||||
import { t } from "../../i18n";
|
||||
import { useProblemsStore } from "./problems";
|
||||
|
||||
const problems = useProblemsStore();
|
||||
|
||||
/** The visible text, or null when no task runs. */
|
||||
const text = computed(() => {
|
||||
const progress = problems.progress;
|
||||
if (!progress) {
|
||||
return null;
|
||||
}
|
||||
const title = progress.title === "" ? t("problems.lsp.progress.working") : progress.title;
|
||||
return progress.percentage === null
|
||||
? title
|
||||
: t("problems.lsp.progress.percentage", { title, percentage: progress.percentage });
|
||||
});
|
||||
|
||||
/** The tooltip and accessible label. */
|
||||
const label = computed(() => {
|
||||
const progress = problems.progress;
|
||||
if (!progress || text.value === null) {
|
||||
return "";
|
||||
}
|
||||
const base = t("problems.lsp.progress.label", { title: text.value });
|
||||
return progress.message ? `${base} (${progress.message})` : base;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span
|
||||
v-if="text !== null"
|
||||
class="lsp-progress"
|
||||
role="status"
|
||||
:title="label"
|
||||
:aria-label="label"
|
||||
data-test="lsp-progress"
|
||||
>
|
||||
<LoaderCircle
|
||||
class="lsp-progress__icon"
|
||||
:size="12"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span>{{ text }}</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.lsp-progress {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
margin-left: auto;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 40%;
|
||||
}
|
||||
|
||||
.lsp-progress__icon {
|
||||
flex: none;
|
||||
animation: lsp-progress-spin 1.2s linear infinite;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.lsp-progress__icon {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes lsp-progress-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -6,6 +6,10 @@
|
|||
* list (empty items remove the file); `diagnostics.list` loads every
|
||||
* file on start and when a project opens, and `lsp.status` the server's
|
||||
* state, which then follows `lspStatus`. A project close clears both.
|
||||
* - **Progress (H3):** the server's newest work-done progress task
|
||||
* (`progress` of `lsp.status`, then `lspProgress`), shown by
|
||||
* `LspProgressItem` in the status bar. It clears when the server stops,
|
||||
* restarts or fails, and on project close.
|
||||
* - **Editor:** every change is handed to the editor's lint extension
|
||||
* ({@link publishDiagnostics}), which draws the underlines and gutter
|
||||
* markers.
|
||||
|
|
@ -48,6 +52,16 @@ export interface LspStatus {
|
|||
message: string | null;
|
||||
}
|
||||
|
||||
/** The language server's newest running work-done progress task. */
|
||||
export interface LspProgress {
|
||||
/** Its title, such as `Indexing workspace`. */
|
||||
title: string;
|
||||
/** Its latest message, if any. */
|
||||
message: string | null;
|
||||
/** 0–100, if the server gives one. */
|
||||
percentage: number | null;
|
||||
}
|
||||
|
||||
/** The diagnostics of one file. */
|
||||
export interface ProblemFile {
|
||||
/** Project-relative path with `/`. */
|
||||
|
|
@ -160,6 +174,30 @@ export function toStatus(raw: unknown): LspStatus | null {
|
|||
return { state: known, message: typeof message === "string" ? message : null };
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the payload of `lspProgress` or the `progress` of `lsp.status`.
|
||||
*
|
||||
* @param raw - untrusted.
|
||||
* @returns the running task, or null when none runs or it is malformed.
|
||||
*/
|
||||
export function toProgress(raw: unknown): LspProgress | null {
|
||||
if (typeof raw !== "object" || raw === null) {
|
||||
return null;
|
||||
}
|
||||
const { active, title, message, percentage } = raw as Record<string, unknown>;
|
||||
if (active !== true) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
title: typeof title === "string" ? title.slice(0, 200) : "",
|
||||
message: typeof message === "string" ? message.slice(0, 500) : null,
|
||||
percentage:
|
||||
typeof percentage === "number" && Number.isFinite(percentage)
|
||||
? Math.round(Math.min(100, Math.max(0, percentage)))
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
/** The Problems store. */
|
||||
export const useProblemsStore = defineStore("problems", () => {
|
||||
/** Whether the tool window is shown in the bottom panel. */
|
||||
|
|
@ -170,6 +208,8 @@ export const useProblemsStore = defineStore("problems", () => {
|
|||
const files = shallowRef<ProblemFile[]>([]);
|
||||
/** The language server's state; null before the first report. */
|
||||
const lsp = ref<LspStatus | null>(null);
|
||||
/** The server's running work-done progress task; null when none. */
|
||||
const progress = ref<LspProgress | null>(null);
|
||||
/** Key of the selected row. */
|
||||
const selectedKey = ref<string | null>(null);
|
||||
/** Bumped when the window should take the keyboard focus. */
|
||||
|
|
@ -226,6 +266,9 @@ export const useProblemsStore = defineStore("problems", () => {
|
|||
const [list, status] = await Promise.all([run("diagnostics.list"), run("lsp.status")]);
|
||||
if (status.ok) {
|
||||
lsp.value = toStatus(status.value) ?? lsp.value;
|
||||
const value = status.value;
|
||||
const raw = typeof value === "object" && value !== null && !Array.isArray(value) ? value.progress : null;
|
||||
progress.value = toProgress(raw);
|
||||
}
|
||||
if (!list.ok) {
|
||||
return;
|
||||
|
|
@ -255,9 +298,15 @@ export const useProblemsStore = defineStore("problems", () => {
|
|||
}
|
||||
} else if (event.kind === "lspStatus") {
|
||||
lsp.value = toStatus(event) ?? lsp.value;
|
||||
if (lsp.value && lsp.value.state !== "ready" && lsp.value.state !== "starting") {
|
||||
progress.value = null;
|
||||
}
|
||||
} else if (event.kind === "lspProgress") {
|
||||
progress.value = toProgress(event);
|
||||
} else if (event.kind === "projectClosed") {
|
||||
clear();
|
||||
lsp.value = null;
|
||||
progress.value = null;
|
||||
} else if (event.kind === "projectOpened") {
|
||||
void load();
|
||||
}
|
||||
|
|
@ -323,6 +372,7 @@ export const useProblemsStore = defineStore("problems", () => {
|
|||
expanded,
|
||||
files,
|
||||
lsp,
|
||||
progress,
|
||||
rows,
|
||||
counts,
|
||||
selectedKey,
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@
|
|||
"notification.close": "Close notification",
|
||||
"notification.command.failed": "{command} failed: {message}",
|
||||
"notification.lsp.failed": "The PHP language server stopped: {reason}. Run Restart PHP Language Server to try again.",
|
||||
"notification.lsp.message": "PHP language server: {message}",
|
||||
"notification.lsp.renamed": "Renamed to {name}: {edits} changes in {files} files ({written} closed files saved)",
|
||||
"notification.project.notLocal": "The chosen folder is not on this computer: {reason}",
|
||||
"notification.project.openFailed": "Cannot open {path}: {reason}",
|
||||
|
|
@ -151,6 +152,9 @@
|
|||
"problems.file.count": "{count} problems",
|
||||
"problems.list.label": "Problems of the project",
|
||||
"problems.lsp.failed": "Phpactor stopped: {message}",
|
||||
"problems.lsp.progress.label": "Language server: {title}",
|
||||
"problems.lsp.progress.percentage": "{title} {percentage}%",
|
||||
"problems.lsp.progress.working": "Language server working…",
|
||||
"problems.lsp.restarting": "Phpactor is restarting: {message}",
|
||||
"problems.lsp.starting": "Phpactor is starting…",
|
||||
"problems.lsp.stopped": "No PHP language server is running. It starts when PHP and Phpactor are available.",
|
||||
|
|
|
|||
|
|
@ -128,6 +128,17 @@ export type EngineEventPayload =
|
|||
/** Why it restarts or failed; unchecked. */
|
||||
message?: unknown;
|
||||
}
|
||||
| {
|
||||
kind: "lspProgress";
|
||||
/** Whether a work-done progress task runs; unchecked. */
|
||||
active: unknown;
|
||||
/** Its title; unchecked. */
|
||||
title?: unknown;
|
||||
/** Its latest message; unchecked. */
|
||||
message?: unknown;
|
||||
/** 0–100; unchecked. */
|
||||
percentage?: unknown;
|
||||
}
|
||||
| {
|
||||
kind: "diagnosticsChanged";
|
||||
/** Project-relative path of the file; unchecked, it comes from the engine. */
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
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