pub struct SyntaxHandle { /* private fields */ }Expand description
Editor-facing handle. Cheap to clone; cloning gives a reference to the same underlying snapshot cell + the same reparse-request channel.
Implementations§
Source§impl SyntaxHandle
impl SyntaxHandle
Sourcepub fn spawn(
lang: Lang,
registry: Arc<LangRegistry>,
) -> Result<Option<Self>, SyntaxError>
pub fn spawn( lang: Lang, registry: Arc<LangRegistry>, ) -> Result<Option<Self>, SyntaxError>
Build a handle for lang and start the worker task.
Returns Ok(None) for Lang::Plain or any language not
registered in the supplied registry – the App treats
None as “no syntax highlighting for this buffer”.
Sourcepub fn seeded(syntax: Syntax) -> Self
pub fn seeded(syntax: Syntax) -> Self
Wrap a pre-built Syntax (already parsed or not) in a
handle. Used by tests that want to drive parses
synchronously and then read the result, and by callers
that already constructed a Syntax for other reasons
(one-shot help-buffer markdown highlighting).
Production callers must use Self::seeded_with_runtime
instead. This method falls back to
Handle::try_current() which silently fails when the
caller hasn’t entered a tokio context (notably: editor
startup runs from a synchronous main(), before the
runtime is set up). When that fails, the worker is never
spawned and request_reparse calls go to a dropped
channel – the snapshot stays at the seeded state forever
and no reparses ever run. LSP solved the same problem
with an explicit runtime handle (see app.rs:96-100); this
constructor remains for tests that already run inside a
tokio context.
Sourcepub fn seeded_with_runtime(
syntax: Syntax,
runtime: &Handle,
on_publish: Option<Arc<dyn Fn() + Send + Sync + 'static>>,
) -> Self
pub fn seeded_with_runtime( syntax: Syntax, runtime: &Handle, on_publish: Option<Arc<dyn Fn() + Send + Sync + 'static>>, ) -> Self
Wrap a pre-built Syntax and spawn the worker on the
supplied tokio runtime handle. This is the production
constructor. Mirrors what
lattice_lsp::supervisor::LspSupervisor::spawn does: take
an explicit handle so the worker actually starts even when
the caller hasn’t entered a tokio context yet (editor
startup runs from synchronous main() and constructs the
handle before the main loop enters tokio).
Without this, Handle::try_current() in Self::seeded
silently fails, the worker is never spawned, and Option B’s
entire incremental-reparse pipeline is dead – request_reparse
sends to a dropped channel, the snapshot stays at the seeded
state, and no edit ever produces a fresh tree. The user-visible
symptom is “syntax highlighting is stuck to byte positions and
never tracks document edits” – which was the bug originally
reported against indent (>>) and backspace flows.
on_publish, when Some, is called after every snapshot publish
(both the intermediate edit-shift and the final reparse).
Production passes a closure that fires the host’s async_landed
Notify (waking the actor) and publishes a SyntaxReparsed event
on the event bus; the event subscriber then fires cells_wake so
idle reparses repaint without a keystroke. Tests pass None.
Sourcepub fn snapshot(&self) -> Arc<SyntaxSnapshot> ⓘ
pub fn snapshot(&self) -> Arc<SyntaxSnapshot> ⓘ
Wait-free read of the latest parse snapshot. Hot path; renderer / fold provider / completion call this on every frame.
Sourcepub fn with_snapshot<R>(&self, f: impl FnOnce(&SyntaxSnapshot) -> R) -> R
pub fn with_snapshot<R>(&self, f: impl FnOnce(&SyntaxSnapshot) -> R) -> R
Borrow the snapshot via ArcSwap’s short-lived guard.
Cheaper than Self::snapshot when the caller only
needs to read a single field (no Arc::clone).
Sourcepub fn request_reparse(
&self,
from_version: u64,
text_version: u64,
buffer: Buffer,
edits: Vec<EditDelta>,
)
pub fn request_reparse( &self, from_version: u64, text_version: u64, buffer: Buffer, edits: Vec<EditDelta>, )
Request that the worker reparse buffer and stamp the
resulting snapshot with text_version. Fire-and-forget;
the new snapshot is observable via Self::snapshot
once the worker completes the parse.
Slice B.5: takes Buffer (clones in O(1) via ropey’s
internal Arc) rather than String. The full source
materialization moves to the worker, off the input
thread.
from_version is the version-baseline the worker’s tree
is expected to be at BEFORE applying edits. The worker
uses it to detect mismatches (dropped requests, file
load, document replace) and falls back to full reparse
when the cached tree’s version doesn’t match.
edits carries the tree-sitter-shaped deltas in apply
order, taking the buffer from from_version to
text_version. Empty edits = “do a full reparse”
(file load / cold-start path).
Coalesced: queued requests’ edits are accumulated in
order; the latest queued request’s buffer and
text_version win; the earliest queued request’s
from_version survives so the burst’s baseline is
preserved.
Trait Implementations§
Source§impl Clone for SyntaxHandle
impl Clone for SyntaxHandle
Source§fn clone(&self) -> SyntaxHandle
fn clone(&self) -> SyntaxHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SyntaxHandle
impl Debug for SyntaxHandle
Source§impl ExcerptHighlighter for SyntaxHandle
impl ExcerptHighlighter for SyntaxHandle
Source§fn highlight_lines(&self, lo: u32, hi: u32) -> Option<Vec<Vec<StyledSpan>>>
fn highlight_lines(&self, lo: u32, hi: u32) -> Option<Vec<Vec<StyledSpan>>>
lo..hi (exclusive).
The returned Vec has exactly (hi - lo) entries; an empty inner
Vec means “no spans on that line” (fall back to default fg).
Returns None when the highlight snapshot is stale or unavailable.Source§fn highlight_version(&self) -> u64
fn highlight_version(&self) -> u64
MatrixVersion::syntax without taking a dep on SyntaxHandle internals.Auto Trait Implementations§
impl Freeze for SyntaxHandle
impl RefUnwindSafe for SyntaxHandle
impl Send for SyntaxHandle
impl Sync for SyntaxHandle
impl Unpin for SyntaxHandle
impl UnsafeUnpin for SyntaxHandle
impl UnwindSafe for SyntaxHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more