diff --git a/cmd/app/client.go b/cmd/app/client.go index 4d3da2e..a599397 100644 --- a/cmd/app/client.go +++ b/cmd/app/client.go @@ -68,6 +68,7 @@ func NewClient() (*Client, error) { retryClient := retryablehttp.NewClient() retryClient.HTTPClient.Transport = tr + retryClient.RetryMax = 0 gitlabOptions = append(gitlabOptions, gitlab.WithHTTPClient(retryClient.HTTPClient)) client, err := gitlab.NewClient(pluginOptions.AuthToken, gitlabOptions...) diff --git a/lua/gitlab/actions/common.lua b/lua/gitlab/actions/common.lua index a6734d2..a2caed0 100644 --- a/lua/gitlab/actions/common.lua +++ b/lua/gitlab/actions/common.lua @@ -293,6 +293,13 @@ M.jump_to_file = function(tree) u.notify("This comment was not left on a particular location", vim.log.levels.WARN) return end + if vim.fn.filereadable(root_node.file_name) == 0 then + u.notify( + string.format("The file %s for which the comment was made doesn't exist in HEAD.", root_node.file_name), + vim.log.levels.WARN + ) + return + end vim.cmd.tabnew() local line_number = get_new_line(root_node) or get_old_line(root_node) if line_number == nil then diff --git a/lua/gitlab/job.lua b/lua/gitlab/job.lua index 7f5f4d8..128591b 100644 --- a/lua/gitlab/job.lua +++ b/lua/gitlab/job.lua @@ -17,6 +17,7 @@ M.run_job = function(endpoint, method, body, callback) -- This handler will handle all responses from the Go server. Anything with a successful -- status will call the callback (if it is supplied for the job). Otherwise, it will print out the -- success message or error message and details from the Go server. + local stderr = {} Job:new({ command = "curl", args = args, @@ -55,13 +56,20 @@ M.run_job = function(endpoint, method, body, callback) end end, 0) end, - on_stderr = function() - vim.defer_fn(function() - u.notify("Could not run command!", vim.log.levels.ERROR) - end, 0) + on_stderr = function(_, data) + if data then + table.insert(stderr, data) + end end, - on_exit = function(_, status) + on_exit = function(code, status) vim.defer_fn(function() + if #stderr ~= 0 then + u.notify( + string.format("Could not run command `%s %s`! Stderr was:", code.command, table.concat(code.args, " ")), + vim.log.levels.ERROR + ) + vim.notify(string.format("%s", table.concat(stderr, "\n")), vim.log.levels.ERROR) + end if status ~= 0 then u.notify(string.format("Go server exited with non-zero code: %d", status), vim.log.levels.ERROR) end diff --git a/lua/gitlab/reviewer/init.lua b/lua/gitlab/reviewer/init.lua index c5b103b..b03f99f 100644 --- a/lua/gitlab/reviewer/init.lua +++ b/lua/gitlab/reviewer/init.lua @@ -109,7 +109,6 @@ M.jump = function(file_name, line_number, new_buffer) return end vim.api.nvim_set_current_tabpage(M.tabnr) - vim.cmd("DiffviewFocusFiles") local view = diffview_lib.get_current_view() if view == nil then u.notify("Could not find Diffview view", vim.log.levels.ERROR) @@ -120,6 +119,13 @@ M.jump = function(file_name, line_number, new_buffer) local file = List.new(files):find(function(file) return file.path == file_name end) + if file == nil then + u.notify( + string.format("The file %s for which the comment was made doesn't exist in HEAD.", file_name), + vim.log.levels.WARN + ) + return + end async.await(view:set_file(file)) local layout = view.cur_layout @@ -325,7 +331,8 @@ local set_keymaps = function(bufnr, keymaps) if keymaps.reviewer.create_comment ~= false then -- Set keymap for repeated operator keybinding vim.keymap.set("o", keymaps.reviewer.create_comment, function() - vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { tostring(vim.v.count1) .. "$" } }, {}) + -- The "V" in "V%d$" forces linewise motion, see `:h o_V` + vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { string.format("V%d$", vim.v.count1) } }, {}) end, { buffer = bufnr, desc = "Create comment for [count] lines", @@ -355,7 +362,8 @@ local set_keymaps = function(bufnr, keymaps) if keymaps.reviewer.create_suggestion ~= false then -- Set keymap for repeated operator keybinding vim.keymap.set("o", keymaps.reviewer.create_suggestion, function() - vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { tostring(vim.v.count1) .. "$" } }, {}) + -- The "V" in "V%d$" forces linewise motion, see `:h o_V` + vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { string.format("V%d$", vim.v.count1) } }, {}) end, { buffer = bufnr, desc = "Create suggestion for [count] lines", diff --git a/lua/gitlab/server.lua b/lua/gitlab/server.lua index 6e77c8a..094100a 100644 --- a/lua/gitlab/server.lua +++ b/lua/gitlab/server.lua @@ -26,7 +26,11 @@ M.start = function(callback) state.chosen_mr_iid = 0 -- Do not let this interfere with subsequent reviewer.open() calls local settings = vim.json.encode(go_server_settings) - local command = string.format("%s '%s'", state.settings.bin, settings) + if vim.fn.has("win32") then + settings = settings:gsub('"', '\\"') + end + + local command = string.format('"%s" "%s"', state.settings.bin, settings) local job_id = vim.fn.jobstart(command, { on_stdout = function(_, data)