diff --git a/lua/gitlab/actions/discussions/winbar.lua b/lua/gitlab/actions/discussions/winbar.lua index 09fb9934..d97c17d5 100644 --- a/lua/gitlab/actions/discussions/winbar.lua +++ b/lua/gitlab/actions/discussions/winbar.lua @@ -49,9 +49,16 @@ local function content() local resolvable_notes, resolved_notes = get_data(state.DISCUSSION_DATA.unlinked_discussions) local draft_notes = require("gitlab.actions.draft_notes") - local inline_draft_notes = List.new(state.DRAFT_NOTES):filter(draft_notes.has_position) - local unlinked_draft_notes = List.new(state.DRAFT_NOTES):filter(function(note) - return not draft_notes.has_position(note) + local inline_draft_notes, unlinked_draft_notes = List.new(state.DRAFT_NOTES):partition(function(note) + if note.discussion_id == "" then + return draft_notes.has_position(note) + end + for _, discussion in ipairs(state.DISCUSSION_DATA.unlinked_discussions) do + if discussion.id == note.discussion_id then + return false + end + end + return true end) local t = { diff --git a/lua/gitlab/utils/list.lua b/lua/gitlab/utils/list.lua index ea54b90c..775522ff 100644 --- a/lua/gitlab/utils/list.lua +++ b/lua/gitlab/utils/list.lua @@ -33,6 +33,23 @@ function List:filter(func) return result end +---Partitions a given list into two lists +---@generic T +---@param func fun(v: T, i: integer):boolean +---@return List, List @Returns two lists: the 1st with elements for which func returns true, the 2nd with elements for which it returns false +function List:partition(func) + local result_true = List.new() + local result_false = List.new() + for i, v in ipairs(self) do + if func(v, i) == true then + table.insert(result_true, v) + else + table.insert(result_false, v) + end + end + return result_true, result_false +end + function List:reduce(func, agg) for i, v in ipairs(self) do agg = func(agg, v, i)