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.
✨ What's New in v0.4.2: Enhanced User Experience
Transform from complex setup to delightful developer experience:
- 🎯 Real-time feedback: See analyzer registration and validation immediately
- 📊 Comprehensive summaries: Detailed scan results with performance metrics
- 🔧 Actionable errors: Clear guidance when something goes wrong
- 🌟 Professional polish: Emoji indicators and user-friendly messages
- 📁 Complete file path tracking: Every code element includes its originating file
Before vs After
// Before: Silent, unclear feedback
let loregrep = builder.build?;
// After: Rich, helpful feedback
let mut loregrep = builder
.with_rust_analyzer // ✅ Rust analyzer registered successfully
.with_python_analyzer // ✅ Python analyzer registered successfully
.build?; // 🎆 LoreGrep configured with 2 languages
// Enhanced scan with comprehensive feedback
let result = loregrep.scan.await?;
// 🔍 Starting scan... 📁 Found X files... 📊 Summary with metrics
Quick Start
Installation
Add to your Cargo.toml
:
[]
= "0.4.2"
= { = "1.35", = ["full"] }
= "1.0"
Basic Usage
use LoreGrep;
use json;
async
API Reference
Advanced Configuration with Builder Pattern
For cases where you need fine-grained control beyond auto-discovery:
use LoreGrep;
// Enhanced builder with detailed configuration
let mut loregrep = builder
.with_rust_analyzer // ✅ Rust analyzer registered successfully
.with_python_analyzer // ✅ Python analyzer registered successfully
.max_file_size // 5MB max file size
.max_depth // Directory traversal depth
.file_patterns
.exclude_patterns
.respect_gitignore // Honor .gitignore files
.build?; // 🎆 LoreGrep configured with 2 languages
// Builder now validates configuration and provides feedback:
// ✅ LoreGrep instance created successfully!
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 with File Path Tracking
Loregrep provides 6 standardized tools for code analysis. Every result includes complete file path information for better cross-file reference tracking:
use json;
// 1. Search functions by pattern - now with file paths!
let functions = loregrep.execute_tool.await?;
// Example response shows file paths for each function:
// {
// "functions": [
// {
// "name": "parse_config",
// "file_path": "src/config.rs", ← Always included
// "start_line": 45,
// "signature": "pub fn parse_config(path: &str) -> Result<Config>"
// },
// {
// "name": "load_config",
// "file_path": "src/utils/loader.rs", ← Different file
// "start_line": 12,
// "signature": "fn load_config() -> Config"
// }
// ]
// }
// 2. Search structs/enums by pattern
let structs = loregrep.execute_tool.await?;
// 3. Analyze specific file - shows all elements with their file paths
let analysis = loregrep.execute_tool.await?;
// 4. Get file dependencies - imports/exports include file paths
let deps = loregrep.execute_tool.await?;
// 5. Find function callers - shows where functions are called from
let callers = loregrep.execute_tool.await?;
// Example response with cross-file calls:
// {
// "callers": [
// {
// "function_name": "parse_config",
// "file_path": "src/main.rs", ← Called from main.rs
// "line_number": 23,
// "caller_function": "main"
// },
// {
// "function_name": "parse_config",
// "file_path": "src/utils/loader.rs", ← Also called from loader.rs
// "line_number": 45,
// "caller_function": "load_default_config"
// }
// ]
// }
// 6. Get repository tree with file path details
let tree = loregrep.execute_tool.await?;
Enhanced Error Handling with Actionable Guidance
use ;
// Enhanced error messages provide specific guidance
match loregrep.scan.await
// Enhanced error handling for unsupported languages:
// ⚠️ No analyzer available for 'javascript' files. Supported: rust, python
// 💡 Add support with: LoreGrep::builder().with_javascript_analyzer() (coming soon)
// Builder validation warnings:
let loregrep = builder
.build?;
// ⚠️ Warning: No language analyzers registered!
// 💡 Consider adding: .with_rust_analyzer() or .with_python_analyzer()
// 📁 Files will be discovered but not analyzed
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
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 - Leveraging File Path Information
use LoreGrep;
use json;
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 | ✅ | ✅ | ✅ | ✅ | Full |
TypeScript | 🚧 | 🚧 | 🚧 | 🚧 | Planned |
JavaScript | 🚧 | 🚧 | 🚧 | 🚧 | Planned |
Advanced Usage
Custom Tool Development with File Path Awareness
use ;
use ;
use HashMap;
// Custom analysis that leverages file path information
// Usage examples:
let module_analysis = loregrep.analyze_by_module.await?;
let dependency_check = loregrep.check_circular_dependencies.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
- Advanced usage demonstrationcoding_assistant.rs
- Full coding assistant implementation
License
Licensed under either of MIT or Apache-2.0 at your option.