fix(runtime): let matchit and matchparen skips fallback on treesitter captures

When treesitter is enabled, by default syntax groups are not defined, but these
groups are used to identify where to skip matches in matchit and matchparen.

This patch does three things:
1. If syntax is enabled regardless of treesitter (`vim.bo.syntax='on'`):
   Use original implementation.
2. If treesitter is enabled and syntax is not:
   Match the syntax groups (i.e. `comment\|string`) against treesitter captures
   to check for skipped groups.
3. Add an explicit treesitter syntax for marking captures to skip:
   matchit uses `b:match_skip` to determine what counts as skippable
   Where 's:comment\|string' uses a match of the named syntax groups against
   a regex match of comment\|string, 't:comment\|string' now uses vim regex
   to match against the names of the treesitter capture groups.

(cherry picked from commit 69aa33d890)
This commit is contained in:
Emilia Simmons
2024-12-15 13:28:16 -05:00
committed by github-actions[bot]
parent 357ee88606
commit 87440e7bc5
3 changed files with 15 additions and 1 deletions

View File

@@ -106,6 +106,10 @@ func s:Highlight_Matching_Pair()
if !has("syntax") || !exists("g:syntax_on")
let s_skip = "0"
elseif exists("b:ts_highlight") && &syntax != 'on'
let s_skip = "match(v:lua.vim.treesitter.get_captures_at_cursor(), '"
\ .. 'string\|character\|singlequote\|escape\|symbol\|comment'
\ .. "') != -1"
else
" Build an expression that detects whether the current cursor position is
" in certain syntax types (string, comment, etc.), for use as