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

Diagram

Rendering…

Interface surface

  • Method: textDocument/hover
  • Capability: hover_provider=True
  • Handler: features/hover.pyhandle_hover

Lookup order

  1. Exact word at cursor via get_word_at_position (identifiers may include .).
  2. Builtin lookup: full word, then leaf after ., then module.word if the preceding token ends with ..
  3. Else user-enum type or Enum.member from the cached AST.
  4. Else keyword brief from PINE_KEYWORDS.
  5. 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

PathRole
features/hover.pyWord resolution + Markdown assembly
providers/builtin_metadata.pyget_builtin
protocol/utils.pyWord extraction

Invariants and edge cases

  1. No source → null. Missing buffer aborts early.
  2. Line OOB → null. Cursor past last line is ignored.
  3. Empty word → null. Whitespace / punctuation yields no hover.
  4. User functions / locals / UDTs are not inferred for hover (enums are). Use definition / outline instead.
  5. 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.sma if the dotted identifier is one match, or sma with module recovery from ta..
  • Response contents.kind = markdown with fence of the metadata detail line.

Failure modes

SymptomCause
Hover never appearsMetadata empty or word not in catalog
Wrong symbolIdentifier regex swallowed neighboring text — rare with _. pattern
Stale docs after adding builtinRegenerate metadata — builtin metadata

See also