aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2020-07-12 16:11:11 +0200
committerThomas Vigouroux <39092278+vigoux@users.noreply.github.com>2020-07-13 22:26:17 +0200
commit8dfe085c41954def22d75daeafae8017b9b6a667 (patch)
tree926da47d5f21dec30ca7a8fd75d8442db6140ab7 /lua
parentAdd rust locals.scm (diff)
downloadnvim-treesitter-8dfe085c41954def22d75daeafae8017b9b6a667.tar
nvim-treesitter-8dfe085c41954def22d75daeafae8017b9b6a667.tar.gz
nvim-treesitter-8dfe085c41954def22d75daeafae8017b9b6a667.tar.bz2
nvim-treesitter-8dfe085c41954def22d75daeafae8017b9b6a667.tar.lz
nvim-treesitter-8dfe085c41954def22d75daeafae8017b9b6a667.tar.xz
nvim-treesitter-8dfe085c41954def22d75daeafae8017b9b6a667.tar.zst
nvim-treesitter-8dfe085c41954def22d75daeafae8017b9b6a667.zip
Add ts_utils.highlight_node
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/refactor/highlight_definitions.lua20
-rw-r--r--lua/nvim-treesitter/ts_utils.lua14
2 files changed, 14 insertions, 20 deletions
diff --git a/lua/nvim-treesitter/refactor/highlight_definitions.lua b/lua/nvim-treesitter/refactor/highlight_definitions.lua
index a581e37d5..3b75cd847 100644
--- a/lua/nvim-treesitter/refactor/highlight_definitions.lua
+++ b/lua/nvim-treesitter/refactor/highlight_definitions.lua
@@ -24,29 +24,13 @@ function M.highlight_usages(bufnr)
local usages = ts_utils.find_usages(node_at_point, scope)
for _, usage_node in ipairs(usages) do
- local start_row, start_col, _, end_col = usage_node:range()
-
if usage_node ~= node_at_point then
- api.nvim_buf_add_highlight(
- bufnr,
- usage_namespace,
- 'TSDefinitionUsage',
- start_row,
- start_col,
- end_col)
+ ts_utils.highlight_node(node_at_point, bufnr, usage_namespace, 'TSDefinitionUsage')
end
end
if def_node ~= node_at_point then
- local start_row, start_col, _, end_col = def_node:range()
-
- api.nvim_buf_add_highlight(
- bufnr,
- usage_namespace,
- 'TSDefinition',
- start_row,
- start_col,
- end_col)
+ ts_utils.highlight_node(def_node, bufnr, usage_namespace, 'TSDefinition')
end
end
diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua
index 463490f5e..39c75365d 100644
--- a/lua/nvim-treesitter/ts_utils.lua
+++ b/lua/nvim-treesitter/ts_utils.lua
@@ -124,8 +124,8 @@ function M.parent_scope(node, cursor_pos)
end
end
-function M.containing_scope(node)
- local bufnr = api.nvim_get_current_buf()
+function M.containing_scope(node, bufnr)
+ local bufnr = bufnr or api.nvim_get_current_buf()
local scopes = locals.get_scopes(bufnr)
if not node or not scopes then return end
@@ -313,4 +313,14 @@ function M.find_usages(node, scope_node, bufnr)
return usages
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