Crate tree_sitter_symbols

Crate tree_sitter_symbols 

Source
Expand description

Convenience wrapper for tree-sitter symbol node type enums across multiple languages.

tss provides a unified interface for working with tree-sitter node types from multiple language grammars. Rather than importing language-specific crates directly, you can enable languages through features and access them through this single crate.

§Quick Start

[dependencies]
tss = { version = "0.2", features = ["lang-rust-full"] }
tree-sitter = "0.24"
tree-sitter-rust = "0.24"
use tree_sitter_symbols::NodeTypeRust;
use std::str::FromStr;

let node_type = NodeTypeRust::from_str("function_item")?;
assert_eq!(node_type, NodeTypeRust::FunctionItem);
assert_eq!(node_type.to_string(), "function_item");

§Language-Specific Type Names

Each language’s NodeType is re-exported with the language name in PascalCase:

  • Rust: tree_sitter_symbols_rust::NodeTypeNodeTypeRust
  • Python (future): tree_sitter_symbols_python::NodeTypeNodeTypePython

This naming convention prevents confusion when working with multiple language grammars simultaneously. You always know which language a node type belongs to.

§Features

By default, this crate has no features enabled and provides no functionality. You must explicitly enable the languages you need.

§Language Selection

Enable languages individually or all at once:

# Single language with metadata only (no node types)
tss = { version = "0.2", features = ["lang-rust"] }

# All languages with metadata only (currently just Rust)
tss = { version = "0.2", features = ["lang-all"] }

# All languages with full node types (currently just Rust)  
tss = { version = "0.2", features = ["lang-all-full"] }

§Language Variants: Metadata-Only vs. Full

Each language has two feature variants:

§lang-{name} - Metadata Only

Enables the language crate with meta_full but no node types. The NodeType enum exists but has no variants, making it essentially unusable for pattern matching. This is useful if you only need the metadata features or plan to enable specific node types manually.

# Rust with metadata only - NodeType enum exists but is empty
tss = { version = "0.2", features = ["lang-rust"] }

§lang-{name}-full - Complete Functionality

Enables the language crate with the full feature, which includes both meta_full and node_full. This gives you all node types and all metadata - complete functionality.

# Rust with all node types + all metadata
tss = { version = "0.2", features = ["lang-rust-full"] }

§Aggregate Features

  • lang-all: Enables all languages with metadata only (no node types)
  • lang-all-full: Enables all languages with full functionality (all nodes + metadata)
# All languages, metadata only
tss = { version = "0.2", features = ["lang-all"] }

# All languages, complete functionality
tss = { version = "0.2", features = ["lang-all-full"] }

§Combining with Language Crate Features

For fine-grained control, enable tss with a metadata-only language, then add the underlying language crate with specific node type features:

[dependencies]
tss = { version = "0.2", features = ["lang-rust"] }
tss-rust = { version = "0.2", features = [
    "function_item",
    "struct_item",
    "impl_item"
]}

This gives you NodeTypeRust through tss with only the specific node types you need, plus all metadata from the lang-rust feature.

§When to Use This Crate

Use tss when:

  • You’re working with multiple tree-sitter languages
  • You want a unified import for all language support
  • You prefer explicit type names like NodeTypeRust vs. NodeType
  • You want lang-all or lang-all-full to easily enable all supported languages

Use language crates directly (e.g., tss-rust) when:

  • You’re only working with a single language
  • You want minimal dependencies
  • You prefer the simpler NodeType name
  • You need fine-grained control over individual node type features

§How It Works

This crate is a thin wrapper that re-exports the underlying language crates based on enabled features. It adds zero runtime overhead - the re-exports are resolved at compile time and generate identical code to using the language crates directly.

Each language crate (tss-rust, etc.) generates node type enums at build time from the corresponding tree-sitter-* crate’s NODE_TYPES constant. See the individual language crate documentation for details on code generation and available metadata features.

§Available Languages

Currently supported:

  • Rust (lang-rust, lang-rust-full)

Coming soon:

  • Python (lang-python, lang-python-full)

Additional languages will be added based on community demand.