Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #50 from theHamsta/hl-info-improvements
Browse files Browse the repository at this point in the history
Improvements for TSHighlightCapturesUnderCursor
  • Loading branch information
theHamsta authored Jul 27, 2021
2 parents 2715d35 + cc663ee commit deb887b
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lua/nvim-treesitter-playground/hl-info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit deb887b

Please sign in to comment.