Skip to content

mac: hover resolves \ref, \cite and \includegraphics instead of pointing at them - #236

Merged
GoKubar merged 1 commit into
mainfrom
agent/mac-hover-resolution
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/mac-hover-resolution

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

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.

hovering before now
\ref{sec:f} ⌘-click to go to \label{sec:f}. Section “Fourier analysis” — line 12
\ref{fig:s} ⌘-click to go to \label{fig:s}. Figure “A sine wave” — line 40 in ch/two.tex
\cite{knuth84} ⌘-click to go to the bibliography entry. Knuth and Lamport — Literate Programming (1984) · The Computer Journal
\includegraphics{plot} (nothing) Resolves to figures/plot.png

How

EditorHoverResolution.swift (new) resolves each kind:

  • \ref → the float, math environment or heading the matching \label sits in, with that item's own text and line. The innermost labelled environment wins over the enclosing section, so a \label in a figure reads as the figure, not the section around it.
  • \cite → a \bibitem in the buffer first, then the project's other documents parsed as BibTeX: braced, quoted and bare values, nested braces, @string/@comment/@preamble skipped, author shortened to surnames (Knuth et al. from three).
  • \includegraphics → the path graphicx actually reads, tried in its order over the \graphicspath roots × 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, \include order, starred headings, appendices and the class's numbering scheme, none of which the project index reports (Completion.Metadata carries 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 one fileExists closure, so nothing touches a shell model or a disk. One existing expectation in EditorIntelligenceTests updated (the \ref doc line is now two lines).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant