rbtr-lang-rust 2026.9.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alejandro Giacometti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: rbtr-lang-rust
3
+ Version: 2026.9.0.dev1
4
+ Summary: rbtr — Rust language plugin
5
+ Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,rust
6
+ Author: Alejandro Giacometti
7
+ Author-email: Alejandro Giacometti <alejandro.giacometti@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Rust
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Topic :: Text Processing :: Indexing
17
+ Classifier: Typing :: Typed
18
+ Requires-Dist: rbtr==2026.9.0.dev1
19
+ Requires-Dist: tree-sitter-rust
20
+ Requires-Python: >=3.13
21
+ Project-URL: Homepage, https://github.com/janrito/rbtr
22
+ Project-URL: Repository, https://github.com/janrito/rbtr
23
+ Project-URL: Documentation, https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-rust#readme
24
+ Project-URL: Issues, https://github.com/janrito/rbtr/issues
25
+ Project-URL: Changelog, https://github.com/janrito/rbtr/releases
26
+ Description-Content-Type: text/markdown
27
+
28
+ # rbtr-lang-rust
29
+
30
+ Rust support for [rbtr]. Optional plugin — install with
31
+ `pip install rbtr[rust]`.
32
+
33
+ [rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
34
+
35
+ ## What it ingests
36
+
37
+ - **Functions & methods** — `fn`; functions inside an `impl` are methods
38
+ scoped to the type.
39
+ - **Classes** — `struct`, `enum`, `trait`, and `impl` blocks (an `impl Svc`
40
+ and `struct Svc` both yield a `Svc` class chunk).
41
+ - **Variables** — module-level `const` / `static`.
42
+ - **Imports** — `use` declarations (scoped paths resolved), for cross-file
43
+ edges.
44
+ - **Attributes** — `#[derive(...)]`, `#[serde(...)]` and the rest fold into
45
+ the item below them, so a type is findable by the traits it derives. A
46
+ module-level `#![allow(...)]`, with no item under it, is its own chunk.
47
+
48
+ Leading `///` / `//!` doc comments fold into the symbol's content, together
49
+ with any attribute between the comment and the item.
50
+
51
+ ## Chunks produced
52
+
53
+ ```rust
54
+ fn greet(name: &str) -> String { … } // function "greet"
55
+ struct Server { … } // class "Server"
56
+ impl Server { fn start(&self) {} } // class "Server"; method "start", scope "Server"
57
+ const MAX: u32 = 100; // variable "MAX"
58
+ use crate::config::Config; // import, metadata {module: crate::config::Config}
59
+ ```
60
+
61
+ ## Embedded / injected chunks
62
+
63
+ None. Rust does not embed other languages.
64
+
65
+ ## Grammar & dependencies
66
+
67
+ Uses the `tree-sitter-rust` grammar. No dependency on other language plugins.
@@ -0,0 +1,40 @@
1
+ # rbtr-lang-rust
2
+
3
+ Rust support for [rbtr]. Optional plugin — install with
4
+ `pip install rbtr[rust]`.
5
+
6
+ [rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
7
+
8
+ ## What it ingests
9
+
10
+ - **Functions & methods** — `fn`; functions inside an `impl` are methods
11
+ scoped to the type.
12
+ - **Classes** — `struct`, `enum`, `trait`, and `impl` blocks (an `impl Svc`
13
+ and `struct Svc` both yield a `Svc` class chunk).
14
+ - **Variables** — module-level `const` / `static`.
15
+ - **Imports** — `use` declarations (scoped paths resolved), for cross-file
16
+ edges.
17
+ - **Attributes** — `#[derive(...)]`, `#[serde(...)]` and the rest fold into
18
+ the item below them, so a type is findable by the traits it derives. A
19
+ module-level `#![allow(...)]`, with no item under it, is its own chunk.
20
+
21
+ Leading `///` / `//!` doc comments fold into the symbol's content, together
22
+ with any attribute between the comment and the item.
23
+
24
+ ## Chunks produced
25
+
26
+ ```rust
27
+ fn greet(name: &str) -> String { … } // function "greet"
28
+ struct Server { … } // class "Server"
29
+ impl Server { fn start(&self) {} } // class "Server"; method "start", scope "Server"
30
+ const MAX: u32 = 100; // variable "MAX"
31
+ use crate::config::Config; // import, metadata {module: crate::config::Config}
32
+ ```
33
+
34
+ ## Embedded / injected chunks
35
+
36
+ None. Rust does not embed other languages.
37
+
38
+ ## Grammar & dependencies
39
+
40
+ Uses the `tree-sitter-rust` grammar. No dependency on other language plugins.
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.11.26,<1"]
3
+ build-backend = "uv_build"
4
+
5
+ [tool.uv.build-backend]
6
+ module-name = "rbtr_lang_rust"
7
+
8
+ [tool.uv.sources.rbtr]
9
+ workspace = true
10
+
11
+ [project]
12
+ name = "rbtr-lang-rust"
13
+ version = "2026.9.0-dev1"
14
+ description = "rbtr — Rust language plugin"
15
+ readme = "README.md"
16
+ license = "MIT"
17
+ license-files = ["LICENSE"]
18
+ keywords = [
19
+ "code-search",
20
+ "code-index",
21
+ "tree-sitter",
22
+ "static-analysis",
23
+ "semantic-search",
24
+ "developer-tools",
25
+ "rust",
26
+ ]
27
+ classifiers = [
28
+ "Development Status :: 4 - Beta",
29
+ "Intended Audience :: Developers",
30
+ "Programming Language :: Python :: 3 :: Only",
31
+ "Programming Language :: Python :: 3.13",
32
+ "Programming Language :: Rust",
33
+ "Topic :: Software Development :: Libraries",
34
+ "Topic :: Text Processing :: Indexing",
35
+ "Typing :: Typed",
36
+ ]
37
+ requires-python = ">=3.13"
38
+ dependencies = [
39
+ "rbtr==2026.9.0-dev1",
40
+ "tree-sitter-rust",
41
+ ]
42
+
43
+ [[project.authors]]
44
+ name = "Alejandro Giacometti"
45
+ email = "alejandro.giacometti@gmail.com"
46
+
47
+ [project.urls]
48
+ Homepage = "https://github.com/janrito/rbtr"
49
+ Repository = "https://github.com/janrito/rbtr"
50
+ Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-rust#readme"
51
+ Issues = "https://github.com/janrito/rbtr/issues"
52
+ Changelog = "https://github.com/janrito/rbtr/releases"
53
+
54
+ [project.entry-points."rbtr.languages"]
55
+ rust = "rbtr_lang_rust.plugin:rust"
56
+
57
+ [dependency-groups]
58
+ dev = ["rbtr[test]"]
@@ -0,0 +1,62 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.11.26,<1"]
3
+ build-backend = "uv_build"
4
+
5
+ [tool.uv.build-backend]
6
+ module-name = "rbtr_lang_rust"
7
+ # No source-exclude: the plugin's tests, samples, and snapshots ship with
8
+ # the wheel (they are the language's golden record), and rust.scm ships as
9
+ # package data.
10
+
11
+ [project]
12
+ name = "rbtr-lang-rust"
13
+ version = "2026.9.0-dev1"
14
+ description = "rbtr — Rust language plugin"
15
+ readme = "README.md"
16
+ license = "MIT"
17
+ license-files = ["LICENSE"]
18
+ authors = [
19
+ { name = "Alejandro Giacometti", email = "alejandro.giacometti@gmail.com" },
20
+ ]
21
+ keywords = [
22
+ "code-search",
23
+ "code-index",
24
+ "tree-sitter",
25
+ "static-analysis",
26
+ "semantic-search",
27
+ "developer-tools",
28
+ "rust",
29
+ ]
30
+ classifiers = [
31
+ "Development Status :: 4 - Beta",
32
+ "Intended Audience :: Developers",
33
+ "Programming Language :: Python :: 3 :: Only",
34
+ "Programming Language :: Python :: 3.13",
35
+ "Programming Language :: Rust",
36
+ "Topic :: Software Development :: Libraries",
37
+ "Topic :: Text Processing :: Indexing",
38
+ "Typing :: Typed",
39
+ ]
40
+ requires-python = ">=3.13"
41
+ dependencies = [
42
+ "rbtr==2026.9.0-dev1",
43
+ "tree-sitter-rust",
44
+ ]
45
+
46
+ [project.urls]
47
+ Homepage = "https://github.com/janrito/rbtr"
48
+ Repository = "https://github.com/janrito/rbtr"
49
+ Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-rust#readme"
50
+ Issues = "https://github.com/janrito/rbtr/issues"
51
+ Changelog = "https://github.com/janrito/rbtr/releases"
52
+
53
+ [project.entry-points."rbtr.languages"]
54
+ # The value resolves to the language's `LanguageRegistration` (named by its
55
+ # id) — see the rbtr ARCHITECTURE "External plugins" note.
56
+ rust = "rbtr_lang_rust.plugin:rust"
57
+
58
+ [tool.uv.sources]
59
+ rbtr = { workspace = true }
60
+
61
+ [dependency-groups]
62
+ dev = ["rbtr[test]"]
@@ -0,0 +1 @@
1
+ """Rust language plugin package."""
@@ -0,0 +1,147 @@
1
+ """Rust language plugin.
2
+
3
+ Provides full support: functions, structs, enums, unions, type
4
+ aliases, traits, modules, impl blocks, `macro_rules!` definitions,
5
+ and `use` declaration extraction. Traits, modules, and impl blocks
6
+ form naming scopes; trait and impl members are methods.
7
+
8
+ Extracted chunks::
9
+
10
+ fn hello() {} → function "hello", scope ""
11
+ struct User { name: String } → class "User", scope ""
12
+ enum Color { Red, Green } → class "Color", scope ""
13
+ impl Svc {
14
+ fn start(&self) {} → method "start", scope "Svc"
15
+ }
16
+
17
+ use std::collections::HashMap
18
+ → import, metadata {module: "std/collections", names: "HashMap"}
19
+ use crate::models::{Chunk, Edge}
20
+ → import, metadata {module: "crate/models", names: "Chunk,Edge"}
21
+ use super::utils
22
+ → import, metadata {names: "utils", dots: "2"}
23
+ """
24
+
25
+ from __future__ import annotations
26
+
27
+ from typing import TYPE_CHECKING
28
+
29
+ from rbtr.domain.models import ImportMeta
30
+ from rbtr.languages.registration import (
31
+ ImportResolver,
32
+ LanguageRegistration,
33
+ QueryExtraction,
34
+ collect_scoped_path,
35
+ load_query,
36
+ )
37
+
38
+ if TYPE_CHECKING:
39
+ from tree_sitter import Node
40
+
41
+ # ── Query ────────────────────────────────────────────────────────────
42
+
43
+
44
+ # ── Import extractor ─────────────────────────────────────────────────
45
+
46
+
47
+ def _path_to_meta(parts: list[str], meta: ImportMeta) -> None:
48
+ """Convert collected Rust path segments into module/dots metadata.
49
+
50
+ Leading `super` segments are counted as relative dots using
51
+ the unified convention (each `super` = one extra level up,
52
+ plus 1 for the file itself). `crate` is kept as a literal
53
+ path segment — it's root-relative, not parent-relative.
54
+ """
55
+ dots = 0
56
+ while parts and parts[0] == "super":
57
+ dots += 1
58
+ parts = parts[1:]
59
+ if dots:
60
+ meta.dots = str(dots + 1) # +1: super = parent dir = 2 levels from file
61
+
62
+ if parts:
63
+ meta.module = "/".join(parts)
64
+
65
+
66
+ def extract_import_meta(
67
+ _resolver: ImportResolver, node: Node, captures: dict[str, list[Node]]
68
+ ) -> ImportMeta:
69
+ """Extract import data from a Rust `use_declaration` node.
70
+
71
+ Walks the node's `argument` field for module path and names.
72
+ The query only captures `@import` — module extraction needs
73
+ `collect_scoped_path` to flatten `scoped_identifier` trees
74
+ and `_path_to_meta` to convert `super` segments to dots.
75
+
76
+ Examples:
77
+
78
+ `use std::collections::HashMap;`:
79
+ module="std/collections", names="HashMap"
80
+
81
+ `use crate::models::{Chunk, Edge};`:
82
+ module="crate/models", names="Chunk,Edge"
83
+
84
+ `use super::utils;`:
85
+ names="utils", dots="2"
86
+
87
+ `use std::io::{self, Read};`:
88
+ module="std/io", names="self,Read"
89
+
90
+ `use serde;`:
91
+ module="serde"
92
+ """
93
+ meta = ImportMeta()
94
+ arg = node.child_by_field_name("argument")
95
+ if arg is None:
96
+ return meta
97
+
98
+ match arg.type:
99
+ case "scoped_identifier":
100
+ parts = collect_scoped_path(arg)
101
+ if len(parts) > 1:
102
+ _path_to_meta(parts[:-1], meta)
103
+ meta.names = parts[-1]
104
+ elif parts:
105
+ _path_to_meta(parts, meta)
106
+
107
+ case "scoped_use_list":
108
+ path_parts: list[str] = []
109
+ names: list[str] = []
110
+ for sc in arg.children:
111
+ if sc.type == "scoped_identifier":
112
+ path_parts = collect_scoped_path(sc)
113
+ elif sc.type == "use_list":
114
+ for item in sc.children:
115
+ if item.type == "identifier" and item.text:
116
+ names.append(item.text.decode())
117
+ elif item.type == "self":
118
+ names.append("self")
119
+ _path_to_meta(path_parts, meta)
120
+ if names:
121
+ meta.names = ",".join(names)
122
+
123
+ case "identifier":
124
+ if arg.text:
125
+ meta.module = arg.text.decode()
126
+
127
+ return meta
128
+
129
+
130
+ # ── Plugin ───────────────────────────────────────────────────────────
131
+
132
+
133
+ rust = LanguageRegistration(
134
+ id="rust",
135
+ extensions=frozenset({".rs"}),
136
+ grammar_module="tree_sitter_rust",
137
+ extraction=QueryExtraction(
138
+ query=load_query(__package__, "rust"),
139
+ scope_types=frozenset({"impl_item", "struct_item", "trait_item", "mod_item", "enum_item"}),
140
+ class_scope_types=frozenset({"impl_item", "struct_item", "trait_item"}),
141
+ ),
142
+ index_files=frozenset({"mod.rs"}),
143
+ path_substitutions=(("crate/", "src/"),),
144
+ extraction_serial=6,
145
+ )
146
+
147
+ rust.import_extractor(extract_import_meta)
@@ -0,0 +1,52 @@
1
+ ; Comments (Rust: `//`/`///`/`//!` line and `/* */` block).
2
+ [(line_comment) (block_comment)] @comment
3
+
4
+ ; An attribute documents the item below it and is its sibling in the
5
+ ; tree, so it folds into that item exactly as a comment block does. One
6
+ ; standing alone — a module's `#![allow(...)]` — becomes its own chunk.
7
+ (source_file [(attribute_item) (inner_attribute_item)] @comment)
8
+
9
+ (function_item
10
+ name: (identifier) @_fn_name) @function
11
+
12
+ (function_signature_item
13
+ name: (identifier) @_fn_name) @function
14
+
15
+ (struct_item
16
+ name: (type_identifier) @_cls_name) @class
17
+
18
+ (enum_item
19
+ name: (type_identifier) @_cls_name) @class
20
+
21
+ (enum_item
22
+ body: (enum_variant_list
23
+ (enum_variant
24
+ name: (identifier) @_var_name) @variable))
25
+
26
+ (union_item
27
+ name: (type_identifier) @_cls_name) @class
28
+
29
+ (type_item
30
+ name: (type_identifier) @_cls_name) @class
31
+
32
+ (trait_item
33
+ name: (type_identifier) @_cls_name) @class
34
+
35
+ (mod_item
36
+ name: (identifier) @_cls_name) @class
37
+
38
+ (macro_definition
39
+ name: (identifier) @_fn_name) @function
40
+
41
+ (impl_item
42
+ type: (type_identifier) @_cls_name) @class
43
+
44
+ (use_declaration) @import
45
+
46
+ (source_file
47
+ (const_item
48
+ name: (identifier) @_var_name) @variable)
49
+
50
+ (source_file
51
+ (static_item
52
+ name: (identifier) @_var_name) @variable)
@@ -0,0 +1,3 @@
1
+ [
2
+ "rust.rs::use crate::config::LOCALE; -> src/config.rs::LOCALE [imports]"
3
+ ]