Skip to content

Commit

Permalink
Be more careful about whether we have TS capability
Browse files Browse the repository at this point in the history
  • Loading branch information
andymass committed Dec 31, 2021
1 parent bb27098 commit cc1d044
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 9 additions & 2 deletions autoload/matchup/loader.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function! matchup#loader#init_buffer() abort " {{{1

let l:has_ts = 0
let [l:no_words, l:filt_words] = [0, 0]
if has('nvim-0.5.0') && matchup#ts_engine#is_enabled(bufnr('%'))
if s:ts_may_be_supported && matchup#ts_engine#is_enabled(bufnr('%'))
let l:has_ts = 1
if matchup#ts_engine#get_option(bufnr('%'), 'include_match_words')
let l:filt_words = 1
Expand All @@ -33,7 +33,7 @@ function! matchup#loader#init_buffer() abort " {{{1
endif

let l:has_ts_hl = 0
if has('nvim-0.5.0') && empty(&syntax)
if s:ts_may_be_supported && empty(&syntax)
\ && matchup#ts_engine#is_hl_enabled(bufnr('%'))
let l:has_ts_hl = 1

Expand Down Expand Up @@ -82,6 +82,13 @@ function! matchup#loader#init_buffer() abort " {{{1
call matchup#perf#toc('loader_init_buffer', 'done')
endfunction

function! matchup#loader#_treesitter_may_be_supported() abort
return s:ts_may_be_supported
endfunction

let s:ts_may_be_supported = has('nvim-0.5.0') && exists('*luaeval')
\ && luaeval('pcall(require, "treesitter-matchup")')

" }}}1
function! matchup#loader#bufwinenter() abort " {{{1
if get(b:, 'matchup_delim_enabled', 0)
Expand Down
8 changes: 6 additions & 2 deletions autoload/matchup/matchparen.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1112,8 +1112,10 @@ function! s:add_matches(corrlist, ...) " {{{1
endif

if exists('s:ns_id')
if strlen(l:corr.match) == 0 && !matchup#ts_engine#get_option(
\ bufnr('%'), 'disable_virtual_text')
if strlen(l:corr.match) == 0
\ && matchup#loader#_treesitter_may_be_supported()
\ && !matchup#ts_engine#get_option(
\ bufnr('%'), 'disable_virtual_text')
if hlexists('MatchupVirtualText')
let l:group = 'MatchupVirtualText'
endif
Expand Down Expand Up @@ -1141,7 +1143,9 @@ endfunction

if has('nvim-0.5.0')
let s:ns_id = nvim_create_namespace('vim-matchup')
endif

if has('nvim-0.5.0') && matchup#loader#_treesitter_may_be_supported()
function s:synID(lnum, col, trans)
return matchup#ts_syntax#synID(a:lnum, a:col, a:trans)
endfunction
Expand Down

0 comments on commit cc1d044

Please sign in to comment.