Skip to main content

GrammarLoader

Struct GrammarLoader 

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

Dynamic grammar loader with caching.

Implementations§

Source§

impl GrammarLoader

Source

pub fn new() -> Self

Create a new grammar loader with default search paths.

Search order:

  1. NORMALIZE_GRAMMAR_PATH environment variable (colon-separated)
  2. ~/.config/normalize/grammars/
Source

pub fn with_paths(paths: Vec<PathBuf>) -> Self

Create a loader with custom search paths.

Source

pub fn add_path(&mut self, path: PathBuf)

Add a search path.

Source

pub fn get(&self, name: &str) -> Result<Language, GrammarLoadError>

Get a grammar by name.

Returns Ok(lang) if found and loaded successfully, Err(GrammarLoadError::NotFound) if no .so/.dylib exists in any search path, and other Err variants for load or ABI failures.

Source

pub fn get_highlights(&self, name: &str) -> Option<Arc<String>>

Get the highlight query for a grammar.

Returns None if no highlight query found for the grammar. Query files are {name}.highlights.scm in the grammar search paths.

Source

pub fn get_injections(&self, name: &str) -> Option<Arc<String>>

Get the injection query for a grammar.

Returns None if no injection query found for the grammar. Query files are {name}.injections.scm in the grammar search paths.

Source

pub fn get_locals(&self, name: &str) -> Option<Arc<String>>

Get the locals query for a grammar.

Returns None if no locals query found for the grammar. Query files are {name}.locals.scm in the grammar search paths.

Source

pub fn get_complexity(&self, name: &str) -> Option<Arc<String>>

Get the complexity query for a grammar.

Returns None if no complexity query found for the grammar. Query files are {name}.complexity.scm in the grammar search paths. Uses @complexity captures for nodes that increase cyclomatic complexity, and @nesting captures for nodes that increase nesting depth.

Source

pub fn get_calls(&self, name: &str) -> Option<Arc<String>>

Get the calls query for a grammar.

Returns None if no calls query found for the grammar. Query files are {name}.calls.scm in the grammar search paths. Uses @call captures for call expressions and @call.qualifier for method call receivers (e.g. foo in foo.bar()).

Source

pub fn get_types(&self, name: &str) -> Option<Arc<String>>

Get the types query for a grammar.

Returns the bundled query for supported languages, or an external file if one exists at {name}.types.scm in the grammar search paths (external wins).

Source

pub fn get_tags(&self, name: &str) -> Option<Arc<String>>

Get the tags query for a grammar.

Tags queries use the tree-sitter tags format with @name.definition.* and @name.reference.* captures for symbol navigation (used by GitHub Linguist, nvim-treesitter, etc.).

Returns the bundled query for supported languages, or an external file if one exists at {name}.tags.scm in the grammar search paths (external wins).

Source

pub fn get_imports(&self, name: &str) -> Option<Arc<String>>

Get the imports query for a grammar.

Returns the bundled query for supported languages, or an external file if one exists at {name}.imports.scm in the grammar search paths (external wins).

Source

pub fn get_decorations(&self, name: &str) -> Option<Arc<String>>

Get the decorations query for a grammar.

Returns the bundled query for supported languages, or an external file if one exists at {name}.decorations.scm in the grammar search paths (external wins). Uses @decoration captures for doc comments, attributes, decorators, and annotations that immediately precede a definition.

Source

pub fn get_test_regions(&self, name: &str) -> Option<Arc<String>>

Get the test-regions query for a grammar.

Returns None if no test-regions query exists for the grammar. Query files are {name}.test_regions.scm in the grammar search paths. Uses @test_region captures for byte ranges of test-only code that rules may opt to skip (via applies_in_tests = false, the default).

Languages without a .test_regions.scm simply have no AST-based test detection — path-based excludes (e.g. **/tests/** or *_test.go) remain the way to scope rules in those cases.

Source

pub fn get_compiled_query( &self, grammar_name: &str, query_type: &str, query_str: &str, ) -> Option<Arc<Query>>

Get a compiled tree-sitter query, using the cache to avoid recompilation.

grammar_name is the grammar name (e.g. “rust”, “python”). query_type is the query category (e.g. “tags”, “complexity”, “calls”). query_str is the raw .scm query string.

Returns the compiled query or None if compilation fails.

Source

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

List available grammars in search paths.

Source

pub fn available_external_with_paths(&self) -> Vec<(String, PathBuf)>

List available grammars in search paths, with their file paths.

Trait Implementations§

Source§

impl Default for GrammarLoader

Source§

fn default() -> Self

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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