Skip to content

Commit 89fd90a

Browse files
authored
feat: Add RBS Inline syntax highlighting support (#206)
This pull request adds support for [RBS Inline syntax](https://github.com/soutaro/rbs-inline/wiki/Syntax-guide) highlighting within Ruby files. <img width="2584" height="2584" alt="CleanShot 2025-11-08 at 21 03 59@2x" src="https://github.com/user-attachments/assets/05976d45-f4c0-410b-83d0-64ce13538dfe" /> Resolves #204 Enabled by joker1007/tree-sitter-rbs#17 Inspired by Shopify/ruby-lsp#3215
1 parent 5eddb4a commit 89fd90a

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

extension.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ commit = "c70c1de07dedd532089c0c90835c8ed9fa694f5c"
4848

4949
[grammars.rbs]
5050
repository = "https://github.com/joker1007/tree-sitter-rbs"
51-
commit = "de893b166476205b09e79cd3689f95831269579a"
51+
commit = "6bcfa169021a9cc40fb47cd75ef4b4d3767d6ab5"
5252

5353
[[capabilities]]
5454
kind = "process:exec"

languages/rbs/highlights.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,6 @@
161161
","
162162
"."
163163
] @punctuation.delimiter
164+
165+
; RBS Inline prefix (keep comment color)
166+
(inline_prefix) @comment

languages/ruby/highlights.scm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@
143143
(nil)
144144
] @constant.builtin
145145

146-
(comment) @comment
146+
; Regular comments (exclude RBS inline comments)
147+
((comment) @comment
148+
(#not-match? @comment "^\\s*#[:|]")
149+
(#not-match? @comment "^\\s*#\\s*(@rbs|\\|)"))
147150

148151
; Operators
149152

languages/ruby/injections.scm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,22 @@
77
(string_content) @content)
88
(#set! "language" "regex"))
99

10+
; RBS Inline: #: syntax
11+
((comment) @content
12+
(#match? @content "^\\s*#:")
13+
(#set! injection.language "rbs"))
14+
15+
; RBS Inline: # @rbs syntax
16+
((comment) @content
17+
(#match? @content "^\\s*#\\s*@rbs")
18+
(#set! injection.language "rbs"))
19+
20+
; RBS Inline: continuation lines (e.g., "#| param: Type" or "# | (?Regexp?) -> void")
21+
; Note: These will parse with errors since they're not complete RBS on their own,
22+
; but types within them will still get highlighted
23+
((comment) @content
24+
(#match? @content "^\\s*#\\s*\\|")
25+
(#set! injection.language "rbs"))
26+
1027
((comment) @content
1128
(#set! injection.language "comment"))

0 commit comments

Comments
 (0)