Skip to main content

Syntax

Struct Syntax 

Source
pub struct Syntax { /* private fields */ }

Implementations§

Source§

impl Syntax

Source

pub fn for_language(lang: Lang) -> Result<Option<Syntax>, SyntaxError>

Build a Syntax for the given language using a fresh standard registry. Convenient when the caller doesn’t already hold a shared registry; for the App’s hot path use Self::for_language_with_registry so all documents share one registry.

Lang::Plain returns None because there’s nothing to parse.

Source

pub fn for_language_with_registry( lang: Lang, registry: Arc<LangRegistry>, ) -> Result<Option<Syntax>, SyntaxError>

Build a Syntax borrowing from a shared registry. Multiple documents (and the help-buffer system) all share one Arc<LangRegistry>; per-document state stays in the Highlighter + source.

Source

pub fn snapshot(&self) -> &SyntaxSnapshot

Borrow the read-only snapshot of the latest parse state. Callers that want to share the snapshot cheaply (across threads, into ArcSwap) clone it; readers that just need one method call use the pass-through helpers below.

Source

pub fn snapshot_owned(&self) -> SyntaxSnapshot

Owned clone of the snapshot. Cheap (Arc-shareable fields).

Source§

impl Syntax

Source

pub fn lang(&self) -> Lang

Convenience getter for self.snapshot().lang(). Kept on Syntax so &Syntax callers (help-buffer markdown highlighting, tests) don’t have to thread .snapshot() through.

Source

pub fn tree(&self) -> Option<&Tree>

Convenience getter for self.snapshot().tree().

Source

pub fn source(&self) -> &[u8] ⓘ

Convenience getter for self.snapshot().source().

Source

pub fn registry(&self) -> &LangRegistry

Convenience getter for self.snapshot().registry().

Source

pub fn cursor_in_string_scope(&self, cursor_byte: usize) -> bool

Convenience pass-through to SyntaxSnapshot::cursor_in_string_scope.

Source

pub fn collect_symbols(&self) -> Vec<String>

Convenience pass-through to SyntaxSnapshot::collect_symbols.

Source

pub fn collect_symbol_locations(&self) -> Vec<(String, u32, u32)>

Convenience pass-through to SyntaxSnapshot::collect_symbol_locations.

Source

pub fn scope_at_cursor( &self, line: u32, col_byte: u32, capture_suffix: &str, ) -> Option<Range>

Convenience pass-through to SyntaxSnapshot::scope_at_cursor.

Source

pub fn highlight_lines( &self, start_line: u32, end_line: u32, ) -> Result<Vec<Vec<StyledSpan>>, SyntaxError>

Convenience pass-through to SyntaxSnapshot::highlight_lines. Note: takes &self (the read API never needed &mut).

Source

pub fn highlight_lines_native( &self, start_line: u32, end_line: u32, ) -> Result<Vec<Vec<StyledSpan>>, SyntaxError>

Convenience pass-through to SyntaxSnapshot::highlight_lines_native.

Source

pub fn parse(&mut self, source: &str)

Replace the cached source and drive a tree-sitter (re)parse. This is the only mutating call on Syntax; everything else is read-only against the snapshot. Production callers should route parse requests through crate::SyntaxHandle so the parse runs off the UI thread (paramount goal #1).

Source

pub fn parse_at(&mut self, source: &str, text_version: u64)

parse variant that also stamps a caller-supplied text_version onto the resulting snapshot. The async handle uses this so consumers can deduplicate stale snapshots.

Full reparse (passes None as the prior tree). The incremental sibling Self::parse_at_with_edits is the keystroke-path entry point; this method is the file-load / cold-start / fallback path.

Parser::parse returning None means cancellation, which we don’t trigger on this synchronous path. Keep the old tree in that unlikely case rather than dropping it – the next parse round will retry.

Source

pub fn parse_at_with_edits( &mut self, source: &str, text_version: u64, from_version: u64, edits: &[EditDelta], )

Incremental reparse: apply edits to the cached tree (sync pre-step on the worker, ~500ns per edit), then parse with the edited tree as the seed (~50µs floor on medium files per §8.2). Falls back to Self::parse_at (full reparse) if the guards on Self::try_apply_intermediate fail.

Slice C.2 split this into two halves so the worker can publish an intermediate snapshot between them – byte ranges shifted to track the edit but tree shape pre-parse, so renderers see byte-aligned spans during the entire parse window. This convenience runs both halves back-to- back without an intermediate publish; the worker calls the two halves directly with the publish in between.

Source

pub fn try_apply_intermediate( &mut self, source: &str, text_version: u64, from_version: u64, edits: &[EditDelta], ) -> Result<(), ()>

Slice C.2: try to apply edits to the cached tree and update source + text_version, WITHOUT running Parser::parse. Returns Ok(()) if the resulting state is valid for the worker to publish as an intermediate snapshot (byte ranges shifted via tree.edit to track the edits; tree shape is pre-parse for the changed regions). Returns Err(()) if any of:

  1. No cached tree – first reparse / worker recovered from prior cancellation; nothing to seed with.
  2. from_version mismatch – worker’s tree isn’t at the version the edits expect to start from. Indicates a dropped reparse request, file load, or document replace; the cached tree’s byte ranges don’t match the edits.
  3. edits empty – nothing to apply.
  4. Byte-length mismatch – accumulated edit delta doesn’t match the source-length delta. Catches dropped or truncated edit lists.

On Err, the caller falls back to Self::parse_at (full reparse).

Tree-sitter’s failure mode for a malformed InputEdit is a silently wrong tree, not a panic. The layered guards here + the slice-B.4 parametrized parity matrix (incremental == full reparse across 27 edit shapes × Rust / Python / JavaScript / Markdown) keep the silent- corruption surface contained.

Source

pub fn reparse_with_cached_tree(&mut self, reparsed_from: u64)

Slice C.2: re-parse using self.inner.source and the cached tree (assumed to already have tree.edit applied via Self::try_apply_intermediate) as seed. Updates self.inner.tree to the freshly-parsed shape.

Pairs with try_apply_intermediate: the worker calls try_apply_intermediate (fast), publishes the intermediate snapshot, then calls this to run the actual parse (slow).

Trait Implementations§

Source§

impl Debug for Syntax

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> IntoMaybeUndefined<T> for T

§

fn into_maybe_undefined(self) -> MaybeUndefined<T>

Converts this value into a three-state builder argument.
§

impl<T> IntoOption<T> for T

§

fn into_option(self) -> Option<T>

Converts this value into an optional builder argument.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Pointer = u32

§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more