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:
parent
b3fd7c6478
commit
578160a2ba
28 changed files with 3730 additions and 34 deletions
168
ui/src/components/editor/nav/RenameInput.vue
Normal file
168
ui/src/components/editor/nav/RenameInput.vue
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The inline rename field (M3.5): placed over the symbol in the editor,
|
||||
* prefilled with the current name (selected). Below it a line tells how
|
||||
* many uses in how many files will change (counted with Find References)
|
||||
* or why the rename failed. Enter applies the new name, Escape or leaving
|
||||
* the field cancels. An exclusive modal (the one-modal rule, `modals.ts`).
|
||||
*/
|
||||
import { computed, nextTick, ref, watch } from "vue";
|
||||
import { t } from "../../../i18n";
|
||||
import { useNavStore } from "./nav";
|
||||
|
||||
const nav = useNavStore();
|
||||
|
||||
/** The input element. */
|
||||
const input = ref<HTMLInputElement | null>(null);
|
||||
|
||||
/** Where the field goes: over the symbol, or near the top without a view. */
|
||||
const style = computed(() => {
|
||||
const anchor = nav.rename?.anchor;
|
||||
return anchor
|
||||
? { left: `${String(Math.max(0, anchor.left - 4))}px`, top: `${String(Math.max(0, anchor.top - 4))}px` }
|
||||
: { left: "50%", top: "12vh", transform: "translateX(-50%)" };
|
||||
});
|
||||
|
||||
/** The line under the field. */
|
||||
const hint = computed(() => {
|
||||
const r = nav.rename;
|
||||
if (!r) {
|
||||
return "";
|
||||
}
|
||||
if (r.error !== null) {
|
||||
return r.error;
|
||||
}
|
||||
if (r.busy) {
|
||||
return t("nav.rename.busy");
|
||||
}
|
||||
if (r.preview === null) {
|
||||
return t("nav.rename.counting");
|
||||
}
|
||||
return t("nav.rename.preview", { uses: String(r.preview.uses), files: String(r.preview.files) });
|
||||
});
|
||||
|
||||
/**
|
||||
* Keyboard handling of the field.
|
||||
*
|
||||
* @param event - the key press.
|
||||
*/
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === "Enter") {
|
||||
void nav.commitRename();
|
||||
} else if (event.key === "Escape") {
|
||||
nav.cancelRename();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
/** Cancels when the focus leaves the field, unless the rename runs. */
|
||||
function onBlur(): void {
|
||||
if (nav.rename && !nav.rename.busy) {
|
||||
nav.cancelRename();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the typed text.
|
||||
*
|
||||
* @param event - the input event.
|
||||
*/
|
||||
function onInput(event: Event): void {
|
||||
if (nav.rename && event.target instanceof HTMLInputElement) {
|
||||
nav.rename.value = event.target.value;
|
||||
nav.rename.error = null;
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => nav.rename !== null,
|
||||
(open) => {
|
||||
if (open) {
|
||||
void nextTick(() => {
|
||||
input.value?.focus();
|
||||
input.value?.select();
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="nav.rename"
|
||||
class="rename"
|
||||
:style="style"
|
||||
role="dialog"
|
||||
:aria-label="t('nav.rename.label', { name: nav.rename.placeholder })"
|
||||
data-test="rename"
|
||||
>
|
||||
<input
|
||||
ref="input"
|
||||
class="rename__input"
|
||||
:class="{ 'rename__input--error': nav.rename.error !== null }"
|
||||
type="text"
|
||||
:value="nav.rename.value"
|
||||
:readonly="nav.rename.busy"
|
||||
:aria-label="t('nav.rename.label', { name: nav.rename.placeholder })"
|
||||
:aria-describedby="'lt-rename-hint'"
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
data-test="rename-input"
|
||||
@input="onInput"
|
||||
@keydown="onKeydown"
|
||||
@blur="onBlur"
|
||||
>
|
||||
<p
|
||||
id="lt-rename-hint"
|
||||
class="rename__hint"
|
||||
:class="{ 'rename__hint--error': nav.rename.error !== null }"
|
||||
role="status"
|
||||
data-test="rename-hint"
|
||||
>
|
||||
{{ hint }}
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.rename {
|
||||
position: fixed;
|
||||
z-index: 30;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 220px;
|
||||
background: var(--lt-bg);
|
||||
border: 1px solid var(--lt-accent);
|
||||
border-radius: var(--lt-radius, 4px);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.rename__input {
|
||||
padding: var(--lt-space-xs, 2px) var(--lt-space-s, 4px);
|
||||
font-family: var(--lt-font-mono);
|
||||
font-size: var(--lt-font-size-editor);
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-editor-bg);
|
||||
border: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.rename__input--error {
|
||||
box-shadow: inset 0 -2px 0 var(--lt-error);
|
||||
}
|
||||
|
||||
.rename__hint {
|
||||
margin: 0;
|
||||
padding: var(--lt-space-xs, 2px) var(--lt-space-s, 4px);
|
||||
font-size: 0.85em;
|
||||
color: var(--lt-fg-muted);
|
||||
border-top: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.rename__hint--error {
|
||||
color: var(--lt-error);
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue