M3.5: go to definition, find references and rename through Phpactor

Engine (`cmd/lsp_nav.rs`, on the pending outcomes of 20d1d28):
- `lsp.definition` (F12) and `lsp.references` (Shift+F12, sorted, with
  line previews) return project-relative locations; locations outside
  the project, such as PHAR stubs and symlink escapes, are dropped.
- `lsp.prepareRename` uses the word at the cursor when the server has
  no prepareProvider.
- `lsp.rename` (F2) applies the workspace edit (`lsp_nav/edit.rs`):
  1. Check everything first: inside the project, ranges fit (UTF-16,
     CRLF), open buffers unchanged since the request, no file
     operations, no incomplete edit.
  2. Write closed files atomically through the VFS, restoring earlier
     writes when a later one fails.
  3. Change open buffers through `buffer.edit` (dirty, undoable).
  4. Send each written file to Phpactor as didOpen/didSave/didClose
     plus didChangeWatchedFiles; without this its index kept the old
     names. Then the summary notification `notification.lsp.renamed`.

UI (`components/editor/nav/`):
- Mod+click goes to the definition, with a pointer cursor while Mod is
  held.
- A location picker for several definitions (exclusive modal).
- A References tab in the bottom panel, grouped by file.
- An inline rename field with a use/file count (exclusive modal).
- `BufferSync.beginUndoableRemote` puts the engine's rename edit into
  the editor history as one undo step per buffer.
- Catalog strings and tokens only.

Fake LSP server: `--script FILE` with scripted capabilities and
answers (additive next to M3.4's arms).

Tests:
- `crates/engine/tests/lsp_nav.rs` (fake): definition; bad positions;
  references; prepareRename; a multi-file rename incl. a closed CRLF
  file; refusals for outside the project, a bad range, a stale buffer,
  bad names and no server.
- The ignored real-Phpactor test covers definition, references and a
  rename and back across 3 files.
- Vitest `ui/tests/nav/`.

Live (Phpactor 2026.06.25.0, Windows, port 7935, tick on):
- definition 93 ms cold / 7-18 ms warm
- references ~140 ms
- prepareRename ~11 ms
- rename 28-59 ms
- index follows written files in 140 ms
- Phpactor 57 MB working set, ~1.6% of a core while ticking idle

Gate: 13 steps, 197 s, Vitest 484 + 1 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-22 18:50:15 +02:00
parent b3fd7c6478
commit 578160a2ba
28 changed files with 3730 additions and 34 deletions

View file

@ -131,6 +131,12 @@ export class BufferSync {
private disposed = false;
/** Callbacks waiting for {@link idle}. */
private waiters: (() => void)[] = [];
/**
* Remote changes up to this engine version enter the undo history
* (a rename, M3.5); `Infinity` while the version is not known yet, null
* when off.
*/
private undoableUntil: number | null = null;
/** Engine transport. */
private readonly transport: SyncTransport;
/** Receives errors that are not handled by a resync. */
@ -241,6 +247,27 @@ export class BufferSync {
}
}
/**
* Makes the engine's next changes to this buffer undoable in the editor
* (they enter the history instead of bypassing it), until
* {@link endUndoableRemote}. Called before a command that edits open
* buffers on the user's behalf, such as `lsp.rename`.
*/
beginUndoableRemote(): void {
this.undoableUntil = Number.POSITIVE_INFINITY;
}
/**
* Ends {@link beginUndoableRemote} once the engine version `version` has
* been taken over; null ends it now (the command did not touch this
* buffer or failed).
*
* @param version - the buffer's version after the command, or null.
*/
endUndoableRemote(version: number | null): void {
this.undoableUntil = version === null || this.version >= version ? null : version;
}
/** Resolves once every local change has reached the engine. */
idle(): Promise<void> {
if (!this.pending || this.disposed) {
@ -370,11 +397,15 @@ export class BufferSync {
this.version = info.version;
this.latestKnown = Math.max(this.latestKnown, info.version);
this.separator = separatorOf(info.lineEnding);
const undoable = this.undoableUntil !== null && info.version <= this.undoableUntil && !dropLocal;
if (this.undoableUntil !== null && Number.isFinite(this.undoableUntil) && this.version >= this.undoableUntil) {
this.undoableUntil = null;
}
if (!toLocal.empty) {
this.applyTransactions([
this.current.update({
changes: toLocal,
annotations: [remoteChange.of(true), Transaction.addToHistory.of(false)],
annotations: [remoteChange.of(true), Transaction.addToHistory.of(undoable)],
}),
]);
}