Skip to main content

Crate thread

Crate thread 

Source
Expand description

§Thread - Safe, Fast, Flexible Code Analysis and Parsing

Thread is a high-performance ecosystem for code analysis and transformation built in Rust. It combines the power of tree-sitter for robust parsing with a high-level rule engine and content-addressed caching for efficient codebase-wide analysis.

This crate serves as the primary entry point for the Thread ecosystem, re-exporting core components from specialized sub-crates.

§Core Architecture

Thread is built on a modular “service-library dual architecture”:

  1. Library Ecosystem - Reusable components for AST pattern matching and transformation.
  2. Service Platform - Persistent analysis with incremental intelligence and caching.

§Key Modules

  • ast - Core AST parsing, matching, and transformation engine.
  • language - Support for various programming languages via tree-sitter.
  • rule - Rule-based scanning and transformation system.
  • services - High-level service interfaces and abstractions.
  • flow - Dataflow orchestration and incremental analysis (optional).
  • utils - Common utilities and performance optimizations.

§Quick Start

use thread::language::{Tsx, LanguageExt};

// Parse code and find patterns
let ast = Tsx.ast_grep("function hello() { console.log('world'); }");
let root = ast.root();
let matches = root.find_all("console.log($$$ARGS)");

for m in matches {
    println!("Found console.log with {} arguments", m.get_env().get_multiple_matches("ARGS").len());
}

Modules§

ast
Core AST engine for parsing, matching, and transformation.
flow
Dataflow orchestration layer for incremental computation and caching.
language
Language definitions and tree-sitter parser integrations.
rule
Rule-based scanning and transformation system.
services
High-level service interfaces and application abstractions.
utils
Shared utilities and performance-critical primitives.

Structs§

Node
A single node in an Abstract Syntax Tree.
ParsedDocument
A parsed document that wraps ast-grep Root with additional codebase-level metadata.
Root
Root of an AST tree that owns the source code and parsed tree structure.

Enums§

ServiceError
Main error type for service layer operations with optimized string handling
SupportLang
Runtime language selection enum supporting all built-in languages.

Traits§

CodeAnalyzer
Core analyzer service trait that abstracts ast-grep analysis functionality.
CodeParser
Core parser service trait that abstracts ast-grep parsing functionality.
Language
Trait to abstract ts-language usage in ast-grep, which includes:

Type Aliases§

AstGrep
ServiceResult
Service result type using Tower’s BoxError pattern for unified error handling