Skip to content

Commit 3ce9025

Browse files
committed
feat: add support for RBS inline type annotations
Adds recognition of RBS (Ruby Signature) inline type annotation comments to enable better editor support for Ruby type annotations. Changes: - Add rbs_type_comment token for #: comments - Add rbs_continuation_comment token for #| comments - Include both tokens in extras to allow them anywhere - Add highlighting queries to style RBS comments as @type.annotation - Add comprehensive test coverage with 11 test cases This implementation intentionally only recognizes RBS comment patterns without parsing the type syntax itself. This keeps the grammar simple while providing the foundation for tools to identify and process type annotations separately. RBS comments are now distinguished from regular comments in the AST, allowing editors to provide enhanced type information display and navigation for Ruby code with inline type signatures.
1 parent 89bd7a8 commit 3ce9025

File tree

6 files changed

+64205
-48119
lines changed

6 files changed

+64205
-48119
lines changed

grammar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ module.exports = grammar({
7676

7777
extras: $ => [
7878
$.comment,
79+
$.rbs_type_comment,
80+
$.rbs_continuation_comment,
7981
$.heredoc_body,
8082
/\s/,
8183
/\\\r?\n/,
@@ -1068,6 +1070,17 @@ module.exports = grammar({
10681070
),
10691071
))),
10701072

1073+
// Simplified RBS type annotations - just recognize the pattern
1074+
rbs_type_comment: _ => token(seq(
1075+
'#:',
1076+
/.*/
1077+
)),
1078+
1079+
rbs_continuation_comment: _ => token(seq(
1080+
'#|',
1081+
/.*/
1082+
)),
1083+
10711084
integer: _ => /0[bB][01](_?[01])*|0[oO]?[0-7](_?[0-7])*|(0[dD])?\d(_?\d)*|0[xX][0-9a-fA-F](_?[0-9a-fA-F])*/,
10721085
_int_or_float: $ => choice($.integer, $.float),
10731086
float: _ => /\d(_?\d)*(\.\d)?(_?\d)*([eE][\+-]?\d(_?\d)*)?/,

queries/highlights.scm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128

129129
(comment) @comment
130130

131+
; RBS Type Annotations
132+
(rbs_type_comment) @type.annotation
133+
(rbs_continuation_comment) @type.annotation
134+
131135
; Operators
132136

133137
[

src/grammar.json

Lines changed: 43 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)