mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 11:50:09 -04:00
Add ts_utils.highlight_node
This commit is contained in:
parent
a027ffbe82
commit
8dfe085c41
2 changed files with 14 additions and 20 deletions
|
|
@ -24,29 +24,13 @@ function M.highlight_usages(bufnr)
|
||||||
local usages = ts_utils.find_usages(node_at_point, scope)
|
local usages = ts_utils.find_usages(node_at_point, scope)
|
||||||
|
|
||||||
for _, usage_node in ipairs(usages) do
|
for _, usage_node in ipairs(usages) do
|
||||||
local start_row, start_col, _, end_col = usage_node:range()
|
|
||||||
|
|
||||||
if usage_node ~= node_at_point then
|
if usage_node ~= node_at_point then
|
||||||
api.nvim_buf_add_highlight(
|
ts_utils.highlight_node(node_at_point, bufnr, usage_namespace, 'TSDefinitionUsage')
|
||||||
bufnr,
|
|
||||||
usage_namespace,
|
|
||||||
'TSDefinitionUsage',
|
|
||||||
start_row,
|
|
||||||
start_col,
|
|
||||||
end_col)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if def_node ~= node_at_point then
|
if def_node ~= node_at_point then
|
||||||
local start_row, start_col, _, end_col = def_node:range()
|
ts_utils.highlight_node(def_node, bufnr, usage_namespace, 'TSDefinition')
|
||||||
|
|
||||||
api.nvim_buf_add_highlight(
|
|
||||||
bufnr,
|
|
||||||
usage_namespace,
|
|
||||||
'TSDefinition',
|
|
||||||
start_row,
|
|
||||||
start_col,
|
|
||||||
end_col)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,8 @@ function M.parent_scope(node, cursor_pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.containing_scope(node)
|
function M.containing_scope(node, bufnr)
|
||||||
local bufnr = api.nvim_get_current_buf()
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
|
||||||
local scopes = locals.get_scopes(bufnr)
|
local scopes = locals.get_scopes(bufnr)
|
||||||
if not node or not scopes then return end
|
if not node or not scopes then return end
|
||||||
|
|
@ -313,4 +313,14 @@ function M.find_usages(node, scope_node, bufnr)
|
||||||
return usages
|
return usages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.highlight_node(node, buf, hl_namespace, hl_group)
|
||||||
|
if not node then return end
|
||||||
|
M.highlight_range({node:range()}, buf, hl_namespace, hl_group)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.highlight_range(range, buf, hl_namespace, hl_group)
|
||||||
|
local start_row, start_col, end_row, end_col = unpack(range)
|
||||||
|
vim.highlight.range(buf, hl_namespace, hl_group, {start_row, start_col}, {end_row, end_col})
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue