Skip to content

Commit

Permalink
Release: Docs Improvements and Bug Fixes (#460)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
harrisoncramer authored Jan 18, 2025
1 parent 495e64c commit 3b396a5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
7 changes: 7 additions & 0 deletions lua/gitlab/actions/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions lua/gitlab/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions lua/gitlab/reviewer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion lua/gitlab/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3b396a5

Please sign in to comment.