Skip to content

Commit 3b396a5

Browse files
Release: Docs Improvements and Bug Fixes (#460)
Miscellaneous bug fixes and improvements. docs: various improvements (#445) fix: don't jump to file from reviewer if it doesn't exist (#452) fix: force linewise motion in suggestion keybinding (#454) fix: prevent error after plenary job update (#456) fix: fix JSON on Windows (#458) fix: remove retry logic (#449) fix: check whether comment can be created (#434)
1 parent 495e64c commit 3b396a5

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

cmd/app/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func NewClient() (*Client, error) {
6868

6969
retryClient := retryablehttp.NewClient()
7070
retryClient.HTTPClient.Transport = tr
71+
retryClient.RetryMax = 0
7172
gitlabOptions = append(gitlabOptions, gitlab.WithHTTPClient(retryClient.HTTPClient))
7273

7374
client, err := gitlab.NewClient(pluginOptions.AuthToken, gitlabOptions...)

lua/gitlab/actions/common.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ M.jump_to_file = function(tree)
293293
u.notify("This comment was not left on a particular location", vim.log.levels.WARN)
294294
return
295295
end
296+
if vim.fn.filereadable(root_node.file_name) == 0 then
297+
u.notify(
298+
string.format("The file %s for which the comment was made doesn't exist in HEAD.", root_node.file_name),
299+
vim.log.levels.WARN
300+
)
301+
return
302+
end
296303
vim.cmd.tabnew()
297304
local line_number = get_new_line(root_node) or get_old_line(root_node)
298305
if line_number == nil then

lua/gitlab/job.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ M.run_job = function(endpoint, method, body, callback)
1717
-- This handler will handle all responses from the Go server. Anything with a successful
1818
-- status will call the callback (if it is supplied for the job). Otherwise, it will print out the
1919
-- success message or error message and details from the Go server.
20+
local stderr = {}
2021
Job:new({
2122
command = "curl",
2223
args = args,
@@ -55,13 +56,20 @@ M.run_job = function(endpoint, method, body, callback)
5556
end
5657
end, 0)
5758
end,
58-
on_stderr = function()
59-
vim.defer_fn(function()
60-
u.notify("Could not run command!", vim.log.levels.ERROR)
61-
end, 0)
59+
on_stderr = function(_, data)
60+
if data then
61+
table.insert(stderr, data)
62+
end
6263
end,
63-
on_exit = function(_, status)
64+
on_exit = function(code, status)
6465
vim.defer_fn(function()
66+
if #stderr ~= 0 then
67+
u.notify(
68+
string.format("Could not run command `%s %s`! Stderr was:", code.command, table.concat(code.args, " ")),
69+
vim.log.levels.ERROR
70+
)
71+
vim.notify(string.format("%s", table.concat(stderr, "\n")), vim.log.levels.ERROR)
72+
end
6573
if status ~= 0 then
6674
u.notify(string.format("Go server exited with non-zero code: %d", status), vim.log.levels.ERROR)
6775
end

lua/gitlab/reviewer/init.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ M.jump = function(file_name, line_number, new_buffer)
109109
return
110110
end
111111
vim.api.nvim_set_current_tabpage(M.tabnr)
112-
vim.cmd("DiffviewFocusFiles")
113112
local view = diffview_lib.get_current_view()
114113
if view == nil then
115114
u.notify("Could not find Diffview view", vim.log.levels.ERROR)
@@ -120,6 +119,13 @@ M.jump = function(file_name, line_number, new_buffer)
120119
local file = List.new(files):find(function(file)
121120
return file.path == file_name
122121
end)
122+
if file == nil then
123+
u.notify(
124+
string.format("The file %s for which the comment was made doesn't exist in HEAD.", file_name),
125+
vim.log.levels.WARN
126+
)
127+
return
128+
end
123129
async.await(view:set_file(file))
124130

125131
local layout = view.cur_layout
@@ -325,7 +331,8 @@ local set_keymaps = function(bufnr, keymaps)
325331
if keymaps.reviewer.create_comment ~= false then
326332
-- Set keymap for repeated operator keybinding
327333
vim.keymap.set("o", keymaps.reviewer.create_comment, function()
328-
vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { tostring(vim.v.count1) .. "$" } }, {})
334+
-- The "V" in "V%d$" forces linewise motion, see `:h o_V`
335+
vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { string.format("V%d$", vim.v.count1) } }, {})
329336
end, {
330337
buffer = bufnr,
331338
desc = "Create comment for [count] lines",
@@ -355,7 +362,8 @@ local set_keymaps = function(bufnr, keymaps)
355362
if keymaps.reviewer.create_suggestion ~= false then
356363
-- Set keymap for repeated operator keybinding
357364
vim.keymap.set("o", keymaps.reviewer.create_suggestion, function()
358-
vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { tostring(vim.v.count1) .. "$" } }, {})
365+
-- The "V" in "V%d$" forces linewise motion, see `:h o_V`
366+
vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { string.format("V%d$", vim.v.count1) } }, {})
359367
end, {
360368
buffer = bufnr,
361369
desc = "Create suggestion for [count] lines",

lua/gitlab/server.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ M.start = function(callback)
2626
state.chosen_mr_iid = 0 -- Do not let this interfere with subsequent reviewer.open() calls
2727

2828
local settings = vim.json.encode(go_server_settings)
29-
local command = string.format("%s '%s'", state.settings.bin, settings)
29+
if vim.fn.has("win32") then
30+
settings = settings:gsub('"', '\\"')
31+
end
32+
33+
local command = string.format('"%s" "%s"', state.settings.bin, settings)
3034

3135
local job_id = vim.fn.jobstart(command, {
3236
on_stdout = function(_, data)

0 commit comments

Comments
 (0)