Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 17c4a93

Browse files
committed
Add option to highlight the whole line
1 parent e72f8b7 commit 17c4a93

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lua/nvim-treesitter-refactor.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function M.init()
1717
enable = false,
1818
disable = {},
1919
is_supported = queries.has_locals,
20+
highlight_eol = false,
2021
},
2122
smart_rename = {
2223
module_path = "nvim-treesitter-refactor.smart_rename",

lua/nvim-treesitter-refactor/highlight_current_scope.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- This module highlights the current scope of at the cursor position
22

3+
local configs = require "nvim-treesitter.configs"
34
local ts_utils = require "nvim-treesitter.ts_utils"
45
local locals = require "nvim-treesitter.locals"
56
local 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
2537
end

0 commit comments

Comments
 (0)