7 unstable releases (3 breaking)

new 0.20.1 Nov 21, 2021
0.20.0 Sep 3, 2021
0.19.2 Mar 8, 2021
0.3.0 Sep 24, 2020
0.2.0 May 12, 2020

#23 in Parser tooling

Download history 288/week @ 2021-08-08 406/week @ 2021-08-15 481/week @ 2021-08-22 321/week @ 2021-08-29 342/week @ 2021-09-05 409/week @ 2021-09-12 317/week @ 2021-09-19 138/week @ 2021-09-26 622/week @ 2021-10-03 444/week @ 2021-10-10 239/week @ 2021-10-17 390/week @ 2021-10-24 355/week @ 2021-10-31 635/week @ 2021-11-07 536/week @ 2021-11-14 176/week @ 2021-11-21

1,719 downloads per month
Used in 3 crates (2 directly)

MIT license

480KB
12K SLoC

C 8K SLoC // 0.0% comments Rust 3.5K SLoC // 0.0% comments

tree-sitter-tags

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

~1.4–2.4MB
~64K SLoC