Repository navigation
Conversation
Pass an explicit CaretContext built from the clicked diff pane so references use that pane's attached document instead of the active editor.
The revision (HEAD) side of a diff now supports hover links and Ctrl+click like an editor, with stock language servers: the IDE sets the document's text to the revision's, asks for a definition, and restores the working copy when it is needed again. - A rev side attaches its text as a git-revision: document. - lsp_goto routes Definition on such a document to the working document of the blob's path and LspManager::revision_definition. - The manager keeps the revision text in place while the diff is in use and restores every document of the file on the next working-copy request or edit; server versions are owned per file. - Targets inside the same blob are mapped from revision lines to working-copy lines. Only standard LSP: no language server changes.
arookieofc-ai
left a comment
There was a problem hiding this comment.
Read the whole thing — the similar-based line mapping, the git-revision: URI helpers, the LspManager text swap and restore, the LspObserver skip, the DiffEditor context-menu wiring, and the tests.
Swapping the working document's text is the right primitive for this. The server already has the working copy open, so putting the revision's text on it for the duration of one request gets a real answer from a real server without a second document, a second server, or a git-revision: URI the server would reject. RevisionBusy's Drop is the careful part: a cancelled request (the editor abandons a jump) still clears the flag, so the document cannot be left permanently "busy" and permanently swapped. next_version's per-file counter, with the comment about an editor tab and a diff pane sharing one server document, is the right fix for the version-collision problem that would otherwise make the server drop the change as stale.
Also good: extracting RevisionTarget / revision_target / revision_blob_path so the URI is decoded in one place instead of twice; restore_revision at the top of the request path and of did_change, so the working text comes back before anything else reads it; the LspObserver skip with its comment explaining why a revision blob is never did_opened; findUsages(c: CaretContext | null = caretContext()) keeping every existing caller working; and the gitRevisionUri unit test decoding the payload back rather than asserting on the string.
Things I would fix before merge:
-
revision_hits_map_onto_the_working_copycannot pass. It assertsrefs.locations[0].range.end.line == 4, but the code computesline = map_line("a\nb\nc\n", "a\nX\nb\nc\n", 1) = 2, thendelta = 2 - 1 = 1, thenend.line = 1 + 1 = 2. The assertion should be2. As written the PR's test suite is red, which also means the mapping has not actually been exercised end to end. -
lsp_gotoswallows the "no target" signal.return Ok(revision_targets(...).await?.unwrap_or_default())— butrevision_targetsnever returnsOk(None); every path returnsOk(Some(...)). Its own doc comment says a server without the revision method "ends with no target, leaving the ordinary path to answer", and thereturnmeans the ordinary path never runs. TheOk(Some(Vec::new()))case (no working copy open) is likewise turned into an empty result rather than a fallback. Either returnNonefromrevision_targetsand fall through, or drop the sentence from the comment. -
map_revision_referencesruns a full Myers diff per location.map_linere-diffs the whole file on every call, andonecalls it once per hit, so N hits in one file cost N full-file diffs. Build the line map once per file and look up each hit. -
revision_busyis keyed byDocIdwhileswappedis keyed byPathBuf.restore_revisionreturns early only when this document is busy, so a request from the editor tab on the same file is not blocked by the diff pane's busy flag and can put the working text back mid-request. Keying the busy set by path would make the guard match what it is protecting. -
send_full_textwrites to the server's stdin while thedocslock is held. Bothswap_revision_textandrestore_revisioncall it inside thedocsguard, so a blocked or slow server pipe stalls every document operation in the manager. Collecting the notifications and sending them after the guard is dropped would keep the lock short. -
arm_revision_restorespawns an uncancellable 30 s timer per request. A diff pane left open re-arms on every jump, and a timer armed by an older request can fire after a newer swap and restore the wrong text. There is no handle to cancel it, and the 30 s is a bare literal. -
DiffEditor.tsx'srevisionUrire-implementsgitRevisionUriinline. The same PR extracts the helper intorevisionInput.tsand then duplicates the hex encoding inDiffEditor.tsx. Worse, the two build different payloads for the same file:revisionUriusesside.path ?? path(absolute) whilerevisionUsageTargetusesrelTo(repo, filePath)(repo-relative). Both happen to resolve throughrepo.join, but two URIs for one document is exactly the kind of drift the extraction was meant to prevent. -
findUsagesItemcallswithDocument(target.path, …)with agit-revision:URI.LspObservernow explicitly refuses todid_opensuch a URI, so opening it as a document is at best a second, unanalysed document — and the request that follows would go throughrevision_references, which needs the working copy open, not this one. -
Only
GotoKind::Definitionis handled. Other goto kinds in a revision pane fall through toposition_documentwith agit-revision:URI, which is the case the comment says the servers reject. -
working_text'sstd::fs::read+String::from_utf8_lossyfallback bypasses the project's encoding detection thatrevision_textused for the blob, so a non-UTF-8 file maps lines through mojibake and the jump lands on the wrong line. -
is_revision_documentswallows errors with.ok()?. A real failure (no project, no identity) looks like "not a revision document" and silently takes the ordinary path, which is the path that cannot work for a revision pane. -
swappedandservedare keyed byPathBufand never pruned. Two diff panes on the same file at different revisions collide on one entry, andservedgrows without bound for the life of the session. -
revision_blob_pathre-parses the URI (base64 + JSON) afterrevision_virtual_documentalready did, so every jump decodes the same payload twice. -
lsp_semantic_tokensreturnsOk(None), so the diff pane loses colouring. The comment is honest about it; worth a follow-up rather than leaving it only there. -
did_change's cross-document text copy does not update the other document's version, so it holds new text with a stale version until its own next change arrives. -
navigation.ts's 10 s probe timeout is a bare literal keyed ondoc?.path.startsWith("git-revision:"); a named constant next to the 3 s one would say why the revision case is different.
Nits, non-blocking:
map_linemaps an emptynewto line 0, which is a line that does not exist.revisionUri's.at(-1)!yields""for a path ending in/.- The lock order is now
revision_busy→docs→swappedin three functions and is undocumented; the existing ledger-before-meta comment is the precedent for writing it down. revision_targets's doc comment describes a fallback that the caller does not implement (see finding 2).
LGTM on the approach — swapping the working document's text for one request, with a busy flag that survives cancellation and a per-file version counter, is the right way to answer a jump inside a revision blob.
- Fix the mapping test expectation and build the line map once per file - Make lsp_goto handle every goto kind consistently - Key the revision busy guard by path and cancel stale restore timers - Send full-text notifications outside the docs lock - Reuse the working copy's encoding detection and decode the URI once - Surface lookup errors instead of treating them as 'not a revision' - Unify revision URI construction and drop the second-document fallback - Name the revision navigation probe timeout
Blocked by #6735 — merge that first; this PR's diff shrinks to its own change
once #6735 is in.
What and why
Find Usages now works on both sides of a Compare: the revision pane on
the left, and the working copy on the right. Before this, the left side sent
the revision's
git-revision:URI straight to the language servers, whichreject it (java-analyzer "Not a file URI", gopls "DocumentURI scheme is not
file") — you got error toasts instead of results. Clicking a result opens the
working copy at the right line even when the line numbers differ between the
two sides.
Depends on #6735 for the underlying jump/navigation machinery (busy→swap→request→restore);
without it the left-side search has no way to hand the revision's text to the
servers.
How it was verified
Commands:
a1657a50e(build-with-ref) — dispatched, resultpending at draft time.
revision_hits_map_onto_the_working_copyadded (an inserted lineshifts the revision hit to the right working-copy line; other files
untouched). Not run locally — local cargo builds are off-limits per project
constraint; flagged here rather than claimed.
covering_elementfrom the left pane → 53 results; clicking one opens theworking copy at the mapped line. Repeated searches and pane switching leave
the working copy intact.
Review focus
revision_references(ide-lsp): runs the search by temporarily putting therevision's text in place of the working document (same busy→swap→request→restore
shape as
revision_definition); the working copy is restored when the request ends.map_revision_references(ide-host): maps same-file hits from the revision'sline numbers to the working copy through the file's diff — including partial
results arriving mid-search; cross-file hits keep their own coordinates.