Skip to content

Commit

Permalink
Update TS hl-info from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
andymass committed Feb 18, 2022
1 parent d0c8f6f commit fce4ec1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions lua/treesitter-matchup/third-party/hl-info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,51 @@ function M.get_treesitter_hl(cursor)

local self = highlighter.active[buf]

if not self then return {} end
if not self then
return {}
end

local matches = {}

self.tree:for_each_tree(function(tstree, tree)
if not tstree then return end
if not tstree then
return
end

local root = tstree:root()
local root_start_row, _, root_end_row, _ = root:range()

-- Only worry about trees within the line range
if root_start_row > row or root_end_row < row then return end
if root_start_row > row or root_end_row < row then
return
end

local query = self:get_query(tree:lang())

-- Some injected languages may not have highlight queries.
if not query:query() then return end
if not query:query() then
return
end

local iter = query:query():iter_captures(root, self.bufnr, row, row + 1)

for capture, node in iter do
local hl = query.hl_cache[capture]

if hl and ts_utils.is_in_node_range(node, row, col) then
for capture, node, metadata in iter do
if ts_utils.is_in_node_range(node, row, col) then
local c = query._query.captures[capture] -- name of the capture in the query
if c ~= nil then
local general_hl = query:_get_hl_from_capture(capture)
local line = { c, hl }
if general_hl ~= hl then
local general_hl, is_vim_hl = query:_get_hl_from_capture(capture)
local local_hl = not is_vim_hl and (tree:lang() .. general_hl)
local line = { c }
if local_hl then
table.insert(line, local_hl)
end
if general_hl and general_hl ~= local_hl then
table.insert(line, general_hl)
end
table.insert(matches, line)
end
end
end

end, true)
return matches
end
Expand Down

0 comments on commit fce4ec1

Please sign in to comment.