Be more careful about whether we have TS capability

This commit is contained in:
Andy K. Massimino
2021-12-31 12:04:47 -05:00
parent bb2709884f
commit cc1d044241
2 changed files with 15 additions and 4 deletions

View File

@@ -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
@@ -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
@@ -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)

View File

@@ -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
@@ -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