Skip to content

Commit 9d85474

Browse files
stevearcF1lipB
authored andcommitted
fix: display stdout as error message if stderr is empty (nvim-lua#486)
1 parent 94cf1d5 commit 9d85474

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lua/conform/runner.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ M.apply_format = function(
272272
return not vim.tbl_isempty(text_edits)
273273
end
274274

275+
---@param output? string[]
276+
---@return boolean
277+
local function is_empty_output(output)
278+
return not output or vim.tbl_isempty(output) or (#output == 1 and output[1] == "")
279+
end
280+
275281
---Map of formatter name to if the last run of that formatter produced an error
276282
---@type table<string, boolean>
277283
local last_run_errored = {}
@@ -402,10 +408,12 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, c
402408
log.debug("%s stdout: %s", formatter.name, stdout)
403409
log.debug("%s stderr: %s", formatter.name, stderr)
404410
local err_str
405-
if stderr and not vim.tbl_isempty(stderr) then
411+
if not is_empty_output(stderr) then
406412
err_str = table.concat(stderr, "\n")
407-
elseif stdout and not vim.tbl_isempty(stdout) then
413+
elseif not is_empty_output(stdout) then
408414
err_str = table.concat(stdout, "\n")
415+
else
416+
err_str = "unknown error"
409417
end
410418
if
411419
vim.api.nvim_buf_is_valid(bufnr)

0 commit comments

Comments
 (0)