pub struct CodeParser { /* private fields */ }Expand description
A robust code parser system that analyzes source code and produces clean, accurate Abstract Syntax Trees (ASTs) optimized for LLM consumption.
§Key capabilities:
- Consistent parsing approach using tree-sitter for reliable, accurate parsing
- Clean, well-documented API for LLM tool use
- Efficient error recovery for handling malformed code
- Structured AST output that LLMs can easily interpret
- Language detection with robust extension mapping
- Declarative query patterns for extracting meaningful code structures
- Efficient caching system for parsers and queries
Implementations§
Source§impl CodeParser
impl CodeParser
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a new CodeParser instance with initialized language support and default configuration.
§Returns
Result<Self>- A new CodeParser instance or an error
Sourcepub fn with_config(
cache_size_limit: Option<usize>,
max_file_size: Option<usize>,
max_files: Option<usize>,
max_depth: Option<usize>,
) -> Result<Self>
pub fn with_config( cache_size_limit: Option<usize>, max_file_size: Option<usize>, max_files: Option<usize>, max_depth: Option<usize>, ) -> Result<Self>
Creates a new CodeParser instance with custom configuration.
§Arguments
cache_size_limit- Optional cache size limit in bytes (default: 50MB)max_file_size- Optional maximum file size to parse in bytes (default: 1MB)max_files- Optional maximum number of files to parse (default: 25)max_depth- Optional maximum recursion depth (default: 3)
§Returns
Result<Self>- A new CodeParser instance or an error
Sourcepub fn detect_language(&self, path: &Path) -> Option<String>
pub fn detect_language(&self, path: &Path) -> Option<String>
Sourcepub fn parse_file(&mut self, path: &Path) -> Result<CodeAST>
pub fn parse_file(&mut self, path: &Path) -> Result<CodeAST>
Sourcepub fn create_simplified_ast(
&self,
path: &Path,
language: &str,
source_code: &str,
) -> Result<CodeAST>
pub fn create_simplified_ast( &self, path: &Path, language: &str, source_code: &str, ) -> Result<CodeAST>
Sourcepub fn extract_search_terms(&self, query: &str) -> Vec<String>
pub fn extract_search_terms(&self, query: &str) -> Vec<String>
Auto Trait Implementations§
impl Freeze for CodeParser
impl RefUnwindSafe for CodeParser
impl Send for CodeParser
impl Sync for CodeParser
impl Unpin for CodeParser
impl UnwindSafe for CodeParser
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
Mutably borrows from an owned value. Read more
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>
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 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>
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