pub struct Parser { /* private fields */ }Expand description
Parser that extracts symbol facts from Rust source code
Pure function: Input (path, contents) → Output Vec<SymbolFact>
No filesystem access. No global state. No caching.
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn extract_symbols(
&mut self,
file_path: PathBuf,
source: &[u8],
) -> Vec<SymbolFact>
👎Deprecated since 1.7.0: Use extract_symbols_with_parser with parser pool for better performance
pub fn extract_symbols( &mut self, file_path: PathBuf, source: &[u8], ) -> Vec<SymbolFact>
Use extract_symbols_with_parser with parser pool for better performance
Extract symbol facts from Rust source code
§Deprecated
This method creates a new parser instance per call, which is inefficient
for batch processing. Use extract_symbols_with_parser with the thread-local
parser pool instead:
use crate::ingest::pool::with_parser;
use crate::ingest::Language;
let facts = with_parser(Language::Rust, |parser| {
RustParser::extract_symbols_with_parser(parser, file_path, source)
})?;§Arguments
file_path- Path to the file (for context only, not accessed)source- Source code content as bytes
§Returns
Vector of symbol facts found in the source
§Guarantees
- Pure function: same input → same output
- No side effects
- No filesystem access
Sourcepub fn extract_symbols_with_parser(
parser: &mut Parser,
file_path: PathBuf,
source: &[u8],
) -> Vec<SymbolFact>
pub fn extract_symbols_with_parser( parser: &mut Parser, file_path: PathBuf, source: &[u8], ) -> Vec<SymbolFact>
Extract symbol facts using an external parser (for parser pooling).
This static method allows sharing a parser instance across multiple calls, reducing allocation overhead when parsing many files.
Sourcepub fn extract_symbols_from_tree(
tree: &Tree,
file_path: PathBuf,
source: &[u8],
) -> Vec<SymbolFact>
pub fn extract_symbols_from_tree( tree: &Tree, file_path: PathBuf, source: &[u8], ) -> Vec<SymbolFact>
Extract symbol facts from a pre-parsed tree.
This static method allows extracting symbols without re-parsing, which is useful when the tree is already available from a previous parse.
§Arguments
tree- The pre-parsed tree-sitter treefile_path- Path to the file (for context only, not accessed)source- Source code content as bytes
§Returns
Vector of symbol facts found in the source
Sourcepub fn extract_impl_relations_static(
tree: &Tree,
source: &[u8],
file_path: &Path,
) -> Vec<ImplRelation>
pub fn extract_impl_relations_static( tree: &Tree, source: &[u8], file_path: &Path, ) -> Vec<ImplRelation>
Extract all impl relationships from a parsed tree.
Walks the tree for impl_item nodes and extracts:
- Trait impls:
impl Trait for Type→ImplRelation { type_name, trait_name: Some("Trait") } - Inherent impls:
impl Type→ImplRelation { type_name, trait_name: None }
This is a separate pass from symbol extraction to keep concerns clean. Inherent impls are included for use by downstream consumers (e.g., llmgrep impl block indexing).
Source§impl Parser
Extension to Parser for reference extraction (convenience wrapper)
impl Parser
Extension to Parser for reference extraction (convenience wrapper)
Sourcepub fn extract_references(
&mut self,
file_path: PathBuf,
source: &[u8],
symbols: &[SymbolFact],
) -> Vec<ReferenceFact>
pub fn extract_references( &mut self, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], ) -> Vec<ReferenceFact>
Extract reference facts using the inner parser
Sourcepub fn extract_calls(
&mut self,
file_path: PathBuf,
source: &[u8],
symbols: &[SymbolFact],
) -> Vec<CallFact>
pub fn extract_calls( &mut self, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], ) -> Vec<CallFact>
Extract function call facts (forward call graph)
§Arguments
file_path- Path to the file (for context only, not accessed)source- Source code content as bytessymbols- Symbols defined in this file (to match against)
§Returns
Vector of CallFact representing caller → callee relationships
§Guarantees
- Only function calls are extracted (not type references)
- Calls are extracted when a function identifier within a function body references another function symbol
- No semantic analysis (AST-based only)
Sourcepub fn extract_calls_with_fqn(
&mut self,
file_path: PathBuf,
source: &[u8],
symbols: &[SymbolFact],
fqn_to_symbol: &HashMap<String, &SymbolFact>,
) -> Vec<CallFact>
pub fn extract_calls_with_fqn( &mut self, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], fqn_to_symbol: &HashMap<String, &SymbolFact>, ) -> Vec<CallFact>
Extract function call facts with optional FQN-aware symbol map.
The FQN map enables accurate resolution of qualified calls such as
math::add() across files.
Sourcepub fn extract_calls_from_tree(
tree: &Tree,
file_path: PathBuf,
source: &[u8],
symbols: &[SymbolFact],
) -> Vec<CallFact>
pub fn extract_calls_from_tree( tree: &Tree, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], ) -> Vec<CallFact>
Extract function call facts from a pre-parsed tree.
Avoids redundant parsing when the tree is already available.
Sourcepub fn extract_calls_from_tree_with_fqn(
tree: &Tree,
file_path: PathBuf,
source: &[u8],
symbols: &[SymbolFact],
fqn_to_symbol: &HashMap<String, &SymbolFact>,
) -> Vec<CallFact>
pub fn extract_calls_from_tree_with_fqn( tree: &Tree, file_path: PathBuf, source: &[u8], symbols: &[SymbolFact], fqn_to_symbol: &HashMap<String, &SymbolFact>, ) -> Vec<CallFact>
Extract function call facts from a pre-parsed tree with FQN map.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Parser
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnsafeUnpin for Parser
impl UnwindSafe for Parser
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> 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