28 releases

0.25.3 Mar 5, 2025
0.24.7 Jan 12, 2025
0.24.6 Dec 27, 2024
0.24.4 Nov 10, 2024
0.2.0 May 12, 2020

#112 in Text editors

Download history 3271/week @ 2024-12-27 7458/week @ 2025-01-03 7585/week @ 2025-01-10 5878/week @ 2025-01-17 4804/week @ 2025-01-24 5638/week @ 2025-01-31 7623/week @ 2025-02-07 5699/week @ 2025-02-14 3994/week @ 2025-02-21 5646/week @ 2025-02-28 7822/week @ 2025-03-07 7226/week @ 2025-03-14 5901/week @ 2025-03-21 7439/week @ 2025-03-28 7447/week @ 2025-04-04 8391/week @ 2025-04-11

30,143 downloads per month
Used in 18 crates (4 directly)

MIT license

710KB
17K SLoC

C 12K SLoC // 0.1% comments Rust 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
~84K SLoC