Skip to content

code/editor/CodeHover

import { … } from 'zidane-ui/code/editor'ui/src/code/editor/CodeHover.tsx

Components#

HoverCodeComponent#

A hover's code block: plain text at once, recolored in place once the highlighter answers.

TypeScript
function HoverCode(props: HoverCodeProps): Element
Parameters
NameTypeDescription
propsHoverCodeProps

code: the block's text; lang: its fence language.

Element
HoverCode props
NameTypeDescription
className?string

Extra classes on the root element.

codestring

The block's text.

langstring

The fence's language id; unknown ones stay plain.

style?CSSProperties

Inline styles on the root element, merged after the component's own.

ui/src/code/editor/CodeHover.tsx:339

Functions#

renderHoverFunction#

Minimal markdown for LSP hovers, one node per section: fenced code blocks become HoverCode (plain first, highlighted in place), other lines are paragraphs with code, bold and italic spans. No remark: a hover must paint in one frame.

TypeScript
function renderHover(markdown: string): ReactNode[]
Parameters
NameTypeDescription
markdownstring

The hover text a language server returned.

ReactNode[]

ui/src/code/editor/CodeHover.tsx:389

tokensFromHtmlFunction#

The highlighter's <pre><code><span style="color:…">… back into lines of colored runs. A run can span lines (its text holds the newlines): it is cut at each one.

TypeScript
function tokensFromHtml(html: string): HoverToken[][]
Parameters
NameTypeDescription
htmlstring

The highlighter's HTML (highlights.ts).

HoverToken[][]

ui/src/code/editor/CodeHover.tsx:308

useHoverCardFunction#

Drives the hover card for a code view: wire onEnter / onLeave to the view's token events and render node (a portal) anywhere.

TypeScript
function useHoverCard(
  fetch: ((line: number, column: number) => Promise<HoverAnswer>) | null,
  actions?: readonly HoverAction[],
  docVersion?: unknown,
  notesAt?: (line: number, column: number) => EditorDiagnostic[],
): { node: Element | null; onEnter: (t: CodeToken, _e: PointerEvent) => void; onLeave: () => void }
Parameters
NameTypeDefaultDescription
fetch((line: number, column: number) => Promise<HoverAnswer>) | null

The answer for the symbol at a 1-based (line, column); null here: findings only.

actions?readonly HoverAction[]NO_ACTIONS

Links at the card's foot (go to definition, find references).

docVersion?unknownnull

Changes whenever the document text changes; invalidates the cache.

notesAt?(line: number, column: number) => EditorDiagnostic[]

Findings to show for the hovered position, ahead of the server's answer.

{ node: Element | null; onEnter: (t: CodeToken, _e: PointerEvent) => void; onLeave: () => void }

ui/src/code/editor/CodeHover.tsx:72

Interfaces#

HoverActionInterface#

A link at the foot of the hover card.

TypeScript
interface HoverAction
HoverAction properties
NameTypeDescription
labelstring

The link's text.

run(line: number, column: number) => void | Promise<unknown>

Runs with the hovered 1-based (line, column) after the card closes.

ui/src/code/editor/CodeHover.tsx:50

HoverAnswerInterface#

What a hover fetch answers: the markdown, and why it is missing when the server is still loading.

TypeScript
interface HoverAnswer
HoverAnswer properties
NameTypeDescription
busy?string

The server is still loading ("rust-analyzer: Indexing 12/340").

textstring | null

The hover's markdown; null: nothing to show.

ui/src/code/editor/CodeHover.tsx:42

HoverCodePropsInterface#

Props for HoverCode.

TypeScript
interface HoverCodeProps
HoverCodeProps properties
NameTypeDescription
className?string

Extra classes on the root element.

codestring

The block's text.

langstring

The fence's language id; unknown ones stay plain.

style?CSSProperties

Inline styles on the root element, merged after the component's own.

ui/src/code/editor/CodeHover.tsx:323