pub struct SyntaxWorker { /* private fields */ }Expand description
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.
§Examples
use std::sync::Arc;
use hjkl_syntax::SyntaxWorker;
use hjkl_bonsai::DotFallbackTheme;
use hjkl_lang::LanguageDirectory;
let theme = Arc::new(DotFallbackTheme::dark());
let dir = Arc::new(LanguageDirectory::new().unwrap());
let worker = SyntaxWorker::spawn(theme, dir);
drop(worker); // joins the threadImplementations§
Source§impl SyntaxWorker
impl SyntaxWorker
Sourcepub fn spawn(
theme: Arc<dyn Theme + Send + Sync>,
directory: Arc<LanguageDirectory>,
) -> Self
pub fn spawn( theme: Arc<dyn Theme + Send + Sync>, directory: Arc<LanguageDirectory>, ) -> Self
Spawn a fresh worker thread with the given theme and language directory.
Sourcepub fn set_language(&self, id: BufferId, grammar: Option<Arc<Grammar>>)
pub fn set_language(&self, id: BufferId, grammar: Option<Arc<Grammar>>)
Set / replace the highlighter for a buffer. None detaches.
Sourcepub fn forget(&self, id: BufferId)
pub fn forget(&self, id: BufferId)
Forget all worker state for a buffer (highlighter + tree). Sent on buffer close.
Sourcepub fn set_theme(&self, theme: Arc<dyn Theme + Send + Sync>)
pub fn set_theme(&self, theme: Arc<dyn Theme + Send + Sync>)
Replace the theme used for capture → style resolution.
Sourcepub fn try_recv_latest(&self) -> Option<RenderOutput>
pub fn try_recv_latest(&self) -> Option<RenderOutput>
Drain all available render results, returning the most recent one. Earlier results are discarded — they’d just be overwritten by the latest install anyway, and this keeps the install path O(1) per frame regardless of backlog depth.
Sourcepub fn try_recv_all(&self) -> Vec<RenderOutput>
pub fn try_recv_all(&self) -> Vec<RenderOutput>
Drain all available render results, returning them all (one per
(buffer_id, kind) pair that completed). Unlike
Self::try_recv_latest this does not discard earlier results —
required so pre-warmed results for non-active buffers can be routed
to the right slot cache.
Sourcepub fn wait_for_latest(&self, timeout: Duration) -> Option<RenderOutput>
pub fn wait_for_latest(&self, timeout: Duration) -> Option<RenderOutput>
Wait up to timeout for the next result, then drain anything
else that arrived after it and return the latest.
Sourcepub fn wait_then_recv_all(&self, timeout: Duration) -> Vec<RenderOutput>
pub fn wait_then_recv_all(&self, timeout: Duration) -> Vec<RenderOutput>
Wait up to timeout for the first result to arrive, then drain
every additional result already in the channel. Returns ALL
results in arrival order (latest per (buffer_id, kind) coalesced).
Unlike Self::wait_for_latest this does NOT discard earlier
results — required when pre-warming non-active buffers so both the
active buffer’s result and pre-warm results reach their slot caches.