11 unstable releases (5 breaking)

new 0.22.2 Mar 17, 2024
0.21.0 Feb 21, 2024
0.20.2 Mar 2, 2022
0.20.1 Nov 21, 2021
0.2.0 May 12, 2020

#1389 in Parser implementations

Download history 3552/week @ 2023-12-01 3780/week @ 2023-12-08 5301/week @ 2023-12-15 2436/week @ 2023-12-22 3377/week @ 2023-12-29 4187/week @ 2024-01-05 3876/week @ 2024-01-12 4259/week @ 2024-01-19 4171/week @ 2024-01-26 4135/week @ 2024-02-02 3928/week @ 2024-02-09 4405/week @ 2024-02-16 5268/week @ 2024-02-23 4838/week @ 2024-03-01 5199/week @ 2024-03-08 3890/week @ 2024-03-15

20,259 downloads per month
Used in 13 crates (2 directly)

MIT license

630KB
15K 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