M3.4: completion, hover and signature help from Phpactor

Engine (crates/engine/src/cmd/lsp_assist.rs), on M3.5's pending outcomes:
- lsp.completion {id, position, triggerCharacter?}: items with label,
  kind, detail, Markdown documentation, insertText, textEdit,
  additionalTextEdits, sortText; sorted, capped at 500 (cut lists are
  incomplete), snippets turned into plain text.
- lsp.hover {id, position}: Markdown contents and range.
- lsp.signatureHelp {id, position}: signatures with UTF-16 parameter spans.
- The request is queued after every didChange; the answer is converted
  in the reply callback, off the engine lock. Positions are checked
  against the buffer. Server strings and lists are capped.
- lutra-lsp-fake answers completion and signature help.

Editor (ui/src/components/editor/assist/):
- Completion source with Lutra's triggers (identifiers, $, ->, ?->, ::,
  namespace \; not in strings or comments unless asked), the server's
  ranking as boost, text edits and imports applied in UTF-16 (CRLF too),
  Lucide kind icons.
- Hover documentation (350 ms) and editor.quickDocumentation (Mod+I).
- Signature help on ( and , following the cursor; editor.parameterInfo.
- editor.complete.
- Lutra's own Markdown renderer without HTML (XSS-tested), tokens only.
- Requests wait for the buffer sync to be idle and use runWaiting.
- New dependency @codemirror/autocomplete (MIT, already transitive).

Tests: 6 engine tests against the fake server, 9 unit tests, an ignored
real-Phpactor latency test, 29 Vitest tests; palette and menu tests list
the new UI commands.

Measured with the real Phpactor (Windows 11, debug build, 25 ms tick):
- Completion 61-109 ms while typing (median 76 ms; ~107 ms in the app).
- Hover and signature help ~16 ms median.
- A useful list 2.3 s after opening a file in a 20-class project, ~65 s
  for 2,000 classes (indexing).
- Phpactor 56-71 MB working set, ~6% of one core while typing.

Live-checked in the app on port 7934. Docs: Code completion 0% -> 5%
(est.), feature depth ~4.1% -> ~4.6%, breadth 26/155, architecture, G6,
ui-parity, language-parity, roadmap, README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-22 18:38:07 +02:00
parent 12d21d96f4
commit a212a44490
35 changed files with 3916 additions and 25 deletions

View file

@ -16,6 +16,7 @@ import { run, type EngineError, type RunResult } from "../ipc";
import { BufferSync, isBufferInfo, engineTransport, type BufferInfo, type SyncTransport } from "../components/editor/bufferSync";
import { onEditorEvent, type EditorEvent } from "../components/editor/engineEvents";
import { editorExtensions } from "../components/editor/extensions";
import type { AssistBuffer } from "../components/editor/assist";
import type { Extension } from "@codemirror/state";
/** Engine command ids used by the editor. */
@ -111,7 +112,7 @@ export const useEditorStore = defineStore("editor", () => {
/** Engine transport for syncs, replaceable in tests. */
let transport: SyncTransport = engineTransport;
/** Extensions of a new editor state for a file path, replaceable in tests. */
let extensions: (path: string) => Extension = editorExtensions;
let extensions: (path: string, buffer?: AssistBuffer) => Extension = editorExtensions;
/** Counter of tab adoptions, so only the newest open activates its tab. */
let openSequence = 0;
/** Unsubscribe function of the event subscription. */
@ -144,7 +145,7 @@ export const useEditorStore = defineStore("editor", () => {
* @param next - transport for new syncs.
* @param nextExtensions - extensions for new editor states, by file path.
*/
function configure(next: SyncTransport, nextExtensions?: (path: string) => Extension): void {
function configure(next: SyncTransport, nextExtensions?: (path: string, buffer?: AssistBuffer) => Extension): void {
transport = next;
if (nextExtensions) {
extensions = nextExtensions;
@ -163,7 +164,7 @@ export const useEditorStore = defineStore("editor", () => {
const started = openStarted.get(info.path);
syncs.set(
info.id,
new BufferSync(info, extensions(info.path), transport, (error) => {
new BufferSync(info, extensions(info.path, { id: info.id, idle: () => syncs.get(info.id)?.idle() ?? Promise.resolve() }), transport, (error) => {
const tab = tabOf(info.id);
if (tab) {
tab.notice = { kind: "error", message: error.message };