From 56315ffa77653fb5dfbece55e5e2aa98dec9c65f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20F=2E=20Bortl=C3=ADk?= Date: Sat, 11 Jul 2026 14:38:11 +0200 Subject: [PATCH 1/3] fix: set diffview hook for added files The hook for setting up keymaps and autocommands didn't fire correctly if the first file in the review was a new file, so it was diffed against diffview://null, which caused some autocommands to not fire appropriately or some state (reviewer.tabid) not to be set correctly. --- lua/gitlab/actions/discussions/init.lua | 1 + lua/gitlab/reviewer/init.lua | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/gitlab/actions/discussions/init.lua b/lua/gitlab/actions/discussions/init.lua index 98cbfde5..51a5c7e5 100644 --- a/lua/gitlab/actions/discussions/init.lua +++ b/lua/gitlab/actions/discussions/init.lua @@ -90,6 +90,7 @@ M.initialize_discussions = function() end) reviewer.set_callback_for_buf_read(function(args) vim.api.nvim_set_option_value("modifiable", false, { buf = args.buf }) + reviewer.update_winid_for_buffer(args.buf) reviewer.set_keymaps(args.buf) reviewer.set_reviewer_autocommands(args.buf) end) diff --git a/lua/gitlab/reviewer/init.lua b/lua/gitlab/reviewer/init.lua index 28d85f5c..3b276a38 100644 --- a/lua/gitlab/reviewer/init.lua +++ b/lua/gitlab/reviewer/init.lua @@ -59,9 +59,9 @@ M.open = function() end end + M.is_open = true vim.api.nvim_command(string.format("%s %s..%s", diffview_open_command, diff_refs.base_sha, diff_refs.head_sha)) - M.is_open = true M.diffview = require("diffview.lib").get_current_view() if M.diffview == nil then u.notify("Could not find Diffview view", vim.log.levels.ERROR) @@ -304,7 +304,11 @@ M.set_callback_for_buf_read = function(callback) pattern = { "DiffviewDiffBufRead" }, group = group, callback = function(...) - if vim.api.nvim_get_current_tabpage() == M.tabid then + -- Only run the callback when we're in the MR's tabpage or when the tabpage has + -- not yet been set (tabid = nil) in a freshly started review (is_open = true). + -- TODO: This is a hacky workaround for cases when an added file is diffeed + -- against diffview://null and this autocommand fires before tabid is set. + if vim.api.nvim_get_current_tabpage() == M.tabid or (M.is_open and M.tabid == nil) then callback(...) end end, From 7ada637b7825503f58d043377280434cb21bbc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20F=2E=20Bortl=C3=ADk?= Date: Mon, 13 Jul 2026 10:17:21 +0200 Subject: [PATCH 2/3] perf: remove unnecessary diagnostics refresh --- lua/gitlab/actions/discussions/init.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/gitlab/actions/discussions/init.lua b/lua/gitlab/actions/discussions/init.lua index 51a5c7e5..cfed643f 100644 --- a/lua/gitlab/actions/discussions/init.lua +++ b/lua/gitlab/actions/discussions/init.lua @@ -177,10 +177,6 @@ M.open = function(callback, view_type) if type(callback) == "function" then callback() end - - vim.schedule(function() - M.refresh_diagnostics() - end) end -- Clears the discussion state and unmounts the split From 86017a39bb1a715828005cea4508ef94b9d36620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20F=2E=20Bortl=C3=ADk?= Date: Mon, 13 Jul 2026 10:17:36 +0200 Subject: [PATCH 3/3] fix: add nil guard --- lua/gitlab/indicators/diagnostics.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gitlab/indicators/diagnostics.lua b/lua/gitlab/indicators/diagnostics.lua index 44abec68..91f7a01b 100644 --- a/lua/gitlab/indicators/diagnostics.lua +++ b/lua/gitlab/indicators/diagnostics.lua @@ -113,7 +113,7 @@ end ---Filter and place the diagnostics for the given buffer. ---@param bufnr number The number of the buffer for placing diagnostics. M.place_diagnostics = function(bufnr) - if not vim.api.nvim_buf_is_valid(bufnr) then + if not bufnr or not vim.api.nvim_buf_is_valid(bufnr) then return end if not state.settings.discussion_signs.enabled then