11-- This module highlights the current scope of at the cursor position
22
3+ local configs = require " nvim-treesitter.configs"
34local ts_utils = require " nvim-treesitter.ts_utils"
45local locals = require " nvim-treesitter.locals"
56local api = vim .api
@@ -16,10 +17,21 @@ function M.highlight_current_scope(bufnr)
1617 local current_scope = locals .containing_scope (node_at_point , bufnr )
1718
1819 if current_scope then
20+ -- Highlight range [start_line, end_line) 0-based
21+ local highlighter = function (start_line , end_line )
22+ local config = configs .get_module " refactor.highlight_current_scope"
23+ vim .api .nvim_buf_set_extmark (bufnr , current_scope_namespace , math.max (vim .fn .line (" w0" ) - 1 , start_line ), 0 , {
24+ end_row = math.min (vim .fn .line (" w$" ), end_line ),
25+ end_col = 0 ,
26+ hl_group = " TSCurrentScope" ,
27+ hl_eol = config .highlight_eol ,
28+ })
29+ end
1930 local start_line , _ , end_line , _ = current_scope :range ()
2031
2132 if start_line ~= 0 or end_line ~= vim .fn .line (" $" ) then
22- ts_utils .highlight_node (current_scope , bufnr , current_scope_namespace , " TSCurrentScope" )
33+ highlighter (start_line , vim .fn .line (" ." ) - 1 )
34+ highlighter (vim .fn .line (" ." ), end_line + 1 )
2335 end
2436 end
2537end
0 commit comments