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

Validate Formatter Exit Codes #221

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
20 changes: 20 additions & 0 deletions lua/null-ls/helpers/check_exit_code.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local logger = require("null-ls.logger")

return function(success_codes, command)
return function(code, stderr)
local success

if type(success_codes) == "number" then
success = code <= success_codes
else
success = vim.tbl_contains(success_codes, code)
end

if not success then
vim.schedule(function()
logger:warn(string.format("failed to run formatter %s; see `:NullLsLog`", command))
logger:add_entry(string.format("failed to run formatter %s: %s", command, stderr), "warn")
end)
end
end
end
Comment on lines +3 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 changes: 5 additions & 0 deletions lua/null-ls/helpers/formatter_factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ return function(opts)
return done({ { text = output } })
end

if opts.check_exit_code == nil then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set check_exit_code in the generator factory instead of here.

vim.print(opts)
barrett-ruth marked this conversation as resolved.
Show resolved Hide resolved
opts.check_exit_code = require("null-ls.helpers").check_exit_code(0, opts.command)
end

return require("null-ls.helpers").generator_factory(opts)
end
1 change: 1 addition & 0 deletions lua/null-ls/helpers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ return {
diagnostics = require("null-ls.helpers.diagnostics"),
formatter_factory = require("null-ls.helpers.formatter_factory"),
generator_factory = require("null-ls.helpers.generator_factory"),
check_exit_code = require("null-ls.helpers.check_exit_code"),
make_builtin = require("null-ls.helpers.make_builtin"),
range_formatting_args_factory = require("null-ls.helpers.range_formatting_args_factory"),
}
Loading