Skip to main content

Module hover

Module hover 

Source
Expand description

§textDocument/hover — what the name under the cursor is

Three questions, in the order the preprocessor asks them:

1. is this a macro?        a name that a #define settles IS that macro at this point in the file
2. otherwise, what does it name?  the index's declaration, rendered from what the fact records
3. and if it names nothing, what is it?  the type of the expression the cursor is in — see below

Macros first because that is what the text means: #define WIDGET_MAX 8 makes WIDGET_MAX eight, and a hover that instead described some declaration of the same spelling would describe a name the compiler never saw. The analysis answers that question the same way — macro_across_files walks the #define/#undef history before the cursor’s offset, and #undef counts, so a name that was a macro answers “not a macro here” rather than pointing at the definition it no longer has.

§What is shown, and what is deliberately not

The declaration as the file writes it (the fact carries the declaration’s range, and the text is read through the session — the buffer for an open file), the qualified name, what kind of thing it is, its written type or return type, the documentation comment above it, and the caveats the fact itself records: a declaration inside a conditional block, or one the parser recovered around. That is the point of a fact-only hover: everything shown is something the analysis knows, and nothing is a guess dressed as a signature.

The third question is the one a cursor on this, *p or f(1) needs, and it is asked only when the second one names nothing: a name is what a reader is asking about, and the type of the expression around it is a fallback rather than a second answer competing with the first.

No range is set on the answer: an LSP hover may carry one, and computing it would mean deciding where the name under the cursor starts and ends — a second implementation of “what is a name” beside the one the analysis already has (sema::resolve::name_at), which is free to disagree with it. The client positions the popup itself when the answer carries none, which is what happens today.

Structs§

HoverCapabilities

Functions§

hover
hover_text
The card’s markdown, for a caller that is not speaking the protocol — a tool, a test, a probe.
on_hover