@willbooster/tree-sitter-rust 3.1.10 → 4.0.0

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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-rust/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.36.11-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.41.8-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-rust.svg)](https://crates.io/crates/willbooster-tree-sitter-rust)
10
10
 
11
11
  Rust grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -60,6 +60,12 @@ parser.setLanguage(await Language.load(rust));
60
60
 
61
61
  The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
62
62
 
63
+ Documentation-comment injections require a host with Markdown parsing and fenced-language injections.
64
+ Line documentation is combined across the syntax tree; an unclosed fence can affect later comments.
65
+ Each block comment is a separate Markdown document. Its content is passed through unchanged, including
66
+ leading `*` gutters, which remain Markdown text and can prevent fence recognition. Use unguttered block
67
+ documentation or line documentation for fenced examples with these queries.
68
+
63
69
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-rust) and on
64
70
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
65
71
  fuzzed with. The parser loads only with that runtime, version 2.0.0 or later; upstream's `tree-sitter` crate rejects it:
@@ -75,14 +81,18 @@ let mut parser = tree_sitter::Parser::new();
75
81
  parser.set_language(&tree_sitter_rust::LANGUAGE.into())?;
76
82
  ```
77
83
 
78
- ## Expression attributes
84
+ ## Attributes
79
85
 
80
86
  An attribute in an expression position can produce an `attributed_expression` node with a `value` field.
81
87
  For example, in `let x = #[allow(unused)] 1 + 2;`, that field contains `1`; the enclosing binary expression
82
- still contains `+ 2`. Multiple attributes can form nested wrappers. Queries matching `_expression` include
83
- these wrappers. Follow each wrapper's `value` field until reaching the operand.
88
+ still contains `+ 2`. Consecutive attributes share one wrapper. Queries matching `_expression` include
89
+ these wrappers, including attributed block statements. The `value` field identifies the operand.
90
+
91
+ Outer declaration attributes belong to an `attributed_declaration` node whose `declaration` field identifies
92
+ the item. In declaration and statement positions, outer attributes without a following declaration or
93
+ expression produce a syntax error.
84
94
 
85
- Existing item, parameter and list attributes retain their sibling nodes. Attributes inside parentheses also precede
95
+ Parameter and list attributes retain their sibling nodes. Attributes inside parentheses also precede
86
96
  the operand as siblings. List and parenthesized operands remain queryable through
87
97
  `_expression`. Compiler feature gates and attribute-placement diagnostics remain the compiler's responsibility.
88
98
 
