Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: async.run_command: report error exit code and stderr #2896

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
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
18 changes: 15 additions & 3 deletions lua/lspconfig/async.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function M.run_command(cmd)

local stdout = {}
local stderr = {}
local exit_code = nil

local jobid = vim.fn.jobstart(cmd, {
on_stdout = function(_, data, _)
data = table.concat(data, '\n')
Expand All @@ -26,19 +28,29 @@ function M.run_command(cmd)
on_stderr = function(_, data, _)
stderr[#stderr + 1] = table.concat(data, '\n')
end,
on_exit = function()
on_exit = function(_, code, _)
exit_code = code
coroutine.resume(co)
end,
stdout_buffered = true,
stderr_buffered = true,
})

if jobid <= 0 then
vim.notify(('[lspconfig] cmd go failed:\n%s'):format(table.concat(stderr, '')), vim.log.levels.WARN)
return
vim.notify(('[lspconfig] unable to run cmd: %s'):format(cmd), vim.log.levels.WARN)
return nil
end

coroutine.yield()

if exit_code ~= 0 then
vim.notify(
('[lspconfig] cmd failed with code %d: %s\n%s'):format(exit_code, cmd, table.concat(stderr, '')),
vim.log.levels.WARN
)
return nil
end

if next(stdout) == nil then
return nil
end
Expand Down