diff --git a/cmd/app/comment_helpers.go b/cmd/app/comment_helpers.go index d6548bd5..8b74ccd5 100644 --- a/cmd/app/comment_helpers.go +++ b/cmd/app/comment_helpers.go @@ -42,19 +42,13 @@ type RequestWithPosition interface { func buildCommentPosition(commentWithPositionData RequestWithPosition) *gitlab.PositionOptions { positionData := commentWithPositionData.GetPositionData() - // If the file has been renamed, then this is a relevant part of the payload - oldFileName := positionData.OldFileName - if oldFileName == "" { - oldFileName = positionData.FileName - } - opt := &gitlab.PositionOptions{ PositionType: &positionData.Type, StartSHA: &positionData.StartCommitSHA, HeadSHA: &positionData.HeadCommitSHA, BaseSHA: &positionData.BaseCommitSHA, NewPath: &positionData.FileName, - OldPath: &oldFileName, + OldPath: &positionData.OldFileName, NewLine: positionData.NewLine, OldLine: positionData.OldLine, } diff --git a/lua/gitlab/actions/common.lua b/lua/gitlab/actions/common.lua index 030c0c8d..6ad224db 100644 --- a/lua/gitlab/actions/common.lua +++ b/lua/gitlab/actions/common.lua @@ -277,7 +277,7 @@ M.jump_to_reviewer = function(tree) u.notify("Could not get line number", vim.log.levels.ERROR) return end - reviewer.jump(root_node.file_name, line_number, is_new_sha) + reviewer.jump(root_node.file_name, root_node.old_file_name, line_number, is_new_sha) end -- This function (settings.keymaps.discussion_tree.jump_to_file) will jump to the file changed in a new tab @@ -301,7 +301,7 @@ M.jump_to_file = function(tree) end vim.cmd.tabnew() local line_number = get_new_line(root_node) or get_old_line(root_node) - if line_number == nil then + if line_number == nil or line_number == 0 then line_number = 1 end local bufnr = vim.fn.bufnr(root_node.file_name) diff --git a/lua/gitlab/actions/discussions/tree.lua b/lua/gitlab/actions/discussions/tree.lua index 7451a802..e4f192ba 100644 --- a/lua/gitlab/actions/discussions/tree.lua +++ b/lua/gitlab/actions/discussions/tree.lua @@ -28,6 +28,8 @@ M.add_discussions_to_table = function(items, unlinked) local root_note_id = "" ---@type string? local root_file_name = "" + ---@type string? + local root_old_file_name = "" ---@type string local root_id local root_text_nodes = {} @@ -43,6 +45,7 @@ M.add_discussions_to_table = function(items, unlinked) if j == 1 then _, root_text, root_text_nodes = M.build_note(note, { resolved = note.resolved, resolvable = note.resolvable }) root_file_name = (type(note.position) == "table" and note.position.new_path or nil) + root_old_file_name = (type(note.position) == "table" and note.position.old_path or nil) root_new_line = (type(note.position) == "table" and note.position.new_line or nil) root_old_line = (type(note.position) == "table" and note.position.old_line or nil) root_id = discussion.id @@ -79,6 +82,7 @@ M.add_discussions_to_table = function(items, unlinked) id = root_id, root_note_id = root_note_id, file_name = root_file_name, + old_file_name = root_old_file_name, new_line = root_new_line, old_line = root_old_line, resolvable = resolvable, diff --git a/lua/gitlab/indicators/diagnostics.lua b/lua/gitlab/indicators/diagnostics.lua index 0eb32b37..e32e086f 100644 --- a/lua/gitlab/indicators/diagnostics.lua +++ b/lua/gitlab/indicators/diagnostics.lua @@ -126,10 +126,8 @@ M.place_diagnostics = function(bufnr) local ok, err = pcall(function() local file_discussions = List.new(M.placeable_discussions):filter(function(discussion_or_note) local note = discussion_or_note.notes and discussion_or_note.notes[1] or discussion_or_note - -- Surprisingly, the following line works even if I'd expect it should match new/old paths - -- with a/b buffers the other way round! - return note.position.new_path == view.cur_layout.a.file.path - or note.position.old_path == view.cur_layout.b.file.path + return note.position.new_path == view.cur_layout.b.file.path + or note.position.old_path == view.cur_layout.a.file.path end) if #file_discussions == 0 then diff --git a/lua/gitlab/reviewer/init.lua b/lua/gitlab/reviewer/init.lua index 24258ca2..fc95f5ac 100644 --- a/lua/gitlab/reviewer/init.lua +++ b/lua/gitlab/reviewer/init.lua @@ -105,10 +105,11 @@ M.close = function() end --- Jumps to the location provided in the reviewer window ----@param file_name string ----@param line_number number ----@param new_buffer boolean -M.jump = function(file_name, line_number, new_buffer) +---@param file_name string The file name after change. +---@param old_file_name string The file name before change (different from file_name for renamed/moved files). +---@param line_number number Line number from the discussion node. +---@param new_buffer boolean If true, jump to the NEW SHA. +M.jump = function(file_name, old_file_name, line_number, new_buffer) if M.tabnr == nil then u.notify("Can't jump to Diffvew. Is it open?", vim.log.levels.ERROR) return @@ -121,8 +122,8 @@ M.jump = function(file_name, line_number, new_buffer) end local files = view.panel:ordered_file_list() - local file = List.new(files):find(function(file) - return file.path == file_name + local file = List.new(files):find(function(f) + return new_buffer and f.path == file_name or f.oldpath == old_file_name end) if file == nil then u.notify( @@ -192,8 +193,8 @@ M.get_reviewer_data = function() local new_sha_win_id = u.get_window_id_by_buffer_id(layout.b.file.bufnr) return { - file_name = layout.a.file.path, - old_file_name = M.is_file_renamed() and layout.b.file.path or "", + old_file_name = layout.a.file.path, + file_name = layout.b.file.path, old_line_from_buf = old_line, new_line_from_buf = new_line, modification_type = modification_type,