Expand description
§tree-sitter-language-pack
Pre-compiled tree-sitter grammars for 305 programming languages with a unified API for parsing, analysis, and intelligent code chunking.
§Quick Start
use tree_sitter_language_pack::{ProcessConfig, available_languages, has_language, process};
// Check available languages
let langs = available_languages();
assert!(has_language("python"));
// Process source code
let config = ProcessConfig::new("python").all();
let result = process("def hello(): pass", &config).unwrap();
println!("Language: {}", result.language);
println!("Functions: {}", result.structure.len());§Parser API
use tree_sitter_language_pack::get_parser;
let mut parser = get_parser("python")?;
let tree = parser.parse("def foo(): pass").expect("parse failed");
assert_eq!(tree.root_node().kind(), "module");§Modules
registry- Thread-safe language registry for parser lookup- [
intel] - Source code intelligence extraction (structure, imports, exports, etc.) - [
parse] - Low-level tree-sitter parsing utilities - [
text_splitter] - Syntax-aware code chunking process_config- Configuration for theprocesspipelinepack_config- Configuration for the language pack (cache dir, languages to download)error- Error types
Re-exports§
pub use error::Error;pub use pack_config::PackConfig;pub use parsing::ByteRange;pub use parsing::Node;pub use parsing::Parser;pub use parsing::Point;pub use parsing::Tree;pub use parsing::TreeCursor;pub use process_config::ProcessConfig;pub use registry::LanguageRegistry;pub use download::DownloadManager;
Modules§
- download
- error
- pack_
config - parsing
- Universal parser/tree/node surface over
tree_sitter. - process_
config - registry
Structs§
- Chunk
Context - Metadata for a single chunk of source code.
- Code
Chunk - A chunk of source code with rich metadata.
- Comment
Info - A comment extracted from source code.
- Diagnostic
- A diagnostic (syntax error, missing node, etc.) from parsing.
- DocSection
- A section within a docstring (e.g., Args, Returns, Raises).
- Docstring
Info - A docstring extracted from source code.
- Export
Info - An export statement extracted from source code.
- File
Metrics - Aggregate metrics for a source file.
- Import
Info - An import statement extracted from source code.
- Language
- An opaque object that defines how to parse a particular language. The code
for each
Languageis generated by the Tree-sitter CLI. - Process
Result - Complete analysis result from processing a source file.
- Span
- Byte and line/column range in source code.
- Structure
Item - A structural item (function, class, struct, etc.) in source code.
- Symbol
Info - A symbol (variable, function, type, etc.) extracted from source code.
Enums§
- Comment
Kind - The kind of a comment found in source code.
- Diagnostic
Severity - Severity level of a diagnostic produced during parsing.
- Docstring
Format - The format of a docstring extracted from source code.
- Export
Kind - The kind of an export statement found in source code.
- Structure
Kind - The kind of structural item found in source code.
- Symbol
Kind - The kind of a symbol definition found in source code.
Functions§
- available_
languages - List all available language names (sorted, deduplicated, includes aliases).
- cache_
dir - Return the effective cache directory path.
- clean_
cache - Delete all cached parser shared libraries.
- configure
- Apply download configuration without downloading anything.
- detect_
language - Detect language name from a file path or extension.
- detect_
language_ from_ content - Detect language name from file content using the shebang line (
#!). - detect_
language_ from_ extension - Detect language name from a file extension (without leading dot).
- detect_
language_ from_ path - Detect language name from a file path.
- download
- Download specific languages to the local cache.
- download_
all - Download all available languages from the remote manifest.
- downloaded_
languages - Return languages that are already downloaded and cached locally.
- get_
highlights_ query - Get the highlights query for a language, if bundled.
- get_
injections_ query - Get the injections query for a language, if bundled.
- get_
language - Get a tree-sitter
Languageby name using the global registry. - get_
locals_ query - Get the locals query for a language, if bundled.
- get_
parser - Get a
Parserpre-configured for the given language. - has_
language - Check if a language is available by name or alias.
- init
- Initialize the language pack with the given configuration.
- language_
count - Return the number of available languages.
- manifest_
languages - Return all language names available in the remote manifest (305).
- process
- Process source code and extract file intelligence using the global registry.