Repository navigation
mac: hover resolves \ref, \cite and \includegraphics instead of pointing at them - #236
Merged
Merged
Conversation
…ing at them
Hover already documented commands, environments and diagnostics, but a
cross-reference only got a navigation hint: "⌘-click to go to \label{eq:main}"
tells the reader nothing they did not already know. It now answers the question
hovering actually asks — what is over there.
- `\ref{key}` → the float, math environment or heading the matching `\label`
sits in, with that item's own text and line: `Section “Fourier analysis” —
line 12`, `Figure “A sine wave” — line 40`, and the file when the label lives
in another open document.
- `\cite{key}` → the bibliography entry: a `\bibitem` in the buffer first, then
the project's `.bib` files parsed as BibTeX (braced, quoted and bare values;
`@string`/`@comment` skipped) → `Knuth and Lamport — Literate Programming
(1984) · The Computer Journal`.
- `\includegraphics{plot}` → the path graphicx actually reads, tried in its
order over `\graphicspath` roots × the pdflatex extension list, or the
candidates that were tried when none exists.
No numbers are invented. The editor can see which section or float a label is
in, but not the number LaTeX will print: that depends on counters, `\include`
order, starred headings and the class, none of which the project index reports.
The kind and the text are what disambiguate two similar keys, and they are
never a guess. Likewise an unsaved project cannot probe files, so the graphics
hover says so rather than claiming the file is missing.
Resolution is pure over the document text plus one `HoverContext` (the other
open documents, one `fileExists` probe), so every case is tested without a
shell model or a disk. The probe goes through `ProjectDocuments.rootedFile`,
so `\includegraphics{../../etc/passwd}` cannot be used to test for files
outside the project root.
Implementation-Agent: claude-mac-lsp
Commit-Executor: claude-mac-lsp
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hover already documented commands, environments and diagnostics (
EditorIntelligence.quickInfo), but a cross-reference only got a navigation hint: "⌘-click to go to\label{eq:main}" tells the reader nothing they did not already know. It now answers the question hovering actually asks — what is over there.\ref{sec:f}\label{sec:f}.Section “Fourier analysis” — line 12\ref{fig:s}\label{fig:s}.Figure “A sine wave” — line 40 in ch/two.tex\cite{knuth84}Knuth and Lamport — Literate Programming (1984) · The Computer Journal\includegraphics{plot}Resolves to figures/plot.pngHow
EditorHoverResolution.swift(new) resolves each kind:\ref→ the float, math environment or heading the matching\labelsits in, with that item's own text and line. The innermost labelled environment wins over the enclosing section, so a\labelin afigurereads as the figure, not the section around it.\cite→ a\bibitemin the buffer first, then the project's other documents parsed as BibTeX: braced, quoted and bare values, nested braces,@string/@comment/@preambleskipped,authorshortened to surnames (Knuth et al.from three).\includegraphics→ the path graphicx actually reads, tried in its order over the\graphicspathroots × the pdflatex extension list (.pdf .png .jpg .jpeg .eps), or the candidates that were tried when none exists.What it deliberately does not do
It invents no numbers. The editor can see which section or float a label is in, but not the number LaTeX will print for it: that depends on counters,
\includeorder, starred headings, appendices and the class's numbering scheme, none of which the project index reports (Completion.Metadatacarries names and counts, not numbers). The kind and the text are what disambiguate two similar keys, and they are never a guess.Likewise an unsaved project cannot probe files, so the graphics hover says "Resolved against the project root when the document is saved." rather than claiming the file is missing.
Safety
The file probe goes through
ProjectDocuments.rootedFile, so\includegraphics{../../etc/passwd}cannot be used to test for the existence of files outside the project root, and a symlinked segment is refused.Tests
18 new cases in
EditorHoverResolutionTests, all pure — the project is in-memory documents plus onefileExistsclosure, so nothing touches a shell model or a disk. One existing expectation inEditorIntelligenceTestsupdated (the\refdoc line is now two lines).🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu