8 releases

0.20.2 Mar 2, 2022
0.20.1 Nov 21, 2021
0.20.0 Sep 3, 2021
0.19.2 Mar 8, 2021
0.2.0 May 12, 2020

#20 in Text editors

Download history 1990/week @ 2023-02-08 1985/week @ 2023-02-15 2426/week @ 2023-02-22 2407/week @ 2023-03-01 3319/week @ 2023-03-08 3004/week @ 2023-03-15 2634/week @ 2023-03-22 2662/week @ 2023-03-29 3323/week @ 2023-04-05 3618/week @ 2023-04-12 3085/week @ 2023-04-19 2630/week @ 2023-04-26 3125/week @ 2023-05-03 2359/week @ 2023-05-10 3102/week @ 2023-05-17 2924/week @ 2023-05-24

12,006 downloads per month
Used in 11 crates (2 directly)

MIT license

510KB
13K SLoC

C 9K SLoC // 0.1% 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.6–2.6MB
~67K SLoC