mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-17 17:38:01 +00:00
feat!(treesitter): parse range around cursor based on g:matchup_treesitter_stopline
This commit is contained in:
@@ -82,6 +82,7 @@ function! s:init_options()
|
||||
call s:init_option('matchup_treesitter_include_match_words', v:false)
|
||||
call s:init_option('matchup_treesitter_enable_quotes', v:true)
|
||||
call s:init_option('matchup_treesitter_disable_virtual_text', v:true)
|
||||
call s:init_option('matchup_treesitter_stopline', 400)
|
||||
endfunction
|
||||
|
||||
function! s:init_option(option, default)
|
||||
|
||||
@@ -73,6 +73,7 @@ local M = {}
|
||||
---@field include_match_words boolean
|
||||
---@field disable_virtual_text boolean
|
||||
---@field enable_quotes boolean
|
||||
---@field stopline integer
|
||||
|
||||
---@class matchup.Config
|
||||
---@field delim matchup.DelimConfig
|
||||
|
||||
@@ -134,10 +134,15 @@ M.get_matches = function(bufnr)
|
||||
local matches = {} ---@type matchup.treesitter.Match[]
|
||||
|
||||
if parser then
|
||||
-- TODO: g:matchup_delim_stopline could be used, but this functions needs to
|
||||
-- know on which window it should look for in order to get the current
|
||||
-- cursor position of that window
|
||||
parser:parse(nil)
|
||||
-- NOTE: assummes that we are always parsing the current window. May cause
|
||||
-- issues if that's not always the case
|
||||
local win = api.nvim_get_current_win()
|
||||
local cur_row = unpack(api.nvim_win_get_cursor(win))
|
||||
local stopline = vim.g.matchup_treesitter_stopline ---@type integer
|
||||
local start_row = math.max(cur_row - stopline, 0)
|
||||
local end_row = math.min(cur_row + stopline, api.nvim_buf_line_count(bufnr))
|
||||
|
||||
parser:parse({start_row, end_row})
|
||||
parser:for_each_tree(function(tree, lang_tree)
|
||||
if not tree or lang_tree:lang() == 'comment' then
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user