Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to vim syntax highlight Ruby Sorbet signatures as de-emphasized comments?

Normally, Sorbet signatures are syntax highlighted as normal Ruby:
enter image description here

However, I'd like to visually de-emphasize the noisy signatures, perhaps by highlighting them as comments instead.

The following at ~/.vim/after/syntax/ruby.vim gets me part of the way there:

" adapted from: https://github.com/zackhsi/sorbet.vim/blob/master/syntax/ruby.vim
syntax region SigBlock matchgroup=SigBlockDelimiter start="{" end="}" contained transparent
syntax region SigBlock matchgroup=SigBlockDelimiter start="\<do\>" end="\<end\>" contained transparent

" Prevent sorbet elements from being contained by vim-ruby elements.
syntax cluster rubyNotTop add=SigBlock

syntax match Sig "\<sig\>" nextgroup=SigBlock skipwhite

" hi def link SigBlockDelimiter rubyDefine

" Match vim-ruby:
" https://github.com/vim-ruby/vim-ruby/commit/19c19a54583c3e7c07dce18b844ae104695c41d7.
syntax match rubyMagicComment "\c\%<10l#\s*\zs\%(typed\):" contained nextgroup=rubyBoolean skipwhite

" de-emphasize Sorbet sig
highlight default link Sig               Comment
highlight default link SigBlockDelimiter Comment

Like so:
enter image description here

How do I get the code inside the signature block also highlighted as Comment?

For reference, I'm using sheerun/vim-polyglot (i.e. vim-ruby/vim-ruby) and nanotech/jellybeans.vim. Also, even more ideal would be to retain colors, but only "decrease contrast", a la VSCode's byesig extension, but that probably requires defining a lot of new colors and syntax rules?

like image 396
Kache Avatar asked Oct 27 '25 12:10

Kache


1 Answers

transparent causes highlighting to be inherited, you don't want that. You can also remove matchgroup since you don't want to highlight delimiters separately:

" https://github.com/zackhsi/sorbet.vim/blob/master/syntax/ruby.vim

syntax region SigBlock start="{" end="}" contained
syntax region SigBlock start="\<do\>" end="\<end\>" contained

syntax cluster rubyNotTop add=SigBlock

syntax match Sig "\<sig\>" nextgroup=SigBlock skipwhite

syntax match rubyMagicComment "\c\%<10l#\s*\zs\%(typed\):" contained nextgroup=rubyBoolean skipwhite

highlight default link Sig      Comment
highlight default link SigBlock Comment

enter image description here

like image 66
Alex Avatar answered Oct 29 '25 05:10

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!