如何在 vim 语法中将 Ruby Sorbet 签名突出显示为不强调的注释?

问题描述 投票:0回答:1

通常,Sorbet 签名的语法与普通 Ruby 一样突出显示:

但是,我想在视觉上弱化嘈杂的签名,也许可以通过将它们突出显示为注释来代替。

~/.vim/after/syntax/ruby.vim
的以下内容让我完成了部分工作:

" 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

像这样:

如何获取签名块内的代码也突出显示为

Comment

作为参考,我使用

sheerun/vim-polyglot
(即
vim-ruby/vim-ruby
)和
nanotech/jellybeans.vim
。另外,更理想的是保留颜色,但仅“降低对比度”,这是 VSCode 的 byesig 扩展,但这可能需要定义大量新的颜色和语法规则?

ruby vim syntax-highlighting vim-plugin sorbet
1个回答
0
投票

transparent
导致突出显示被继承,你不希望这样。 您还可以删除
matchgroup
,因为您不想单独突出显示分隔符:

" 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

© www.soinside.com 2019 - 2024. All rights reserved.