Skip to main content

LangRegistry

Struct LangRegistry 

Source
pub struct LangRegistry { /* private fields */ }
Expand description

Catalog of every supported language’s parser + highlight + injection configuration. Construct once via Self::standard and share by Arc clone.

Default produces an empty registry – used by lattice_host::editor::Editor::default() for headless / placeholder construction. Production uses Self::standard. Clone is cheap by construction: each config sits behind an Arc, so a clone is one refcount bump per language plus a small map. That is what makes the copy-on-write registration path affordable — compiling the queries for ~19 languages costs ~1.2 s and must never be repeated just because a plugin registered a twentieth.

Implementations§

Source§

impl LangRegistry

Source

pub fn standard() -> Result<Arc<Self>, SyntaxError>

The standard registry: rust, python, javascript, markdown (block + inline) and the rest. Returns an Arc so the App / multiple Syntax instances can share one allocation.

Memoised process-wide. Building it compiles five tree-sitter queries (highlights, injections, folds, symbols, textobjects) for each of ~19 languages, which measured at ~1.2 s — and Editor::boot calls this every time. In the test suite that was the dominant cost of the entire crate: one App-building test took 1.28 s against 0.01 s for a test that builds no App, and lattice-ui-tui’s 1683 tests took 779 s almost entirely on this. In production it is paid at startup, to open one file.

Sharing is safe by construction rather than by convention: a LangRegistry has no interior mutability and no &mut self method, so a snapshot cannot be observed to change under its holder. Which snapshot you get can change — LG.3a made this the live RCU value so a plugin language appears in the same map bundled ones live in, with no call-site change and no kind-branch anywhere. Registration replaces the value; holders of an older Arc keep a coherent older view until they next call this.

See live, [register_plugin_language] and [unregister_plugin].

Only success is cached. A failure here means a static query string does not compile, which is deterministic and fatal (every caller expects it), so re-deriving it costs nothing real and avoids requiring SyntaxError: Clone.

Source

pub fn folds_query(&self, name: &str) -> Option<&Query>

The compiled folds.scm Query for name, when the language ships one. Used by lattice-ui-tui::folds::compute_syntax_folds.

Source

pub fn highlights_query(&self, name: &str) -> Option<&Query>

Compiled highlights.scm query for the native pipeline.

Source

pub fn highlight_styles(&self, name: &str) -> Option<&[Style]>

Per-capture Style table aligned with highlights_query’s capture_names().

Source

pub fn highlight_priorities(&self, name: &str) -> Option<&[u32]>

Per-capture priority table (CAPTURE_NAMES position) aligned with highlights_query’s capture_names(). Lower = higher precedence on overlap.

Source

pub fn indents_query(&self, name: &str) -> Option<&Query>

IN.2: the compiled indents.scm query for name, when the language ships one. Consumed by crate::indent.

Source

pub fn injections_query(&self, name: &str) -> Option<&Query>

Compiled injections.scm query, when one is registered.

Source

pub fn symbols_query(&self, name: &str) -> Option<&Query>

Compiled symbols.scm query for the gen:tree-sitter-symbol insert-completion source (Phase 4.2.g.6 (1/2)). None for languages that don’t ship a symbols query (markdown family today).

Source

pub fn textobjects_query(&self, name: &str) -> Option<&Query>

Compiled textobjects.scm query for name (N.1.0), when the language ships one. Used by crate::SyntaxSnapshot::scope_at_cursor to resolve narrow-mode’s tree-sitter targets (:narrow-function / :narrow-class / :narrow-block). None for languages without a text-object query (markdown family today). Resolves the same aliases as the other per-query lookups.

Source

pub fn tree_sitter_language(&self, name: &str) -> Option<Language>

Resolve the tree_sitter::Language for name (with the same alias mapping as the other per-query lookups). Returned by value because Language is a cheap Arc-equivalent handle in tree-sitter 0.24+.

Source

pub fn conceal_rules(&self, name: &str) -> Arc<[ConcealRule]> ⓘ

H.2: this language’s compiled conceal rules, or an empty slice.

Returns the Arc rather than a borrow so the display-matrix build can hold the rules across a rebuild without pinning the whole registry snapshot, and so a plugin unloading mid-rebuild cannot pull them out from under it.

Empty is the answer for every language but one, and callers are expected to branch on that before doing any per-line work — the conceal path must cost a Rust buffer nothing at all.

Source

pub fn has_lang(&self, name: &str) -> bool

True if a config exists for the given canonical language name.

Source

pub fn lang_names(&self) -> impl Iterator<Item = &&'static str>

Iterate the registered language names. Useful for tests + the future :describe-mode content.

Trait Implementations§

Source§

impl Clone for LangRegistry

Source§

fn clone(&self) -> LangRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LangRegistry

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for LangRegistry

Source§

fn default() -> LangRegistry

Returns the “default value” for a type. 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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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