Skip to content

Commit 839257a

Browse files
authored
Fix: Show non-resolvable notes in winbar (#417)
1 parent a03b2f6 commit 839257a

File tree

3 files changed

+66
-27
lines changed

3 files changed

+66
-27
lines changed

lua/gitlab/actions/discussions/winbar.lua

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local u = require("gitlab.utils")
12
local List = require("gitlab.utils.list")
23
local state = require("gitlab.state")
34

@@ -17,12 +18,13 @@ M.set_buffers = function(linked_bufnr, unlinked_bufnr)
1718
end
1819

1920
---@param nodes Discussion[]|UnlinkedDiscussion[]|nil
20-
---@return number, number
21+
---@return number, number, number
2122
local get_data = function(nodes)
2223
local total_resolvable = 0
2324
local total_resolved = 0
25+
local total_non_resolvable = 0
2426
if nodes == nil or nodes == vim.NIL then
25-
return total_resolvable, total_resolved
27+
return total_resolvable, total_resolved, total_non_resolvable
2628
end
2729

2830
total_resolvable = List.new(nodes):reduce(function(agg, d)
@@ -33,6 +35,14 @@ local get_data = function(nodes)
3335
return agg
3436
end, 0)
3537

38+
total_non_resolvable = List.new(nodes):reduce(function(agg, d)
39+
local first_child = d.notes[1]
40+
if first_child and not first_child.resolvable then
41+
agg = agg + 1
42+
end
43+
return agg
44+
end, 0)
45+
3646
total_resolved = List.new(nodes):reduce(function(agg, d)
3747
local first_child = d.notes[1]
3848
if first_child and first_child.resolved then
@@ -41,12 +51,13 @@ local get_data = function(nodes)
4151
return agg
4252
end, 0)
4353

44-
return total_resolvable, total_resolved
54+
return total_resolvable, total_resolved, total_non_resolvable
4555
end
4656

4757
local function content()
48-
local resolvable_discussions, resolved_discussions = get_data(state.DISCUSSION_DATA.discussions)
49-
local resolvable_notes, resolved_notes = get_data(state.DISCUSSION_DATA.unlinked_discussions)
58+
local resolvable_discussions, resolved_discussions, non_resolvable_discussions =
59+
get_data(state.DISCUSSION_DATA.discussions)
60+
local resolvable_notes, resolved_notes, non_resolvable_notes = get_data(state.DISCUSSION_DATA.unlinked_discussions)
5061

5162
local draft_notes = require("gitlab.actions.draft_notes")
5263
local inline_draft_notes, unlinked_draft_notes = List.new(state.DRAFT_NOTES):partition(function(note)
@@ -64,10 +75,12 @@ local function content()
6475
local t = {
6576
resolvable_discussions = resolvable_discussions,
6677
resolved_discussions = resolved_discussions,
78+
non_resolvable_discussions = non_resolvable_discussions,
6779
inline_draft_notes = #inline_draft_notes,
6880
unlinked_draft_notes = #unlinked_draft_notes,
6981
resolvable_notes = resolvable_notes,
7082
resolved_notes = resolved_notes,
83+
non_resolvable_notes = non_resolvable_notes,
7184
help_keymap = state.settings.keymaps.help,
7285
}
7386

@@ -94,34 +107,58 @@ M.update_winbar = function()
94107
vim.api.nvim_set_option_value("winbar", c, { scope = "local", win = win_id })
95108
end
96109

110+
local function get_connector(base_title)
111+
return string.match(base_title, "%($") and "" or "; "
112+
end
113+
97114
---Builds the title string for both sections, using the count of resolvable and draft nodes
98115
---@param base_title string
99116
---@param resolvable_count integer
100117
---@param resolved_count integer
101118
---@param drafts_count integer
102119
---@return string
103-
local add_drafts_and_resolvable = function(base_title, resolvable_count, resolved_count, drafts_count)
120+
local add_drafts_and_resolvable = function(
121+
base_title,
122+
resolvable_count,
123+
resolved_count,
124+
drafts_count,
125+
non_resolvable_count
126+
)
127+
if resolvable_count == 0 and drafts_count == 0 and non_resolvable_count == 0 then
128+
return base_title
129+
end
130+
base_title = base_title .. " ("
131+
if non_resolvable_count ~= 0 then
132+
base_title = base_title .. u.pluralize(non_resolvable_count, "comment")
133+
end
104134
if resolvable_count ~= 0 then
105-
base_title = base_title .. string.format(" (%d/%d resolved", resolvable_count, resolved_count)
135+
base_title = base_title
136+
.. get_connector(base_title)
137+
.. string.format("%d/%s", resolved_count, u.pluralize(resolvable_count, "thread"))
106138
end
107139
if drafts_count ~= 0 then
108-
if resolvable_count ~= 0 then
109-
base_title = base_title .. string.format("; %d drafts)", drafts_count)
110-
else
111-
base_title = base_title .. string.format(" (%d drafts)", drafts_count)
112-
end
113-
elseif resolvable_count ~= 0 then
114-
base_title = base_title .. ")"
140+
base_title = base_title .. get_connector(base_title) .. u.pluralize(drafts_count, "draft")
115141
end
116-
142+
base_title = base_title .. ")"
117143
return base_title
118144
end
119145

120146
---@param t WinbarTable
121147
M.make_winbar = function(t)
122-
local discussion_title =
123-
add_drafts_and_resolvable("Inline Comments", t.resolvable_discussions, t.resolved_discussions, t.inline_draft_notes)
124-
local notes_title = add_drafts_and_resolvable("Notes", t.resolvable_notes, t.resolved_notes, t.unlinked_draft_notes)
148+
local discussion_title = add_drafts_and_resolvable(
149+
"Inline Comments",
150+
t.resolvable_discussions,
151+
t.resolved_discussions,
152+
t.inline_draft_notes,
153+
t.non_resolvable_discussions
154+
)
155+
local notes_title = add_drafts_and_resolvable(
156+
"Notes",
157+
t.resolvable_notes,
158+
t.resolved_notes,
159+
t.unlinked_draft_notes,
160+
t.non_resolvable_notes
161+
)
125162

126163
-- Colorize the active tab
127164
if M.current_view_type == "discussions" then

lua/gitlab/annotations.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@
8585
---@field view_type string
8686
---@field resolvable_discussions number
8787
---@field resolved_discussions number
88+
---@field non_resolvable_discussions number
8889
---@field inline_draft_notes number
8990
---@field unlinked_draft_notes number
9091
---@field resolvable_notes number
9192
---@field resolved_notes number
93+
---@field non_resolvable_notes number
9294
---@field help_keymap string
9395
---
9496
---@class SignTable

lua/gitlab/utils/init.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ end
9898
---@param num integer The count of the item/word
9999
---@param word string The word to pluralize
100100
---@return string
101-
local function pluralize(num, word)
101+
M.pluralize = function(num, word)
102102
return num .. string.format(" %s", word) .. ((num > 1 or num <= 0) and "s" or "")
103103
end
104104

@@ -122,13 +122,13 @@ M.time_since = function(date_string, current_date_table)
122122
local time_diff = current_date - date
123123

124124
if time_diff < 60 then
125-
return pluralize(time_diff, "second") .. " ago"
125+
return M.pluralize(time_diff, "second") .. " ago"
126126
elseif time_diff < 3600 then
127-
return pluralize(math.floor(time_diff / 60), "minute") .. " ago"
127+
return M.pluralize(math.floor(time_diff / 60), "minute") .. " ago"
128128
elseif time_diff < 86400 then
129-
return pluralize(math.floor(time_diff / 3600), "hour") .. " ago"
129+
return M.pluralize(math.floor(time_diff / 3600), "hour") .. " ago"
130130
elseif time_diff < 2592000 then
131-
return pluralize(math.floor(time_diff / 86400), "day") .. " ago"
131+
return M.pluralize(math.floor(time_diff / 86400), "day") .. " ago"
132132
else
133133
local formatted_date = os.date("%B %e, %Y", date)
134134
return tostring(formatted_date)
@@ -457,13 +457,13 @@ M.format_date = function(date_string)
457457
local time_diff = current_date - date
458458

459459
if time_diff < 60 then
460-
return pluralize(time_diff, "second")
460+
return M.pluralize(time_diff, "second")
461461
elseif time_diff < 3600 then
462-
return pluralize(math.floor(time_diff / 60), "minute")
462+
return M.pluralize(math.floor(time_diff / 60), "minute")
463463
elseif time_diff < 86400 then
464-
return pluralize(math.floor(time_diff / 3600), "hour")
464+
return M.pluralize(math.floor(time_diff / 3600), "hour")
465465
elseif time_diff < 2592000 then
466-
return pluralize(math.floor(time_diff / 86400), "day")
466+
return M.pluralize(math.floor(time_diff / 86400), "day")
467467
else
468468
local formatted_date = os.date("%A, %B %e", date)
469469
return formatted_date

0 commit comments

Comments
 (0)