Skip to content

Commit a2b8e91

Browse files
tenderlovetpope
authored andcommitted
Add highlighting for shareable_constant_value
Ruby 3.0.0 added a new magic comment for making different literals "shareable" (a.k.a frozen). Here is a link to the docs: https://github.com/ruby/ruby/blob/cfbf2bde4002821d12047b2aba0010739aaf925e/doc/syntax/comments.rdoc#label-shareable_constant_value+Directive Here's a demo of the feature: ``` $ cat test.rb # shareable_constant_value: literal FOO = [ 1, 2, 3 ] p FOO.frozen? $ ruby test.rb true ```
1 parent 10dfcbe commit a2b8e91

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

spec/syntax/comments_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
EOF
4141
end
4242

43+
specify "magic comments - shareable_constant_value" do
44+
assert_correct_highlighting <<~'EOF', 'shareable_constant_value', 'rubyMagicComment'
45+
# shareable_constant_value: literal
46+
EOF
47+
end
48+
4349
specify "TODO comments" do
4450
assert_correct_highlighting <<~'EOF', 'TODO', 'rubyTodo'
4551
# TODO: turn off the oven

syntax/ruby.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,10 @@ endif
429429
" Comments and Documentation {{{1
430430
syn match rubySharpBang "\%^#!.*" display
431431
syn keyword rubyTodo FIXME NOTE TODO OPTIMIZE HACK REVIEW XXX todo contained
432-
syn match rubyEncoding "[[:alnum:]-]\+" contained display
432+
syn match rubyEncoding "[[:alnum:]-_]\+" contained display
433433
syn match rubyMagicComment "\c\%<3l#\s*\zs\%(coding\|encoding\):" contained nextgroup=rubyEncoding skipwhite
434434
syn match rubyMagicComment "\c\%<10l#\s*\zs\%(frozen_string_literal\|warn_indent\|warn_past_scope\):" contained nextgroup=rubyBoolean skipwhite
435+
syn match rubyMagicComment "\c\%<10l#\s*\zs\%(shareable_constant_value\):" contained nextgroup=rubyEncoding skipwhite
435436
syn match rubyComment "#.*" contains=@rubyCommentSpecial,rubySpaceError,@Spell
436437

437438
syn cluster rubyCommentSpecial contains=rubySharpBang,rubyTodo,rubyMagicComment

0 commit comments

Comments
 (0)