tree_sitter_symbols/lib.rs
1//! Convenience wrapper for tree-sitter symbol node type enums across multiple languages.
2//!
3//! `tss` provides a unified interface for working with tree-sitter node types from multiple
4//! language grammars. Rather than importing language-specific crates directly, you can enable
5//! languages through features and access them through this single crate.
6//!
7//! # Quick Start
8//!
9//! ```toml
10//! [dependencies]
11//! tss = { version = "0.2", features = ["lang-rust-full"] }
12//! tree-sitter = "0.24"
13//! tree-sitter-rust = "0.24"
14//! ```
15//!
16//! ```
17//! # #[cfg(feature = "lang-rust-full")]
18//! # {
19//! use tree_sitter_symbols::NodeTypeRust;
20//! use std::str::FromStr;
21//!
22//! let node_type = NodeTypeRust::from_str("function_item")?;
23//! assert_eq!(node_type, NodeTypeRust::FunctionItem);
24//! assert_eq!(node_type.to_string(), "function_item");
25//! # }
26//! # Ok::<(), String>(())
27//! ```
28//!
29//! # Language-Specific Type Names
30//!
31//! Each language's `NodeType` is re-exported with the language name in `PascalCase`:
32//!
33//! - **Rust**: `tree_sitter_symbols_rust::NodeType` → `NodeTypeRust`
34//! - **Python** (future): `tree_sitter_symbols_python::NodeType` → `NodeTypePython`
35//!
36//! This naming convention prevents confusion when working with multiple language grammars
37//! simultaneously. You always know which language a node type belongs to.
38//!
39//! # Features
40//!
41//! **By default, this crate has no features enabled and provides no functionality.** You must
42//! explicitly enable the languages you need.
43//!
44//! ## Language Selection
45//!
46//! Enable languages individually or all at once:
47//!
48//! ```toml
49//! # Single language with metadata only (no node types)
50//! tss = { version = "0.2", features = ["lang-rust"] }
51//!
52//! # All languages with metadata only (currently just Rust)
53//! tss = { version = "0.2", features = ["lang-all"] }
54//!
55//! # All languages with full node types (currently just Rust)
56//! tss = { version = "0.2", features = ["lang-all-full"] }
57//! ```
58//!
59//! ## Language Variants: Metadata-Only vs. Full
60//!
61//! Each language has two feature variants:
62//!
63//! ### `lang-{name}` - Metadata Only
64//!
65//! Enables the language crate with `meta_full` but **no node types**. The `NodeType` enum
66//! exists but has no variants, making it essentially unusable for pattern matching. This is
67//! useful if you only need the metadata features or plan to enable specific node types manually.
68//!
69//! ```toml
70//! # Rust with metadata only - NodeType enum exists but is empty
71//! tss = { version = "0.2", features = ["lang-rust"] }
72//! ```
73//!
74//! ### `lang-{name}-full` - Complete Functionality
75//!
76//! Enables the language crate with the `full` feature, which includes both `meta_full` and
77//! `node_full`. This gives you all node types and all metadata - complete functionality.
78//!
79//! ```toml
80//! # Rust with all node types + all metadata
81//! tss = { version = "0.2", features = ["lang-rust-full"] }
82//! ```
83//!
84//! ### Aggregate Features
85//!
86//! - **`lang-all`**: Enables all languages with metadata only (no node types)
87//! - **`lang-all-full`**: Enables all languages with full functionality (all nodes + metadata)
88//!
89//! ```toml
90//! # All languages, metadata only
91//! tss = { version = "0.2", features = ["lang-all"] }
92//!
93//! # All languages, complete functionality
94//! tss = { version = "0.2", features = ["lang-all-full"] }
95//! ```
96//!
97//! ## Combining with Language Crate Features
98//!
99//! For fine-grained control, enable `tss` with a metadata-only language, then add the underlying
100//! language crate with specific node type features:
101//!
102//! ```toml
103//! [dependencies]
104//! tss = { version = "0.2", features = ["lang-rust"] }
105//! tss-rust = { version = "0.2", features = [
106//! "function_item",
107//! "struct_item",
108//! "impl_item"
109//! ]}
110//! ```
111//!
112//! This gives you `NodeTypeRust` through `tss` with only the specific node types you need,
113//! plus all metadata from the `lang-rust` feature.
114//!
115//! # When to Use This Crate
116//!
117//! **Use `tss`** when:
118//! - You're working with multiple tree-sitter languages
119//! - You want a unified import for all language support
120//! - You prefer explicit type names like `NodeTypeRust` vs. `NodeType`
121//! - You want `lang-all` or `lang-all-full` to easily enable all supported languages
122//!
123//! **Use language crates directly** (e.g., `tss-rust`) when:
124//! - You're only working with a single language
125//! - You want minimal dependencies
126//! - You prefer the simpler `NodeType` name
127//! - You need fine-grained control over individual node type features
128//!
129//! # How It Works
130//!
131//! This crate is a thin wrapper that re-exports the underlying language crates based on
132//! enabled features. It adds zero runtime overhead - the re-exports are resolved at compile
133//! time and generate identical code to using the language crates directly.
134//!
135//! Each language crate (`tss-rust`, etc.) generates node type enums at build time from the
136//! corresponding `tree-sitter-*` crate's `NODE_TYPES` constant. See the individual language
137//! crate documentation for details on code generation and available metadata features.
138//!
139//! # Available Languages
140//!
141//! Currently supported:
142//! - **Rust** (`lang-rust`, `lang-rust-full`)
143//!
144//! Coming soon:
145//! - **Python** (`lang-python`, `lang-python-full`)
146//!
147//! Additional languages will be added based on community demand.
148
149#![allow(clippy::negative_feature_names)]
150#![allow(clippy::redundant_feature_names)]
151
152#[cfg(feature = "lang-rust")]
153/// Re-export of the complete `tree_sitter_symbols_rust` module.
154///
155/// Provides access to all types and functions from the Rust language crate.
156/// Use this when you need the full module API, or prefer to access `NodeType`
157/// through the module path.
158///
159/// # Examples
160///
161/// ```
162/// # #[cfg(feature = "lang-rust")]
163/// # {
164/// use tree_sitter_symbols::tree_sitter_symbols_rust;
165///
166/// // Access through the module
167/// let node_type = tree_sitter_symbols_rust::NodeType::FunctionItem;
168/// # }
169/// ```
170pub use tree_sitter_symbols_rust;
171
172#[cfg(feature = "lang-rust")]
173/// Rust language node type enum.
174///
175/// This is a re-export of `tree_sitter_symbols_rust::NodeType` with a language-specific
176/// name to avoid confusion when working with multiple languages.
177///
178/// # Examples
179///
180/// ```
181/// # #[cfg(all(feature = "lang-rust-full"))]
182/// # {
183/// use tree_sitter_symbols::NodeTypeRust;
184/// use std::str::FromStr;
185///
186/// let node_type = NodeTypeRust::from_str("function_item")?;
187/// assert_eq!(node_type, NodeTypeRust::FunctionItem);
188/// # }
189/// # Ok::<(), String>(())
190/// ```
191///
192/// See the [`tree_sitter_symbols_rust`] module documentation for details on available
193/// features and metadata.
194pub use tree_sitter_symbols_rust::NodeType as NodeTypeRust;
195
196#[cfg(feature = "lang-rust-full")]
197#[cfg(test)]
198mod tests {
199 #[cfg(feature = "lang-rust")]
200 use super::*;
201
202 #[cfg(feature = "lang-rust")]
203 mod rust_tests {
204 use super::tree_sitter_symbols_rust::*;
205 use std::str::FromStr;
206
207 #[test]
208 fn test_from_str() {
209 assert_eq!(
210 NodeType::from_str("function_item").unwrap(),
211 NodeType::FunctionItem
212 );
213 }
214
215 #[test]
216 fn test_display() {
217 assert_eq!(NodeType::FunctionItem.to_string(), "function_item");
218 }
219 }
220}