Skip to content

Commit 40548af

Browse files
committed
fix(treesitter): ctrl-c should interrupt %
nvim often hang on `%` on file with slow treesitter support
1 parent a2d6184 commit 40548af

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

autoload/matchup/delim.vim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ function! s:get_delim_multi(opts) abort " {{{1
4444
let l:best = {}
4545
for l:e in get(get(b:, 'matchup_active_engines', {}), a:opts.type, [])
4646
let l:res = call(s:engines[l:e].get_delim, [a:opts])
47-
if empty(l:res)
48-
continue
49-
endif
47+
if l:res is 0 | return | endif
48+
if empty(l:res) | continue | endif
5049
if a:opts.direction ==# 'current'
5150
return l:res
5251
elseif a:opts.direction ==# 'next'

autoload/matchup/motion.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function! matchup#motion#find_matching_pair(visual, down) " {{{1
5353

5454
" get a delim where the cursor is
5555
let l:delim = matchup#delim#get_current('all', 'both_all')
56+
if l:delim is 0 | return | endif
5657
if empty(l:delim)
5758
" otherwise search forward
5859
let l:delim = matchup#delim#get_next('all', 'both_all')

autoload/matchup/ts_engine.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function! matchup#ts_engine#get_delim(opts) abort
2525
call matchup#perf#tic('ts_engine.get_delim')
2626

2727
let l:res = s:forward('get_delim', bufnr('%'), a:opts)
28+
if l:res is 0 | return | endif
2829
if empty(l:res)
2930
call matchup#perf#toc('ts_engine.get_delim', 'fail')
3031
return {}

lua/treesitter-matchup/internal.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,18 @@ local get_lang_matches = function(bufnr, root, lang, srow, erow)
7171
return {}
7272
end
7373

74+
local last_time = vim.uv.hrtime()
75+
local check_interrupt = function()
76+
if vim.uv.hrtime() - last_time > 100e6 then
77+
local got_int = select(2, vim.wait(1)) == -2
78+
if got_int then error('Interrupted') end
79+
last_time = vim.uv.hrtime()
80+
end
81+
end
82+
7483
local out = {} ---@type matchup.treesitter.Match[]
7584
for _, match, metadata in query:iter_matches(root, bufnr, srow, erow) do
85+
check_interrupt()
7686
for id, nodes in pairs(match) do
7787
local first = nodes[1]
7888
local last = nodes[#nodes]

0 commit comments

Comments
 (0)