[Hover]
textDocument/hover — Markdown documentation cards for Pine builtins from metadata.
Hover
Abstract
Hover answers “what is this identifier?” for builtins. The handler extracts the word under the cursor (including dotted forms), looks up metadata, and returns a Markdown card: signature fence, brief, optional long documentation, curated examples, and related symbols. User-defined symbols without metadata return null.
Conceptual model
Interface surface
- Method:
textDocument/hover - Capability:
hover_provider=True - Handler:
features/hover.py→handle_hover
Lookup order
- Exact word at cursor via
get_word_at_position(identifiers may include.). - If no metadata hit, inspect text before the word: if it ends with
module., trymodule.word. - Build hover with range covering
[start, end)of the word on the line.
Card structure
{detail}
{brief}
---
{first documentation paragraph, ≤500 chars}
**Example:** …
**See also:** `ta.ema`, …
Examples and related maps are hardcoded for a small high-value set (ta.sma, ta.ema, ta.rsi, ta.macd, strategy entry/exit, etc.). Others show signature + brief only.
External TradingView doc links are intentionally omitted (_build_docs_link returns empty) to keep hover self-contained.
Internals
| Path | Role |
|---|---|
features/hover.py | Word resolution + Markdown assembly |
providers/builtin_metadata.py | get_builtin |
protocol/utils.py | Word extraction |
Invariants and edge cases
- No source → null. Missing buffer aborts early.
- Line OOB → null. Cursor past last line is ignored.
- Empty word → null. Whitespace / punctuation yields no hover.
- User symbols (local variables, UDTs) are not inferred for hover; use definition / outline instead.
- Documentation truncation is first-paragraph / 500-char only — full docs live in metadata and completion resolve.
Worked example
Cursor on sma in plot(ta.sma(close, 14)):
- Word may be
ta.smaif the dotted identifier is one match, orsmawith module recovery fromta.. - Response
contents.kind = markdownwith fence of the metadatadetailline.
Failure modes
| Symptom | Cause |
|---|---|
| Hover never appears | Metadata empty or word not in catalog |
| Wrong symbol | Identifier regex swallowed neighboring text — rare with _. pattern |
| Stale docs after adding builtin | Regenerate metadata — builtin metadata |