Skip to main content

Crate hjkl_syntax

Crate hjkl_syntax 

Source
Expand description

Renderer-agnostic syntax-highlighting pipeline for the hjkl editor stack.

Owns a SyntaxWorker background thread (holding the Highlighter and retained tree_sitter::Tree) plus a main-thread RenderCache of (source, row_starts). Call SyntaxLayer::set_language_for_path after opening a file, then SyntaxLayer::apply_edits for each frame’s queued hjkl_engine::ContentEdit batch and SyntaxLayer::submit_render to enqueue a parse + viewport-scoped highlight on the worker. Drain results via SyntaxLayer::take_all_results each frame and route them to the correct per-slot cache field.

§Design

Output is renderer-agnostic: RenderOutput::spans carries (byte_start, byte_end, StyleSpec) triples rather than renderer-specific style types. A TUI adapter ([hjkl-syntax-tui]) maps these to ratatui::style::Style; a future GUI adapter will map them to cosmic_text attributes.

Structs§

Color
Resolved RGBA color (all channels 0–255).
DiagSign
A single diagnostic sign emitted from the syntax pipeline.
Modifiers
Per-character text modifiers.
PerfBreakdown
Per-call sub-step timings exposed to apps’ :perf overlay. Recorded on the worker side and shipped back inside RenderOutput.
RenderOutput
Per-frame output of the syntax worker.
StyleSpec
Foreground, background, and modifier flags for a syntax or UI element.
SyntaxLayer
Per-App syntax highlighting layer. Multiplexes per-buffer state (helix-style): each open buffer carries its own retained tree (worker-side) plus source-cache and edit queue (here). One worker thread serves all buffers.
SyntaxWorker
Background worker that owns the Highlighter and the retained tree-sitter Tree. Communicates with the main thread via a Mutex<Pending> + Condvar for submits, and an mpsc channel for rendered output.

Enums§

LoadEvent
Event emitted by SyntaxLayer::poll_pending_loads for each handle that resolved during the tick.
LoadEventKind
Exhaustive view of a LoadEvent for use in SyntaxLayer::dispatch_load_event callbacks.
ParseKind
Discriminates the purpose of a parse request / result so the App can route it to the correct per-slot cache field.
ParseKindKind
Exhaustive view of a ParseKind for use in SyntaxLayer::dispatch_parse_kind callbacks.
SetLanguageOutcome
Outcome of SyntaxLayer::set_language_for_path.

Functions§

build_by_row
Resolve flat highlight spans into a per-row span table sized to row_count. Pulled out so the worker can call it in isolation and tests can exercise it without a running thread.
layer_with_theme
Build a SyntaxLayer using the given theme + language directory.

Type Aliases§

BufferId
Stable identifier for an open buffer. Assigned by the App; carried through every syntax-pipeline message so the worker can multiplex per-buffer tree state.