rubyvimsyntax-highlightingvim-pluginsorbet

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?


Solution

  • 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