Loregrep Rust Crate
High-performance repository indexing library for coding assistants
A fast, memory-efficient Rust library that parses codebases using tree-sitter and provides structured access to functions, structs, dependencies, and call graphs. Built for AI coding assistants and code analysis tools.
Quick Start
Installation
Add to your Cargo.toml
:
[]
= "0.3.3"
= { = "1.35", = ["full"] }
= "1.0"
Basic Usage
use LoreGrep;
use json;
async
API Reference
Builder Pattern
let loregrep = builder
.max_file_size // 5MB max file size
.max_depth // Directory traversal depth
.file_patterns
.exclude_patterns
.respect_gitignore // Honor .gitignore files
.build?;
Scanning Results
use ScanResult;
let result: ScanResult = loregrep.scan.await?;
// Access detailed scan statistics
println!;
println!;
println!;
println!;
// Handle any scan errors
for error in &result.errors
Tool Execution
Loregrep provides 6 standardized tools for code analysis:
use json;
// 1. Search functions by pattern
let functions = loregrep.execute_tool.await?;
// 2. Search structs/enums by pattern
let structs = loregrep.execute_tool.await?;
// 3. Analyze specific file
let analysis = loregrep.execute_tool.await?;
// 4. Get file dependencies
let deps = loregrep.execute_tool.await?;
// 5. Find function callers
let callers = loregrep.execute_tool.await?;
// 6. Get repository tree
let tree = loregrep.execute_tool.await?;
Error Handling
use ;
match loregrep.scan.await
CLI Usage
Loregrep includes a powerful CLI for interactive and scripted usage:
Installation
Basic Commands
# Scan current directory
# Search for functions
# Analyze specific file
# Get repository tree
# Interactive mode
CLI Configuration
Create a loregrep.toml
file in your project root:
[]
= 5242880 # 5MB
= 15
= true
[]
= ["*.rs", "*.toml", "*.md"]
= ["target/", ".git/", "*.tmp"]
[]
= "json" # or "table", "tree"
= 50
Performance Characteristics
Benchmarks
On a typical Rust project (100 files, 50k LOC):
- Scanning: ~200ms
- Indexing: ~50ms
- Function search: ~2ms
- Memory usage: ~10MB
Optimization Tips
// For large repositories
let loregrep = builder
.max_file_size // Limit file size
.exclude_patterns
.build?;
// For memory-constrained environments
let loregrep = builder
.max_depth // Limit recursion depth
.file_patterns
.build?;
Async and Concurrency
Loregrep is fully async and thread-safe:
use Arc;
use task;
// Share across tasks
let loregrep = new;
// Concurrent operations
let handles: = .map.collect;
// Wait for all tasks
for handle in handles
Integration Patterns
With AI Libraries
use LoreGrep;
With Web Servers
use ;
use LoreGrep;
use Arc;
async
async
Build Scripts Integration
// build.rs
use LoreGrep;
Language Support
Language | Functions | Structs/Enums | Imports | Calls | Status |
---|---|---|---|---|---|
Rust | ✅ | ✅ | ✅ | ✅ | Full |
Python | 🚧 | 🚧 | 🚧 | 🚧 | Planned |
TypeScript | 🚧 | 🚧 | 🚧 | 🚧 | Planned |
JavaScript | 🚧 | 🚧 | 🚧 | 🚧 | Planned |
Advanced Usage
Custom Tool Development
use ;
use Value;
// Implement custom analysis tools
// Example: Find all public functions
let public_functions = loregrep.execute_custom_tool.await;
Extending File Support
// Add custom file extensions
let loregrep = builder
.file_patterns
.build?;
Contributing
Want to contribute to loregrep? See our main README for guidelines.
Rust-Specific Contributions
- Language analyzers: Implement parsers for new languages
- Performance optimizations: Profile and optimize hot paths
- Tool implementations: Add new analysis tools
- CLI enhancements: Improve command-line interface
Examples
See the examples/
directory for complete examples:
basic_usage.rs
- Basic scanning and searchingcli_integration.rs
- CLI tool usageperformance_demo.rs
- Performance benchmarkingcoding_assistant.rs
- Full coding assistant implementation
License
Licensed under either of MIT or Apache-2.0 at your option.