22 unstable releases (7 breaking)

new 0.24.5 Dec 11, 2024
0.24.4 Nov 10, 2024
0.24.3 Oct 9, 2024
0.22.6 May 5, 2024
0.2.0 May 12, 2020

#2132 in Parser implementations

Download history 6890/week @ 2024-08-21 4140/week @ 2024-08-28 4672/week @ 2024-09-04 4367/week @ 2024-09-11 5100/week @ 2024-09-18 4885/week @ 2024-09-25 5452/week @ 2024-10-02 4655/week @ 2024-10-09 4699/week @ 2024-10-16 4411/week @ 2024-10-23 4551/week @ 2024-10-30 5034/week @ 2024-11-06 4314/week @ 2024-11-13 4087/week @ 2024-11-20 4111/week @ 2024-11-27 4746/week @ 2024-12-04

18,067 downloads per month
Used in 13 crates (2 directly)

MIT license

660KB
16K SLoC

C 12K 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.5–4.5MB
~84K SLoC