From 8dfe085c41954def22d75daeafae8017b9b6a667 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 12 Jul 2020 16:11:11 +0200 Subject: Add ts_utils.highlight_node --- lua/nvim-treesitter/ts_utils.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lua/nvim-treesitter/ts_utils.lua') diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index 463490f5..39c75365 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 -- cgit v1.2.3