Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4ff27c2
fix: Fixes issues w/ shared pointers to structs (#378)
harrisoncramer Sep 16, 2024
87e224a
feat: adds even better debugging and linting support (#376)
harrisoncramer Sep 16, 2024
e17d713
fix: error messages and run all tests (#381)
gkze Sep 21, 2024
523bdd4
feat: Automatically open fold under cursor (#380)
jakubbortlik Sep 23, 2024
6ac8895
Merge branch 'main' into develop
harrisoncramer Sep 24, 2024
879ee20
fix: discussion ID is not required (#383)
harrisoncramer Sep 26, 2024
125cfbb
Chore: Add more emojis (#384)
jakubbortlik Oct 4, 2024
7171f4c
Fix: Publish all drafts (#391)
jakubbortlik Oct 10, 2024
0e19857
fix: make discussion tree buffers nomodifiable (#394)
jakubbortlik Oct 11, 2024
96efdc2
fix: Incorrect warning about commits (#395)
harrisoncramer Oct 12, 2024
b359b47
Fix: Show draft replies in the correct tree (#396)
jakubbortlik Oct 13, 2024
a63823c
fix: Cannot choose merge requests (#398)
harrisoncramer Oct 13, 2024
0f3841f
fix: parse dates without timezone offset (#404)
harrisoncramer Oct 14, 2024
04976db
Fix: Use correct name for emoji
jakubbortlik Oct 15, 2024
cd8a404
Merge pull request #405 from jakubbortlik/fix-party-emoji
jakubbortlik Oct 18, 2024
c8c0395
fix: enable replying if tree is in a different tab (#407)
jakubbortlik Oct 25, 2024
e4c9dbe
fix: wrong get url (#413)
OscarCreator Nov 5, 2024
5f657fd
Fix: Restore cursor when updating from outside of tree (#406)
jakubbortlik Nov 5, 2024
a03b2f6
Merge branch 'main' into develop
harrisoncramer Nov 5, 2024
839257a
Fix: Show non-resolvable notes in winbar (#417)
jakubbortlik Nov 5, 2024
a0d10a4
Fix: add more emojis and make emoji picker configurable (#414)
jakubbortlik Nov 6, 2024
c44daf5
fix: comment creation should not be possible for renamed and moved fi…
harrisoncramer Nov 10, 2024
b606ceb
fix: color highlight groups are invalid (#421)
harrisoncramer Nov 10, 2024
ddf0f41
fix: plugin failing to build on Windows (#419)
harrisoncramer Nov 12, 2024
d8d289d
Merge branch 'main' into develop
harrisoncramer Nov 12, 2024
15a3839
Feat: Enable sorting discussions by original comment (#422)
jakubbortlik Dec 6, 2024
08d289c
Feat: Improve popup UX (#426)
jakubbortlik Dec 6, 2024
a3aa79a
Feat: Automatically update MR summary details (#427)
jakubbortlik Dec 8, 2024
b2d64fa
Feat: Show update progress in winbar (#432)
jakubbortlik Dec 8, 2024
768dfaf
Feat: Abbreviate winbar (#439)
harrisoncramer Dec 8, 2024
621bfa6
Merge branch 'main' into develop
harrisoncramer Dec 8, 2024
606d931
Fix: Note Creation Bug (#441)
harrisoncramer Dec 8, 2024
508a394
Fix: Checking whether comment can be created (#434)
jakubbortlik Dec 8, 2024
3d76b8d
Fix: Syntax in discussion tree (#433)
jakubbortlik Dec 10, 2024
aebdaf4
fix: improve indication of resolved threads and drafts (#442)
jakubbortlik Dec 10, 2024
72f2155
Docs: Various minor improvements (#445)
jakubbortlik Dec 11, 2024
3b83880
Fix: Removes Retry, fixes mess of errors for #425 (#449)
harrisoncramer Dec 26, 2024
109703a
fix: manage buffer-local settings outside reviewer
jakubbortlik Dec 9, 2024
19e5855
fix: remove unused function
jakubbortlik Dec 9, 2024
962232a
fixup: docstring
jakubbortlik Dec 11, 2024
91f3b8e
fix: use correct window-IDs for reviewer buffers
jakubbortlik Dec 11, 2024
3bbd402
docs: unify function annotations
jakubbortlik Dec 11, 2024
e02e7a6
refactor: unify callback style
jakubbortlik Dec 11, 2024
fd2ae92
docs: fix typos
jakubbortlik Dec 11, 2024
03bb696
style: fix formatting
jakubbortlik Dec 12, 2024
70aca8c
Release: Docs Improvements and Bug Fixes (#460)
harrisoncramer Jan 18, 2025
b27b939
Merge branch 'develop' into fix-buffer-local-settings-outside-reviewer
jakubbortlik Jan 28, 2025
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
30 changes: 8 additions & 22 deletions lua/gitlab/actions/discussions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ local List = require("gitlab.utils.list")
local tree_utils = require("gitlab.actions.discussions.tree")
local discussions_tree = require("gitlab.actions.discussions.tree")
local draft_notes = require("gitlab.actions.draft_notes")
local diffview_lib = require("diffview.lib")
local signs = require("gitlab.indicators.signs")
local diagnostics = require("gitlab.indicators.diagnostics")
local winbar = require("gitlab.actions.discussions.winbar")
Expand Down Expand Up @@ -74,36 +73,23 @@ end
M.initialize_discussions = function()
state.discussion_tree.last_updated = os.time()
signs.setup_signs()
reviewer.set_callback_for_file_changed(function()
M.refresh_diagnostics()
M.modifiable(false)
reviewer.set_reviewer_keymaps()
reviewer.set_callback_for_file_changed(function(args)
reviewer.update_winid_for_buffer(args.buf)
end)
reviewer.set_callback_for_reviewer_enter(function()
M.modifiable(false)
M.refresh_diagnostics()
end)
reviewer.set_callback_for_buf_read(function(args)
vim.api.nvim_buf_set_option(args.buf, "modifiable", false)
reviewer.set_keymaps(args.buf)
reviewer.set_reviewer_autocommands(args.buf)
end)
reviewer.set_callback_for_reviewer_leave(function()
signs.clear_signs()
diagnostics.clear_diagnostics()
M.modifiable(true)
reviewer.del_reviewer_keymaps()
end)
end

--- Ensures that the both buffers in the reviewer are/not modifiable. Relevant if the user is using
--- the --imply-local setting
M.modifiable = function(bool)
local view = diffview_lib.get_current_view()
local a = view.cur_layout.a.file.bufnr
local b = view.cur_layout.b.file.bufnr
if a ~= nil and vim.api.nvim_buf_is_loaded(a) then
vim.api.nvim_buf_set_option(a, "modifiable", bool)
end
if b ~= nil and vim.api.nvim_buf_is_loaded(b) then
vim.api.nvim_buf_set_option(b, "modifiable", bool)
end
end

--- Take existing data and refresh the diagnostics, the winbar, and the signs
M.refresh_diagnostics = function()
if state.settings.discussion_signs.enabled then
Expand Down
120 changes: 75 additions & 45 deletions lua/gitlab/reviewer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local M = {
bufnr = nil,
tabnr = nil,
stored_win = nil,
buf_winids = {},
}

-- Checks for legacy installations, only Diffview is supported.
Expand Down Expand Up @@ -62,6 +63,8 @@ M.open = function()
vim.api.nvim_command(string.format("%s %s..%s", diffview_open_command, diff_refs.base_sha, diff_refs.head_sha))

M.is_open = true
local cur_view = diffview_lib.get_current_view()
M.diffview_layout = cur_view.cur_layout
M.tabnr = vim.api.nvim_get_current_tabpage()

if state.settings.discussion_diagnostic ~= nil or state.settings.discussion_sign ~= nil then
Expand All @@ -77,9 +80,11 @@ M.open = function()
M.tabnr = nil
end
end
require("diffview.config").user_emitter:on("view_closed", function(_, ...)
M.is_open = false
on_diffview_closed(...)
require("diffview.config").user_emitter:on("view_closed", function(_, args)
if M.tabnr == args.tabpage then
M.is_open = false
on_diffview_closed(args)
end
end)

if state.settings.discussion_tree.auto_open then
Expand Down Expand Up @@ -248,44 +253,63 @@ M.does_file_have_changes = function()
return file_data.stats.additions > 0 or file_data.stats.deletions > 0
end

---Diffview exposes events which can be used to setup autocommands.
---Run callback every time the buffer in one of the two reviewer windows changes.
---@param callback fun(opts: table) - for more information about opts see callback in :h nvim_create_autocmd
M.set_callback_for_file_changed = function(callback)
local group = vim.api.nvim_create_augroup("gitlab.diffview.autocommand.file_changed", {})
vim.api.nvim_create_autocmd("User", {
pattern = { "DiffviewDiffBufWinEnter" },
group = group,
callback = function(...)
M.stored_win = vim.api.nvim_get_current_win()
if M.tabnr == vim.api.nvim_get_current_tabpage() then
callback(...)
end
end,
})
end

---Diffview exposes events which can be used to setup autocommands.
---Run callback the first time a new diff buffer is created and loaded into a window.
---@param callback fun(opts: table) - for more information about opts see callback in :h nvim_create_autocmd
M.set_callback_for_buf_read = function(callback)
local group = vim.api.nvim_create_augroup("gitlab.diffview.autocommand.buf_read", {})
vim.api.nvim_create_autocmd("User", {
pattern = { "DiffviewDiffBufRead" },
group = group,
callback = function(...)
if vim.api.nvim_get_current_tabpage() == M.tabnr then
callback(...)
end
end,
})
end

---Run callback when the reviewer is closed or the user switches to another tab.
---@param callback fun(opts: table) - for more information about opts see callback in :h nvim_create_autocmd
M.set_callback_for_reviewer_leave = function(callback)
local group = vim.api.nvim_create_augroup("gitlab.diffview.autocommand.leave", {})
vim.api.nvim_create_autocmd("User", {
pattern = { "DiffviewViewLeave", "DiffviewViewClosed" },
group = group,
callback = function(...)
if M.tabnr == vim.api.nvim_get_current_tabpage() then
if vim.api.nvim_get_current_tabpage() == M.tabnr then
callback(...)
end
end,
})
end

---Run callback when the reviewer is opened for the first time or the view is entered from another
---tab page.
---@param callback fun(opts: table) - for more information about opts see callback in :h nvim_create_autocmd
M.set_callback_for_reviewer_enter = function(callback)
local group = vim.api.nvim_create_augroup("gitlab.diffview.autocommand.enter", {})
vim.api.nvim_create_autocmd("User", {
pattern = { "DiffviewViewOpened" },
pattern = { "DiffviewViewEnter", "DiffviewViewOpened" },
group = group,
callback = function(...)
callback(...)
if vim.api.nvim_get_current_tabpage() == M.tabnr then
callback(...)
end
end,
})
end
Expand Down Expand Up @@ -325,8 +349,16 @@ end

---Set keymaps for creating comments, suggestions and for jumping to discussion tree.
---@param bufnr integer Number of the buffer for which the keybindings will be created.
---@param keymaps table The settings keymaps table.
local set_keymaps = function(bufnr, keymaps)
M.set_keymaps = function(bufnr)
if bufnr == nil or not vim.api.nvim_buf_is_loaded(bufnr) then
return
end
-- Require keymaps only after user settings have been merged with defaults
local keymaps = require("gitlab.state").settings.keymaps
if keymaps.disable_all or keymaps.reviewer.disable_all then
return
end

-- Set mappings for creating comments
if keymaps.reviewer.create_comment ~= false then
-- Set keymap for repeated operator keybinding
Expand Down Expand Up @@ -399,29 +431,17 @@ local set_keymaps = function(bufnr, keymaps)
end
end

--- Sets up keymaps for both buffers in the reviewer.
M.set_reviewer_keymaps = function()
---Delete keymaps from reviewer buffers.
---@param bufnr integer Number of the buffer from which the keybindings will be removed.
local del_keymaps = function(bufnr)
if bufnr == nil or not vim.api.nvim_buf_is_loaded(bufnr) then
return
end
-- Require keymaps only after user settings have been merged with defaults
local keymaps = require("gitlab.state").settings.keymaps
if keymaps.disable_all or keymaps.reviewer.disable_all then
return
end

local view = diffview_lib.get_current_view()
local a = view.cur_layout.a.file.bufnr
local b = view.cur_layout.b.file.bufnr
if a ~= nil and vim.api.nvim_buf_is_loaded(a) then
set_keymaps(a, keymaps)
end
if b ~= nil and vim.api.nvim_buf_is_loaded(b) then
set_keymaps(b, keymaps)
end
end

---Delete keymaps from reviewer buffers.
---@param bufnr integer Number of the buffer from which the keybindings will be removed.
---@param keymaps table The settings keymaps table.
local del_keymaps = function(bufnr, keymaps)
for _, func in ipairs({ "create_comment", "create_suggestion" }) do
if keymaps.reviewer[func] ~= false then
for _, mode in ipairs({ "n", "o", "v" }) do
Expand All @@ -434,23 +454,33 @@ local del_keymaps = function(bufnr, keymaps)
end
end

--- Deletes keymaps from both buffers in the reviewer.
M.del_reviewer_keymaps = function()
-- Require keymaps only after user settings have been merged with defaults
local keymaps = require("gitlab.state").settings.keymaps
if keymaps.disable_all or keymaps.reviewer.disable_all then
return
end
--- Set up autocaommands that will take care of setting and unsetting buffer-local options and keymaps
M.set_reviewer_autocommands = function(bufnr)
local group = vim.api.nvim_create_augroup("gitlab.diffview.autocommand.win_enter." .. bufnr, {})
vim.api.nvim_create_autocmd({ "WinEnter", "BufWinEnter" }, {
group = group,
buffer = bufnr,
callback = function()
if vim.api.nvim_get_current_win() == M.buf_winids[bufnr] then
M.stored_win = vim.api.nvim_get_current_win()
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
M.set_keymaps(bufnr)
else
if M.diffview_layout.b.id == M.buf_winids[bufnr] then
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
end
del_keymaps(bufnr)
end
end,
})
end

local view = diffview_lib.get_current_view()
local a = view.cur_layout.a.file.bufnr
local b = view.cur_layout.b.file.bufnr
if a ~= nil and vim.api.nvim_buf_is_loaded(a) then
del_keymaps(a, keymaps)
end
if b ~= nil and vim.api.nvim_buf_is_loaded(b) then
del_keymaps(b, keymaps)
end
--- Update the stored winid for a given reviewer buffer. This is necessary for the
--- M.set_reviewer_autocommands function to work correctly in cases like when the user closes one of
--- the original reviewer windows and Diffview automatically creates a new pair
--- of reviewer windows or the user wipes out a buffer and Diffview reloads it with a different ID.
M.update_winid_for_buffer = function(bufnr)
M.buf_winids[bufnr] = vim.fn.bufwinid(bufnr)
end

return M
Loading