Highlight matching angle brackets in Rust syntax

Trying to fix a bug in the Rust vim plugin, I thought it might be worth consulting this.

Rust has common traits denoted with angle brackets ( <...>

), similar to C ++ or Java. However, it is possible that an arrow ( ->

) may appear inside . As an example, consider the expression

Box<Fn(A) -> B>

      

When the cursor is over the opening parenthesis, vim highlights the arrow >

instead of the closing parenthesis.

Now I thought it was because the syntax scope match did not cause special cases of arrows to exist. I tried to fix this by changing end=/>/

to end=/-\@<!>/

in my definition. But it doesn't seem to affect the selection of parentheses. Now I'm starting to think that the syntax scopes have nothing to do with it.

To conclude, my question is, how can you change the way you match parentheses for selection?

+3


source to share


1 answer


This is actually handled by the MatchParen plugin (comes with all vim installations).

The MatchParen plugin uses a fixed list of syntax attributes to ignore when looking for a matching parenthesis (From around line 96 in $VIMRUNTIME/plugin/matchparen.vim

)

  " When not in a string or comment ignore matches inside them.
  " We match "escape" for special items, such as lispEscapeSpecial.
  let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' .
    \ '=~?  "string\\|character\\|singlequote\\|escape\\|comment"'
  execute 'if' s_skip '| let s_skip = 0 | endif'

      



s_skip

then passed to searchpairpos

later. Doesn't look like it can be changed s_skip

from outside the plugin anyway .

So, if you change all instances rustArrow

to rustArrowCharacter

, the brace highlighting is correct. (There are three instances to change, two in syntax/rust.vim

and one ftplugin/rust.vim

). Validation simply checks if a line, character, single comment, escape or comment appears anywhere in the syntax attribute (case insensitive). If it skips it when looking for matching parentheses.

I would recommend asking vim-dev if matchparen can be fixed so that custom syntax attributes can be added to the skip list.

+3


source