15 unstable releases (5 breaking)

0.22.6 May 5, 2024
0.22.2 Mar 17, 2024
0.20.2 Mar 2, 2022
0.20.1 Nov 21, 2021
0.2.0 May 12, 2020

#1111 in Parser implementations

Download history 4172/week @ 2024-01-24 4312/week @ 2024-01-31 3958/week @ 2024-02-07 3839/week @ 2024-02-14 5477/week @ 2024-02-21 4682/week @ 2024-02-28 5083/week @ 2024-03-06 5043/week @ 2024-03-13 4652/week @ 2024-03-20 4470/week @ 2024-03-27 5114/week @ 2024-04-03 5812/week @ 2024-04-10 5357/week @ 2024-04-17 4202/week @ 2024-04-24 6183/week @ 2024-05-01 5225/week @ 2024-05-08

21,919 downloads per month
Used in 14 crates (2 directly)

MIT license

640KB
16K SLoC

C 11K SLoC // 0.0% comments Rust 4.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
~79K SLoC