From e4eabaf71d9b98bbdc12c769477735837686b109 Mon Sep 17 00:00:00 2001 From: "Harrison (Harry) Cramer" <32515581+harrisoncramer@users.noreply.github.com> Date: Sat, 24 Jan 2026 10:04:47 -0500 Subject: [PATCH] Release 1/24/26 (#519) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Jumping to renamed files (#484) * fix: prevent "cursor position outside buffer" error * fix: swap file_name and old_file_name in reviewer data `old_file_name` is not set to the empty string for un-renamed files anymore, because then we can remove the empty-line check in `comment_helpers.go` which was used to replace the empty string with the current file name anyway. * fix: add old_file_name to discussion root node data * fix: also consider old_file_name when jumping to the reviewer This fixes jumping to renamed files, however, may not work for comments that were created on renamed files with the previous version of `gitlab.nvim` as that version assigned the `file_name` and `old_file_name` incorrectly. * refactor: don't shadow variable * fix: check file_name or old_file_name based on which SHA comment belongs to * Fix: Store reviewer data before creating comment popup (#476) * Fix: Make publishing drafts more robust (#483) * Fix: Swap file_name and old_file_name in reviewer data (#485) * Feat: Enable toggling date format between relative and absolute (#491) * Fix: Add opts to help popup (#492) * Fix: Force start_line for jumping to diagnostic to be inside buffer (#494) * fix: redefine colors after reloading colorscheme (#500) * Fix: Use path instead of oldpath as fallback for unrenamed files (#496) * Fix: Use file_name when old_file_name is not set (#495) * fix(ci): fix lua tests (#501) * Proxy Support (#499) * feat(ci): Cancel obsolete after a new commit is pushed in an open PR (#503) * fix: start and clean up winbar timer properly (#513) This is a PATCH. * fix: put attach_file markdown on new line (#512) This is a PATCH PR. * docs: fix incorrect value for 'relative' option to Split (#511) This is a PATCH. * docs: add default keybinding maps available in the help (#506) This is a PATCH change. * feat: enable setting discussion tree options (#509) * docs: add description of `refresh_data` function * fix: only set gitlab filetype in one place * feat: set some useful window options for the discussion tree split This is a PATCH PR. --------- Co-authored-by: Jakub F. Bortlík Co-authored-by: Jonathan Duck Co-authored-by: Kitsios Konstantinos Co-authored-by: Mohammad Akbari --- .github/workflows/go.yaml | 5 ++ README.md | 81 +++++++++++++++++++++++ doc/gitlab.nvim.txt | 29 +++++++- lua/gitlab/actions/common.lua | 1 - lua/gitlab/actions/discussions/init.lua | 10 ++- lua/gitlab/actions/discussions/winbar.lua | 19 +++++- lua/gitlab/actions/miscellaneous.lua | 4 +- lua/gitlab/reviewer/init.lua | 1 + lua/gitlab/state.lua | 6 ++ 9 files changed, 145 insertions(+), 11 deletions(-) diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 73f5ad1..5d16155 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -8,6 +8,11 @@ on: - 'cmd/**' # Ignore changes to the Lua code - 'go.sum' - 'go.mod' + +concurrency: + group: pr-${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + jobs: go_lint: name: Lint Go 💅 diff --git a/README.md b/README.md index 1b6841a..b0567b1 100644 --- a/README.md +++ b/README.md @@ -122,3 +122,84 @@ For a list of all these settings please run `:h gitlab.nvim.configuring-the-plug The plugin sets up a number of useful keybindings in the special buffers it creates, and some global keybindings as well. Refer to the relevant section of the manual `:h gitlab.nvim.keybindings` for more details. For more information about each of these commands, and about the APIs in general, run `:h gitlab.nvim.api` + +`gitlab.nvim` comes with a set of default `keymaps` for different contexts. You can override any of these in your configuration. + +### Global Keymaps + +These keymaps are available globally (i.e., in any buffer). + +``` +g? Open a help popup for local keymaps +glaa Add assignee +glad Delete assignee +glla Add label +glld Delete label +glra Add reviewer +glrd Delete reviewer +glA Approve MR +glR Revoke MR approval +glM Merge the feature branch to the target branch and close MR +glC Create a new MR for currently checked-out feature branch +glc Chose MR for review +glS Start review for the currently checked-out branch +gls Show the editable summary of the MR +glu Copy the URL of the MR to the system clipboard +glo Open the URL of the MR in the default Internet browser +gln Create a note (comment not linked to a specific line) +glp Show the pipeline status +gld Toggle the discussions window +glD Toggle between draft mode and live mode +glP Publish all draft comments/notes +``` + +#### Popup Keymaps + +These `keymaps` are active in the popup windows (e.g., for creating comments, editing the summary, etc.). + +``` + Cycle to the next field + Cycle to the previous field +ZZ Perform action (e.g., save comment) +ZA Perform linewise action +ZQ Discard changes and quit the popup +``` + +#### Discussion Tree Keymaps + +These `keymaps` are active in the discussion tree window. + +``` +Ea Add an emoji to the note/comment +Ed Remove an emoji from a note/comment +dd Delete comment +e Edit comment +r Reply to comment +- Toggle the resolved status of the whole discussion +o Jump to comment location in file +a Jump to the comment location in the reviewer window +b Jump to the URL of the current note/discussion +u Copy the URL of the current node to clipboard +c Toggle between the notes and discussions views +i Toggle type of discussion tree +P Publish the currently focused note/comment +dt Toggle between date formats +D Toggle between draft mode and live mode +st Toggle whether discussions are sorted by the "latest_reply", or by "original_comment" +t Open or close the discussion +T Open or close separately both resolved and unresolved discussions +R Open or close all resolved discussions +U Open or close all unresolved discussions + Refresh the data in the view +p Print the current node (for debugging) +``` + +#### Reviewer Keymaps + +These `keymaps` are active in the reviewer window (the diff view). + +``` +c Create a comment for the lines that the following {motion} moves over +s Create a suggestion for the lines that the following {motion} moves over +a Jump to the comment in the discussion tree +``` diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index 19ae720..212a920 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -262,7 +262,7 @@ you call this function with no values the defaults will be used: keep_current_open = false, -- If true, current discussion stays open even if it should otherwise be closed when toggling position = "bottom", -- "top", "right", "bottom" or "left" size = "20%", -- Size of split - relative = "editor", -- Position of tree split relative to "editor" or "window" + relative = "editor", -- Position of tree split relative to "editor" or "win" (window) resolved = '✓', -- Symbol to show next to resolved discussions unresolved = '-', -- Symbol to show next to unresolved discussions unlinked = "󰌸", -- Symbol to show next to unliked comments (i.e., not threads) @@ -270,6 +270,12 @@ you call this function with no values the defaults will be used: tree_type = "simple", -- Type of discussion tree - "simple" means just list of discussions, "by_file_name" means file tree with discussions under file draft_mode = false, -- Whether comments are posted as drafts as part of a review relative_date = true, -- Whether to show relative time like "5 days ago" or absolute time like "03/01/2025 at 01:43" + winopts = { -- Window-local options for the discussion tree split + number = false, + relativenumber = false, + breakindent = true, -- Every wrapped line will continue visually indented + showbreak = "+ ", -- String to put at the start of lines that have been wrapped + } winbar = nil, -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua) -- If using lualine, please add "gitlab" to disabled file types, otherwise you will not see the winbar. }, @@ -1078,4 +1084,25 @@ execute and passed the data as an argument. with each resource as a key-value pair, with the key being it's type. + *gitlab.nvim.data* +gitlab.refresh_data() ~ + +Fetches discussion tree data from Gitlab and refreshes the tree views. It can +be used in an autocommand to refresh the data every time you enter the +discussion tree. This exmaple shows how to easily limit the refresh rate to at +least 10 seconds: +>lua + local last_updated = os.time() + local gitlab = vim.api.nvim_create_augroup("Gitlab", {}) + vim.api.nvim_create_autocmd("BufEnter", { + group = gitlab, + callback = function() + if vim.bo.filetype == "gitlab" and os.time() - last_updated > 10 then + require("gitlab").refresh_data() + last_updated = os.time() + end + end + }) +< + vim:tw=78:ts=4:sw=4:expandtab:ft=help:norl: diff --git a/lua/gitlab/actions/common.lua b/lua/gitlab/actions/common.lua index 538d498..30140c7 100644 --- a/lua/gitlab/actions/common.lua +++ b/lua/gitlab/actions/common.lua @@ -25,7 +25,6 @@ M.switch_can_edit_bufs = function(bool, ...) ---@param v integer for _, v in ipairs(bufnrs) do u.switch_can_edit_buf(v, bool) - vim.api.nvim_set_option_value("filetype", "gitlab", { buf = v }) end end diff --git a/lua/gitlab/actions/discussions/init.lua b/lua/gitlab/actions/discussions/init.lua index c22fa76..dc0526e 100644 --- a/lua/gitlab/actions/discussions/init.lua +++ b/lua/gitlab/actions/discussions/init.lua @@ -115,15 +115,19 @@ M.open = function(callback, view_type) M.linked_bufnr = linked_bufnr M.unlinked_bufnr = unlinked_bufnr - vim.api.nvim_set_option_value("filetype", "gitlab", { buf = M.split.bufnr }) - vim.api.nvim_set_option_value("filetype", "gitlab", { buf = M.unlinked_bufnr }) + for opt, val in pairs(state.settings.discussion_tree.winopts) do + vim.api.nvim_set_option_value(opt, val, { win = M.split.winid }) + end + vim.api.nvim_set_option_value("filetype", "gitlab", { buf = M.linked_bufnr }) + vim.api.nvim_set_option_value("filetype", "gitlab", { buf = M.unlinked_bufnr }) M.split = split M.split_visible = true split:mount() -- Initialize winbar module with data from buffers + winbar.start_timer() winbar.set_buffers(M.linked_bufnr, M.unlinked_bufnr) winbar.switch_view_type(view_type) @@ -156,6 +160,7 @@ M.close = function() end M.split_visible = false M.discussion_tree = nil + winbar.cleanup_timer() end ---Move to the discussion tree at the discussion from diagnostic on current line. @@ -455,7 +460,6 @@ M.rebuild_discussion_tree = function() M.set_tree_keymaps(discussion_tree, M.linked_bufnr, false) M.discussion_tree = discussion_tree common.switch_can_edit_bufs(false, M.linked_bufnr, M.unlinked_bufnr) - vim.api.nvim_set_option_value("filetype", "gitlab", { buf = M.linked_bufnr }) state.discussion_tree.resolved_expanded = false state.discussion_tree.unresolved_expanded = false end diff --git a/lua/gitlab/actions/discussions/winbar.lua b/lua/gitlab/actions/discussions/winbar.lua index 7b1dc25..719c48f 100644 --- a/lua/gitlab/actions/discussions/winbar.lua +++ b/lua/gitlab/actions/discussions/winbar.lua @@ -271,8 +271,21 @@ 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)) +---Set up a timer to update the winbar periodically +M.start_timer = function() + M.cleanup_timer() + ---@type nil|uv_timer_t + M.timer = vim.uv.new_timer() + M.timer:start(0, 100, vim.schedule_wrap(M.update_winbar)) +end + +--Stop and close the timer +M.cleanup_timer = function() + if M.timer ~= nil then + M.timer:stop() + M.timer:close() + M.timer = nil + end +end return M diff --git a/lua/gitlab/actions/miscellaneous.lua b/lua/gitlab/actions/miscellaneous.lua index 368c198..1b0c555 100644 --- a/lua/gitlab/actions/miscellaneous.lua +++ b/lua/gitlab/actions/miscellaneous.lua @@ -27,9 +27,7 @@ M.attach_file = function() local body = { file_path = full_path, file_name = choice } job.run_job("/attachment", "POST", body, function(data) local markdown = data.markdown - local current_line = u.get_current_line_number() - local bufnr = vim.api.nvim_get_current_buf() - vim.api.nvim_buf_set_lines(bufnr, current_line - 1, current_line, false, { markdown }) + vim.api.nvim_put({ markdown }, "l", true, false) end) end) end diff --git a/lua/gitlab/reviewer/init.lua b/lua/gitlab/reviewer/init.lua index 46a6034..76d24f3 100644 --- a/lua/gitlab/reviewer/init.lua +++ b/lua/gitlab/reviewer/init.lua @@ -78,6 +78,7 @@ M.open = function() local on_diffview_closed = function(view) if view.tabpage == M.tabnr then M.tabnr = nil + require("gitlab.actions.discussions.winbar").cleanup_timer() end end require("diffview.config").user_emitter:on("view_closed", function(_, args) diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index b7e2a46..d67e0c0 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -172,6 +172,12 @@ M.settings = { tree_type = "simple", draft_mode = false, relative_date = true, + winopts = { + number = false, + relativenumber = false, + breakindent = true, + showbreak = "+ ", + }, }, emojis = { formatter = nil,