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

#860 in Parser implementations

Download history 5131/week @ 2024-02-26 4822/week @ 2024-03-04 5314/week @ 2024-03-11 4689/week @ 2024-03-18 4703/week @ 2024-03-25 4509/week @ 2024-04-01 5812/week @ 2024-04-08 5921/week @ 2024-04-15 4100/week @ 2024-04-22 5424/week @ 2024-04-29 6543/week @ 2024-05-06 5720/week @ 2024-05-13 5146/week @ 2024-05-20 5935/week @ 2024-05-27 5743/week @ 2024-06-03 5956/week @ 2024-06-10

23,176 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
~80K SLoC