Skip to content

Commit

Permalink
Add ancestor related helper to nodes
Browse files Browse the repository at this point in the history
This is goign to be important when it comes to correctly identifying the
current node, which is a Big Problem. This has an impact on both
highlighting and on node swapping.
  • Loading branch information
aaronik committed Dec 15, 2024
1 parent 39ccff6 commit f54d28b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lua/treewalker/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ function M.get_descendants(node)
return descendants
end

---@param node TSNode
---@return TSNode
function M.get_farthest_ancestor_with_same_srow(node)
local node_row = node:range()
local farthest_ancestor = node
local iter_row = node:range()
local iter = node:parent()


while iter do
iter_row = iter:range()
if iter_row ~= node_row then
break
end
farthest_ancestor = iter
iter = iter:parent()
end

return farthest_ancestor
end

--- Take a list of nodes and unique them based on line start
---@param nodes TSNode[]
---@return TSNode[]
Expand Down

0 comments on commit f54d28b

Please sign in to comment.