Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/gitlab.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ you call this function with no values the defaults will be used:
collapsed = " ", -- Icon for collapsed discussion thread
indentation = " ", -- Indentation Icon
},
spinner_chars = { "/", "|", "\\", "-" }, -- Characters for the refresh animation
auto_open = true, -- Automatically open when the reviewer is opened
default_view = "discussions" -- Show "discussions" or "notes" by default
blacklist = {}, -- List of usernames to remove from tree (bots, CI, etc)
Expand Down
16 changes: 8 additions & 8 deletions lua/gitlab/actions/discussions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ M.rebuild_view = function(unlinked, all)
else
M.rebuild_discussion_tree()
end
M.refresh_diagnostics_and_winbar()
state.discussion_tree.last_updated = os.time()
M.refresh_diagnostics()
end)
end

---Makes API call to get the discussion data, stores it in the state, and calls the callback
---@param callback function|nil
M.load_discussions = function(callback)
state.discussion_tree.last_updated = nil
state.load_new_state("discussion_data", function(data)
if not state.DISCUSSION_DATA then
state.DISCUSSION_DATA = {}
Expand All @@ -70,9 +72,10 @@ end

---Initialize everything for discussions like setup of signs, callbacks for reviewer, etc.
M.initialize_discussions = function()
state.discussion_tree.last_updated = os.time()
signs.setup_signs()
reviewer.set_callback_for_file_changed(function()
M.refresh_diagnostics_and_winbar()
M.refresh_diagnostics()
M.modifiable(false)
reviewer.set_reviewer_keymaps()
end)
Expand Down Expand Up @@ -102,11 +105,10 @@ M.modifiable = function(bool)
end

--- Take existing data and refresh the diagnostics, the winbar, and the signs
M.refresh_diagnostics_and_winbar = function()
M.refresh_diagnostics = function()
if state.settings.discussion_signs.enabled then
diagnostics.refresh_diagnostics()
end
winbar.update_winbar()
common.add_empty_titles()
end

Expand Down Expand Up @@ -154,7 +156,7 @@ M.open = function(callback)
end

vim.schedule(function()
M.refresh_diagnostics_and_winbar()
M.refresh_diagnostics()
end)
end

Expand Down Expand Up @@ -585,7 +587,7 @@ M.set_tree_keymaps = function(tree, bufnr, unlinked)
if keymaps.discussion_tree.jump_to_reviewer then
vim.keymap.set("n", keymaps.discussion_tree.jump_to_reviewer, function()
if M.is_current_node_note(tree) then
common.jump_to_reviewer(tree, M.refresh_diagnostics_and_winbar)
common.jump_to_reviewer(tree, M.refresh_diagnostics)
end
end, { buffer = bufnr, desc = "Jump to reviewer", nowait = keymaps.discussion_tree.jump_to_reviewer_nowait })
end
Expand All @@ -603,7 +605,6 @@ M.set_tree_keymaps = function(tree, bufnr, unlinked)

if keymaps.discussion_tree.refresh_data then
vim.keymap.set("n", keymaps.discussion_tree.refresh_data, function()
u.notify("Refreshing data...", vim.log.levels.INFO)
draft_notes.rebuild_view(unlinked, false)
end, {
buffer = bufnr,
Expand Down Expand Up @@ -802,7 +803,6 @@ end
---Toggle between draft mode (comments posted as drafts) and live mode (comments are posted immediately)
M.toggle_draft_mode = function()
state.settings.discussion_tree.draft_mode = not state.settings.discussion_tree.draft_mode
winbar.update_winbar()
end

---Toggle between sorting by "original comment" (oldest at the top) or "latest reply" (newest at the
Expand Down
24 changes: 22 additions & 2 deletions lua/gitlab/actions/discussions/winbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@ local get_data = function(nodes)
return total_resolvable, total_resolved, total_non_resolvable
end

local spinner_index = 0
state.discussion_tree.last_updated = nil

local function content()
local updated
if state.discussion_tree.last_updated then
local last_update = tostring(os.date("!%Y-%m-%dT%H:%M:%S", state.discussion_tree.last_updated))
updated = "Updated: " .. u.time_since(last_update)
else
spinner_index = (spinner_index % #state.settings.discussion_tree.spinner_chars) + 1
updated = "Updated: " .. state.settings.discussion_tree.spinner_chars[spinner_index]
end

local resolvable_discussions, resolved_discussions, non_resolvable_discussions =
get_data(state.DISCUSSION_DATA.discussions)
local resolvable_notes, resolved_notes, non_resolvable_notes = get_data(state.DISCUSSION_DATA.unlinked_discussions)
Expand Down Expand Up @@ -82,9 +94,10 @@ local function content()
resolved_notes = resolved_notes,
non_resolvable_notes = non_resolvable_notes,
help_keymap = state.settings.keymaps.help,
updated = updated,
}

return M.make_winbar(t)
return state.settings.discussion_tree.winbar and state.settings.discussion_tree.winbar(t) or M.make_winbar(t)
end

---This function updates the winbar
Expand Down Expand Up @@ -175,13 +188,16 @@ M.make_winbar = function(t)
-- Join everything together and return it
local separator = "%#Comment#|"
local end_section = "%="
local updated = "%#Text#" .. t.updated
local help = "%#Comment#Help: " .. (t.help_keymap and t.help_keymap:gsub(" ", "<space>") .. " " or "unmapped")
return string.format(
" %s %s %s %s %s %s %s %s %s",
" %s %s %s %s %s %s %s %s %s %s %s",
discussion_title,
separator,
notes_title,
end_section,
updated,
separator,
sort_method,
separator,
mode,
Expand Down Expand Up @@ -225,4 +241,8 @@ M.switch_view_type = function(override)
M.update_winbar()
end

-- Set up a timer to update the winbar periodically
local timer = vim.uv.new_timer()
timer:start(0, 100, vim.schedule_wrap(M.update_winbar))

return M
1 change: 1 addition & 0 deletions lua/gitlab/actions/draft_notes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
---Makes API call to get the discussion data, stores it in the state, and calls the callback
---@param callback function|nil
M.load_draft_notes = function(callback)
state.discussion_tree.last_updated = nil
state.load_new_state("draft_notes", function()
if callback ~= nil then
callback()
Expand Down
1 change: 1 addition & 0 deletions lua/gitlab/annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
---@field resolved_notes number
---@field non_resolvable_notes number
---@field help_keymap string
---@field updated string
---
---@class SignTable
---@field name string
Expand Down
1 change: 0 additions & 1 deletion lua/gitlab/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ return {
publish_all_drafts = draft_notes.publish_all_drafts,
refresh_data = function()
-- This also rebuilds the regular views
u.notify("Refreshing data...", vim.log.levels.INFO)
draft_notes.rebuild_view(false, true)
end,
-- Other functions 🤷
Expand Down
1 change: 1 addition & 0 deletions lua/gitlab/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ M.settings = {
collapsed = " ",
indentation = " ",
},
spinner_chars = { "-", "\\", "|", "/" },
auto_open = true,
default_view = "discussions",
blacklist = {},
Expand Down
2 changes: 1 addition & 1 deletion lua/gitlab/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ M.time_since = function(date_string, current_date_table)
local time_diff = current_date - date

if time_diff < 60 then
return M.pluralize(time_diff, "second") .. " ago"
return "just now"
elseif time_diff < 3600 then
return M.pluralize(math.floor(time_diff / 60), "minute") .. " ago"
elseif time_diff < 86400 then
Expand Down
Loading