Skip to content

Commit

Permalink
fix(tree): use format as node id for group without fields
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 30, 2024
1 parent fd9928e commit a29c293
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lua/trouble/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ function M:is_group()
end

---@param item trouble.Item
---@param fields string[]
function M.get_group_id(item, fields)
---@param group trouble.Group
function M.get_group_id(item, group)
local fields = group.fields
if #fields == 0 then
return group.format
end
local id = tostring(item[fields[1]])
if #fields > 1 then
for i = 2, #fields do
Expand All @@ -63,7 +67,7 @@ function M.build(items, section)
local node = root
for depth, group in ipairs(section.groups) do
-- id is based on the parent id and the group fields
local id = node.id .. "#" .. M.get_group_id(item, group.fields)
local id = node.id .. "#" .. M.get_group_id(item, group)
local child = node:get(id)
if not child then
child = M.new({ depth = depth, id = id, item = item })
Expand Down

0 comments on commit a29c293

Please sign in to comment.