code-analyze-core 0.2.5

Multi-language AST analysis library using tree-sitter
Documentation

code-analyze-core

Core library for code structure analysis using tree-sitter.

Features

  • Directory analysis - File tree with LOC, function, and class counts
  • File analysis - Functions, classes, and imports with signatures and line ranges
  • Symbol call graphs - Callers and callees across a directory with configurable depth
  • Module index - Lightweight function and import index (~75% smaller than full file analysis)
  • Multi-language - Rust, Python, TypeScript, TSX, Go, Java, Fortran, JavaScript, C/C++, C#
  • Pagination - Cursor-based pagination for large outputs
  • Caching - LRU cache for parsed results with mtime-based invalidation
  • Parallel - Rayon-based parallel file analysis

Installation

Add to your Cargo.toml:

[dependencies]
code-analyze-core = "0.2"

Example

use code_analyze_core::{analyze_directory, analyze_file, AnalysisConfig};
use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    // Analyze a directory (depth 2, compact summary)
    let output = analyze_directory("src/", Some(2), true, None, None, false, false).await?;
    println!("{}", output.formatted);

    // Analyze a single file
    let output = analyze_file("src/lib.rs", false, None, None, false, false, None, None).await?;
    println!("{}", output.formatted);

    Ok(())
}

Supported Languages

Language Extensions Feature flag
Rust .rs lang-rust
Python .py lang-python
TypeScript .ts lang-typescript
TSX .tsx lang-tsx
Go .go lang-go
Java .java lang-java
Fortran .f, .f77, .f90, .f95, .f03, .f08, .for, .ftn lang-fortran
JavaScript .js, .mjs, .cjs lang-javascript
C/C++ .c, .cc, .cpp, .cxx, .h, .hpp, .hxx lang-cpp
C# .cs lang-csharp

Configuration

AnalysisConfig provides resource limits for library consumers:

use code_analyze_core::AnalysisConfig;

let config = AnalysisConfig {
    max_file_bytes: Some(1_000_000), // skip files > 1 MB
    parse_timeout_micros: None,      // reserved, no-op in 0.2
    cache_capacity: None,            // use default LRU capacity
};

Support

For questions and support, visit clouatre.ca.

License

Apache-2.0. See LICENSE.