From cc663ee53b93ee7b7cf9d6e390f81118c3e0bb6c Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 24 Jul 2021 20:39:45 +0200 Subject: [PATCH] Improvements for TSHighlightCapturesUnderCursor - show priority - show both syntax and tree-sitter if both are enabled --- lua/nvim-treesitter-playground/hl-info.lua | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/lua/nvim-treesitter-playground/hl-info.lua b/lua/nvim-treesitter-playground/hl-info.lua index acbf78c..7946396 100644 --- a/lua/nvim-treesitter-playground/hl-info.lua +++ b/lua/nvim-treesitter-playground/hl-info.lua @@ -38,7 +38,7 @@ function M.get_treesitter_hl() local iter = query:query():iter_captures(root, self.bufnr, row, row + 1) - for capture, node in iter do + for capture, node, metadata in iter do local hl = query.hl_cache[capture] if hl and ts_utils.is_in_node_range(node, row, col) then @@ -49,6 +49,9 @@ function M.get_treesitter_hl() if general_hl ~= hl then line = line .. " -> **" .. general_hl .. "**" end + if metadata.priority then + line = line .. " *(priority " .. metadata.priority .. ")*" + end table.insert(matches, line) end end @@ -73,21 +76,29 @@ end function M.show_hl_captures() local buf = vim.api.nvim_get_current_buf() local lines = {} - local matches + + local function show_matches(matches) + if #matches == 0 then + table.insert(lines, "* No highlight groups found") + end + for _, line in ipairs(matches) do + table.insert(lines, line) + end + table.insert(lines, "") + end + if highlighter.active[buf] then table.insert(lines, "# Treesitter") - matches = M.get_treesitter_hl() - else - table.insert(lines, "# Syntax") - matches = M.get_syntax_hl() - end - if #matches == 0 then - table.insert(lines, "* No highlight groups found") + local matches = M.get_treesitter_hl() + show_matches(matches) end - table.insert(lines, "") - for _, line in ipairs(matches) do - table.insert(lines, line) + + if vim.b.current_syntax then + table.insert(lines, "# Syntax") + local matches = M.get_syntax_hl() + show_matches(matches) end + vim.lsp.util.open_floating_preview(lines, "markdown", { border = "single", pad_left = 4, pad_right = 4 }) end