pub struct GrammarLoader { /* private fields */ }Expand description
Dynamic grammar loader with caching.
Implementations§
Source§impl GrammarLoader
impl GrammarLoader
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new grammar loader with default search paths.
Search order:
NORMALIZE_GRAMMAR_PATHenvironment variable (colon-separated)~/.config/normalize/grammars/
Sourcepub fn with_paths(paths: Vec<PathBuf>) -> Self
pub fn with_paths(paths: Vec<PathBuf>) -> Self
Create a loader with custom search paths.
Sourcepub fn get(&self, name: &str) -> Result<Language, GrammarLoadError>
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.
Sourcepub fn get_highlights(&self, name: &str) -> Option<Arc<String>>
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.
Sourcepub fn get_injections(&self, name: &str) -> Option<Arc<String>>
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.
Sourcepub fn get_locals(&self, name: &str) -> Option<Arc<String>>
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.
Sourcepub fn get_complexity(&self, name: &str) -> Option<Arc<String>>
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.
Sourcepub fn get_calls(&self, name: &str) -> Option<Arc<String>>
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()).
Sourcepub fn get_types(&self, name: &str) -> Option<Arc<String>>
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).
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).
Sourcepub fn get_imports(&self, name: &str) -> Option<Arc<String>>
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).
Sourcepub fn get_decorations(&self, name: &str) -> Option<Arc<String>>
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.
Sourcepub fn get_test_regions(&self, name: &str) -> Option<Arc<String>>
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.
Sourcepub fn get_compiled_query(
&self,
grammar_name: &str,
query_type: &str,
query_str: &str,
) -> Option<Arc<Query>>
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.
Sourcepub fn available_external(&self) -> Vec<String>
pub fn available_external(&self) -> Vec<String>
List available grammars in search paths.
Sourcepub fn available_external_with_paths(&self) -> Vec<(String, PathBuf)>
pub fn available_external_with_paths(&self) -> Vec<(String, PathBuf)>
List available grammars in search paths, with their file paths.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for GrammarLoader
impl RefUnwindSafe for GrammarLoader
impl Send for GrammarLoader
impl Sync for GrammarLoader
impl Unpin for GrammarLoader
impl UnsafeUnpin for GrammarLoader
impl UnwindSafe for GrammarLoader
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request