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

Conversation

barrett-ruth
Copy link
Collaborator

@barrett-ruth barrett-ruth commented Dec 19, 2024

Resolves #216.

Warns on formatter failures, defaulting to != 0.

Create a utility wrapper helpers.check_exit_code to maintain backwards compatibility.

TODO

  1. logger:warn spawns a blocking notification (i.e. must press enter) and creates a timeout error if not pressed within the defualt timeout

^ this is unavoidable - addressed by using a shorter initial message pointing you to to the log file.

@barrett-ruth barrett-ruth marked this pull request as draft December 19, 2024 21:09
@barrett-ruth
Copy link
Collaborator Author

@mochaaP I can't assign reviewers so please take a look. I know I need to squash commits and a bunch of other stuff but I just wanted to draft the initial API. Let me know everything that can be improved.

@mochaaP mochaaP self-assigned this Dec 19, 2024
@mochaaP mochaaP self-requested a review December 19, 2024 22:44
@barrett-ruth barrett-ruth marked this pull request as ready for review December 22, 2024 18:41
@barrett-ruth barrett-ruth marked this pull request as draft December 22, 2024 18:42
@barrett-ruth
Copy link
Collaborator Author

@mochaaP I'm going to start going through the formatters one-by-one (pain) to ensure I'm passing the right exit code.

  1. Is there a better way to do this?
  2. I currently make it optional (and default to exit code 0) to indicate formatter success in check_exit_code. Is this fine?

@mochaaP
Copy link
Member

mochaaP commented Dec 22, 2024

I think (2) is fine.

For (1), we could land the changes first and wait for feedback from ones who actually use them if any problem arises.

@barrett-ruth barrett-ruth marked this pull request as ready for review December 22, 2024 19:27
@barrett-ruth barrett-ruth marked this pull request as draft December 22, 2024 19:30
@barrett-ruth
Copy link
Collaborator Author

Ready for review.

@barrett-ruth barrett-ruth marked this pull request as ready for review December 22, 2024 19:36
lua/null-ls/helpers/formatter_factory.lua Outdated Show resolved Hide resolved
Comment on lines +3 to +20
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
Copy link
Member

Choose a reason for hiding this comment

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

@@ -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.

@barrett-ruth
Copy link
Collaborator Author

barrett-ruth commented Dec 28, 2024

@mochaaP addressing both comments above:

The problem I have with moving the code to the generic factory (and this includes the code duplication comment above) is that I thought this feature only makes sense for formatters.

If we added this to generator factory, wouldn't we also be checking linting exit codes as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatting: Show Error on failure
2 participants