package/grammar.js CHANGED
@@ -146,7 +146,16 @@ module.exports = grammar({
146
146
  sym('_frontmatter_context'),
147
147
  ],
148
148
 
149
- supertypes: ($) => [$._declaration_statement, $._expression, $._type, $._literal, $._literal_pattern, $._pattern],
149
+ supertypes: ($) => [
150
+ $._declaration_statement,
151
+ $._foreign_declaration_statement,
152
+ $._block_statement_expression,
153
+ $._expression,
154
+ $._type,
155
+ $._literal,
156
+ $._literal_pattern,
157
+ $._pattern,
158
+ ],
150
159
 
151
160
  inline: ($) => [
152
161
  $._path,
@@ -160,13 +169,13 @@ module.exports = grammar({
160
169
  ],
161
170
 
162
171
  conflicts: ($) => [
172
+ [$._attributed_block_statement, $._expression_except_range],
163
173
  [$.type_parameters, $.for_lifetimes],
164
174
  [$.lifetime_parameter, $.for_lifetimes],
165
175
  [$._token_pattern, $.token_repetition_pattern],
166
176
  [$.token_tree, $.token_repetition],
167
177
  [$.field_initializer_list, $.block],
168
178
  [$._expression_except_range, $.shorthand_field_initializer],
169
- [$._declaration_statement, $.attributed_expression],
170
179
  [$._expression_except_range, $.struct_expression],
171
180
  [$.function_modifiers, $.modified_trait_bound],
172
181
  [$.function_modifiers, $.impl_item, $.modified_trait_bound],
@@ -196,17 +205,30 @@ module.exports = grammar({
196
205
 
197
206
  empty_statement: () => ';',
198
207
 
199
- expression_statement: ($) => choice(seq($._expression, ';'), prec(1, $._expression_ending_with_block)),
208
+ expression_statement: ($) =>
209
+ choice(
210
+ seq($._expression, ';'),
211
+ prec(1, $._expression_ending_with_block),
212
+ prec(1, alias($._block_statement_expression, $._expression))
213
+ ),
214
+
215
+ _block_statement_expression: ($) => alias($._attributed_block_statement, $.attributed_expression),
216
+
217
+ _outer_attributes: ($) => prec.right(seq($.attribute_item, repeat($.attribute_item))),
218
+
219
+ _attributed_block_statement: ($) => seq($._outer_attributes, field('value', $._expression_ending_with_block)),
200
220
 
201
221
  _declaration_statement: ($) =>
222
+ choice($.empty_statement, $.inner_attribute_item, $._attributable_declaration, $.attributed_declaration),
223
+
224
+ attributed_declaration: ($) => seq($._outer_attributes, field('declaration', $._attributable_declaration)),
225
+
226
+ _attributable_declaration: ($) =>
202
227
  choice(
203
228
  $.const_item,
204
229
  $.macro_invocation,
205
230
  $.macro_definition,
206
231
  $.decl_macro,
207
- $.empty_statement,
208
- $.attribute_item,
209
- $.inner_attribute_item,
210
232
  $.mod_item,
211
233
  $.foreign_mod_item,
212
234
  $.struct_item,
@@ -406,7 +428,31 @@ module.exports = grammar({
406
428
  // `_foreign_declaration_start` required by qualified extern items. Keep this context marker so `safe` remains
407
429
  // an identifier outside extern blocks while qualified items still participate in declaration supertype queries.
408
430
  _foreign_declaration_list: ($) =>
409
- seq('{', repeat(seq(optional(sym('_foreign_declaration_context')), $._declaration_statement)), '}'),
431
+ seq(
432
+ '{',
433
+ repeat(
434
+ seq(
435
+ optional(sym('_foreign_declaration_context')),
436
+ alias($._foreign_declaration_statement, $._declaration_statement)
437
+ )
438
+ ),
439
+ '}'
440
+ ),
441
+
442
+ _foreign_declaration_statement: ($) =>
443
+ choice(
444
+ $.empty_statement,
445
+ $.inner_attribute_item,
446
+ $._attributable_declaration,
447
+ alias($._foreign_attributed_declaration, $.attributed_declaration)
448
+ ),
449
+
450
+ _foreign_attributed_declaration: ($) =>
451
+ seq(
452
+ $._outer_attributes,
453
+ optional(sym('_foreign_declaration_context')),
454
+ field('declaration', $._attributable_declaration)
455
+ ),
410
456
 
411
457
  _safe_function_signature_item: ($) =>
412
458
  seq(
@@ -1009,7 +1055,7 @@ module.exports = grammar({
1009
1055
  _expression: ($) => choice($._expression_except_range, $.range_expression, $.attributed_expression),
1010
1056
 
1011
1057
  attributed_expression: ($) =>
1012
- prec.dynamic(-1, prec.right(PREC.unary, seq(repeat1($.attribute_item), field('value', $._expression)))),
1058
+ prec.dynamic(-1, seq($._outer_attributes, prec.right(PREC.unary, field('value', $._expression)))),
1013
1059
 
1014
1060
  _expression_ending_with_block: ($) =>
1015
1061
  choice(
@@ -1210,11 +1256,11 @@ module.exports = grammar({
1210
1256
  ),
1211
1257
 
1212
1258
  shorthand_field_initializer: ($) =>
1213
- seq(repeat($.attribute_item), choice($.identifier, alias(choice(...fieldIdentifierKeywords), $.identifier))),
1259
+ seq(optional($._outer_attributes), choice($.identifier, alias(choice(...fieldIdentifierKeywords), $.identifier))),
1214
1260
 
1215
1261
  field_initializer: ($) =>
1216
1262
  seq(
1217
- repeat($.attribute_item),
1263
+ optional($._outer_attributes),
1218
1264
  field(
1219
1265
  'field',
1220
1266
  choice(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-rust",
3
- "version": "3.1.10",
3
+ "version": "4.0.0",
4
4
  "description": "Rust grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -46,20 +46,19 @@
46
46
  "@vitest/browser-playwright": "5.0.3",
47
47
  "@willbooster/oxfmt-config": "1.2.2",
48
48
  "@willbooster/oxlint-config": "1.4.8",
49
- "@willbooster/wb": "22.24.0",
50
- "@willbooster/web-tree-sitter": "2.0.1",
51
- "conventional-changelog-conventionalcommits": "10.4.0",
52
- "lefthook": "2.1.16",
53
- "oxfmt": "0.71.0",
54
- "oxlint": "1.86.0",
55
- "oxlint-tsgolint": "7.0.2003",
56
- "playwright": "1.63.0",
49
+ "@willbooster/wb": "22.26.1",
50
+ "@willbooster/web-tree-sitter": "2.0.27",
51
+ "conventional-changelog-conventionalcommits": "10.4.1",
52
+ "lefthook": "2.2.1",
53
+ "oxfmt": "0.72.0",
54
+ "oxlint": "1.87.0",
55
+ "oxlint-tsgolint": "7.0.2004",
56
+ "playwright": "1.64.0",
57
57
  "semantic-release": "25.0.9",
58
58
  "sort-package-json": "4.0.0",
59
- "typescript": "7.0.2",
60
- "vite": "8.3.2",
59
+ "vite": "8.3.4",
61
60
  "vitest": "5.0.3",
62
- "wrangler": "4.147.0"
61
+ "wrangler": "4.149.0"
63
62
  },
64
63
  "peerDependencies": {
65
64
  "@willbooster/web-tree-sitter": "^2.0.0"
@@ -13,3 +13,12 @@
13
13
  body: (token_tree) @injection.content)
14
14
  (#set! injection.language "rust")
15
15
  (#set! injection.include-children))
16
+
17
+ ((line_comment
18
+ doc: (doc_comment) @injection.content)
19
+ (#set! injection.language "markdown")
20
+ (#set! injection.combined))
21
+
22
+ ((block_comment
23
+ doc: (doc_comment) @injection.content)
24
+ (#set! injection.language "markdown"))
package/queries/tags.scm CHANGED
@@ -1,5 +1,3 @@
1
- ; ADT definitions
2
-
3
1
  (struct_item
4
2
  name: (type_identifier) @name) @definition.class
5
3
 
@@ -9,43 +7,36 @@
9
7
  (union_item
10
8
  name: (type_identifier) @name) @definition.class
11
9
 
12
- ; type aliases
13
-
14
10
  (type_item
15
11
  name: (type_identifier) @name) @definition.class
16
12
 
17
- ; method definitions
18
-
19
13
  (declaration_list
20
14
  (function_item
21
15
  name: (identifier) @name) @definition.method)
22
16
 
23
- ; function definitions
17
+ (declaration_list
18
+ (attributed_declaration
19
+ declaration: (function_item
20
+ name: (identifier) @name) @definition.method))
24
21
 
25
22
  (function_item
26
23
  name: (identifier) @name) @definition.function
27
24
 
28
- ; trait definitions
29
25
  (trait_item
30
26
  name: (type_identifier) @name) @definition.interface
31
27
 
32
28
  (trait_alias
33
29
  name: (type_identifier) @name) @definition.interface
34
30
 
35
- ; module definitions
36
31
  (mod_item
37
32
  name: (identifier) @name) @definition.module
38
33
 
39
- ; macro definitions
40
-
41
34
  (macro_definition
42
35
  name: (identifier) @name) @definition.macro
43
36
 
44
37
  (decl_macro
45
38
  name: (identifier) @name) @definition.macro
46
39
 
47
- ; references
48
-
49
40
  (call_expression
50
41
  function: (identifier) @name) @reference.call
51
42
 
@@ -56,8 +47,6 @@
56
47
  (macro_invocation
57
48
  macro: (identifier) @name) @reference.call
58
49
 
59
- ; implementations
60
-
61
50
  (impl_item
62
51
  trait: (type_identifier) @name) @reference.implementation
63
52
 
@@ -8,7 +8,7 @@
8
8
  "named": true
9
9
  },
10
10
  {
11
- "type": "attribute_item",
11
+ "type": "attributed_declaration",
12
12
  "named": true
13
13
  },
14
14
  {
@@ -782,6 +782,108 @@
782
782
  ]
783
783
  }
784
784
  },
785
+ {
786
+ "type": "attributed_declaration",
787
+ "named": true,
788
+ "fields": {
789
+ "declaration": {
790
+ "multiple": false,
791
+ "required": true,
792
+ "types": [
793
+ {
794
+ "type": "associated_type",
795
+ "named": true
796
+ },
797
+ {
798
+ "type": "const_item",
799
+ "named": true
800
+ },
801
+ {
802
+ "type": "decl_macro",
803
+ "named": true
804
+ },
805
+ {
806
+ "type": "enum_item",
807
+ "named": true
808
+ },
809
+ {
810
+ "type": "extern_crate_declaration",
811
+ "named": true
812
+ },
813
+ {
814
+ "type": "foreign_mod_item",
815
+ "named": true
816
+ },
817
+ {
818
+ "type": "function_item",
819
+ "named": true
820
+ },
821
+ {
822
+ "type": "function_signature_item",
823
+ "named": true
824
+ },
825
+ {
826
+ "type": "impl_item",
827
+ "named": true
828
+ },
829
+ {
830
+ "type": "let_declaration",
831
+ "named": true
832
+ },
833
+ {
834
+ "type": "macro_definition",
835
+ "named": true
836
+ },
837
+ {
838
+ "type": "macro_invocation",
839
+ "named": true
840
+ },
841
+ {
842
+ "type": "mod_item",
843
+ "named": true
844
+ },
845
+ {
846
+ "type": "static_item",
847
+ "named": true
848
+ },
849
+ {
850
+ "type": "struct_item",
851
+ "named": true
852
+ },
853
+ {
854
+ "type": "trait_alias",
855
+ "named": true
856
+ },
857
+ {
858
+ "type": "trait_item",
859
+ "named": true
860
+ },
861
+ {
862
+ "type": "type_item",
863
+ "named": true
864
+ },
865
+ {
866
+ "type": "union_item",
867
+ "named": true
868
+ },
869
+ {
870
+ "type": "use_declaration",
871
+ "named": true
872
+ }
873
+ ]
874
+ }
875
+ },
876
+ "children": {
877
+ "multiple": true,
878
+ "required": true,
879
+ "types": [
880
+ {
881
+ "type": "attribute_item",
882
+ "named": true
883
+ }
884
+ ]
885
+ }
886
+ },
785
887
  {
786
888
  "type": "attributed_expression",
787
889
  "named": true,
Binary file
package/tree-sitter.json CHANGED
@@ -25,7 +25,7 @@
25
25
  }
26
26
  ],
27
27
  "metadata": {
28
- "version": "3.1.10",
28
+ "version": "4.0.0",
29
29
  "license": "MIT",
30
30
  "description": "Rust grammar for tree-sitter",
31
31
  "authors": [