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
impl LangRegistry
Sourcepub fn standard() -> Result<Arc<Self>, SyntaxError>
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.
Sourcepub fn folds_query(&self, name: &str) -> Option<&Query>
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.
Sourcepub fn highlights_query(&self, name: &str) -> Option<&Query>
pub fn highlights_query(&self, name: &str) -> Option<&Query>
Compiled highlights.scm query for the native pipeline.
Sourcepub fn highlight_styles(&self, name: &str) -> Option<&[Style]>
pub fn highlight_styles(&self, name: &str) -> Option<&[Style]>
Per-capture Style table aligned with highlights_query’s
capture_names().
Sourcepub fn highlight_priorities(&self, name: &str) -> Option<&[u32]>
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.
Sourcepub fn indents_query(&self, name: &str) -> Option<&Query>
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.
Sourcepub fn injections_query(&self, name: &str) -> Option<&Query>
pub fn injections_query(&self, name: &str) -> Option<&Query>
Compiled injections.scm query, when one is registered.
Sourcepub fn symbols_query(&self, name: &str) -> Option<&Query>
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).
Sourcepub fn textobjects_query(&self, name: &str) -> Option<&Query>
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.
Sourcepub fn tree_sitter_language(&self, name: &str) -> Option<Language>
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+.
Sourcepub fn conceal_rules(&self, name: &str) -> Arc<[ConcealRule]> ⓘ
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.
Sourcepub fn has_lang(&self, name: &str) -> bool
pub fn has_lang(&self, name: &str) -> bool
True if a config exists for the given canonical language name.
Sourcepub fn lang_names(&self) -> impl Iterator<Item = &&'static str>
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
impl Clone for LangRegistry
Source§fn clone(&self) -> LangRegistry
fn clone(&self) -> LangRegistry
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 LangRegistry
impl Debug for LangRegistry
Source§impl Default for LangRegistry
impl Default for LangRegistry
Source§fn default() -> LangRegistry
fn default() -> LangRegistry
Auto Trait Implementations§
impl Freeze for LangRegistry
impl RefUnwindSafe for LangRegistry
impl Send for LangRegistry
impl Sync for LangRegistry
impl Unpin for LangRegistry
impl UnsafeUnpin for LangRegistry
impl UnwindSafe for LangRegistry
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