Hover
textDocument/hover — Markdown documentation cards for Pine builtins from metadata.
This page
Hover
Abstract
Hover answers “what is this identifier?” for builtins, then user enums, then keywords. The handler extracts the word under the cursor (including dotted forms), looks up metadata / enum members / PINE_KEYWORDS, and returns a Markdown card. Local functions and variables still return null (use definition).
Conceptual model
Rendering…
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.). - Builtin lookup: full word, then leaf after
., thenmodule.wordif the preceding token ends with.. - Else user-enum type or
Enum.memberfrom the cached AST. - Else keyword brief from
PINE_KEYWORDS. - 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 functions / locals / UDTs are not inferred for hover (enums are). 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 |