diff --git a/extension.toml b/extension.toml index eca5d00..953aa07 100644 --- a/extension.toml +++ b/extension.toml @@ -48,7 +48,7 @@ commit = "c70c1de07dedd532089c0c90835c8ed9fa694f5c" [grammars.rbs] repository = "https://github.com/joker1007/tree-sitter-rbs" -commit = "de893b166476205b09e79cd3689f95831269579a" +commit = "6bcfa169021a9cc40fb47cd75ef4b4d3767d6ab5" [[capabilities]] kind = "process:exec" diff --git a/languages/rbs/highlights.scm b/languages/rbs/highlights.scm index 4ab0b1a..3b25478 100644 --- a/languages/rbs/highlights.scm +++ b/languages/rbs/highlights.scm @@ -161,3 +161,6 @@ "," "." ] @punctuation.delimiter + +; RBS Inline prefix (keep comment color) +(inline_prefix) @comment diff --git a/languages/ruby/highlights.scm b/languages/ruby/highlights.scm index 2ee9103..0b81895 100644 --- a/languages/ruby/highlights.scm +++ b/languages/ruby/highlights.scm @@ -143,7 +143,10 @@ (nil) ] @constant.builtin -(comment) @comment +; Regular comments (exclude RBS inline comments) +((comment) @comment + (#not-match? @comment "^\\s*#[:|]") + (#not-match? @comment "^\\s*#\\s*(@rbs|\\|)")) ; Operators diff --git a/languages/ruby/injections.scm b/languages/ruby/injections.scm index b7f5d4c..f91d93c 100644 --- a/languages/ruby/injections.scm +++ b/languages/ruby/injections.scm @@ -7,5 +7,22 @@ (string_content) @content) (#set! "language" "regex")) +; RBS Inline: #: syntax +((comment) @content + (#match? @content "^\\s*#:") + (#set! injection.language "rbs")) + +; RBS Inline: # @rbs syntax +((comment) @content + (#match? @content "^\\s*#\\s*@rbs") + (#set! injection.language "rbs")) + +; RBS Inline: continuation lines (e.g., "#| param: Type" or "# | (?Regexp?) -> void") +; Note: These will parse with errors since they're not complete RBS on their own, +; but types within them will still get highlighted +((comment) @content + (#match? @content "^\\s*#\\s*\\|") + (#set! injection.language "rbs")) + ((comment) @content (#set! injection.language "comment"))