27 releases

new 0.25.2 Feb 18, 2025
0.24.7 Jan 12, 2025
0.24.6 Dec 27, 2024
0.24.4 Nov 10, 2024
0.2.0 May 12, 2020

#1970 in Parser implementations

Download history 4551/week @ 2024-10-30 5034/week @ 2024-11-06 4314/week @ 2024-11-13 4087/week @ 2024-11-20 4104/week @ 2024-11-27 5358/week @ 2024-12-04 5000/week @ 2024-12-11 2683/week @ 2024-12-18 2381/week @ 2024-12-25 5633/week @ 2025-01-01 7655/week @ 2025-01-08 6262/week @ 2025-01-15 6151/week @ 2025-01-22 4756/week @ 2025-01-29 6966/week @ 2025-02-05 6012/week @ 2025-02-12

24,615 downloads per month
Used in 14 crates (2 directly)

MIT license

710KB
17K SLoC

C 12K SLoC // 0.1% comments Rust 5K SLoC // 0.0% comments

Tree-sitter Tags

crates.io badge

Usage

Add this crate, and the language-specific crates for whichever languages you want to parse, to your Cargo.toml:

[dependencies]
tree-sitter-tags = "0.19"
tree-sitter-javascript = "0.19"
tree-sitter-python = "0.19"

Create a tag context. You need one of these for each thread that you're using for tag computation:

use tree_sitter_tags::TagsContext;

let context = TagsContext::new();

Load some tagging queries from the queries directory of some language repositories:

use tree_sitter_tags::TagsConfiguration;

let python_config = TagsConfiguration::new(
    tree_sitter_python::language(),
    tree_sitter_python::TAGGING_QUERY,
    "",
).unwrap();

let javascript_config = TagsConfiguration::new(
    tree_sitter_javascript::language(),
    tree_sitter_javascript::TAGGING_QUERY,
    tree_sitter_javascript::LOCALS_QUERY,
).unwrap();

Compute code navigation tags for some source code:

let tags = context.generate_tags(
    &javascript_config,
    b"class A { getB() { return c(); } }",
    None,
);

for tag in tags {
    println!("kind: {:?}", tag.kind);
    println!("range: {:?}", tag.range);
    println!("name_range: {:?}", tag.name_range);
    println!("docs: {:?}", tag.docs);
}

Dependencies

~2.6–4.5MB
~88K SLoC