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

Formatting: Show Error on failure #216

Open
1 task done
barrett-ruth opened this issue Dec 16, 2024 · 1 comment · May be fixed by #221
Open
1 task done

Formatting: Show Error on failure #216

barrett-ruth opened this issue Dec 16, 2024 · 1 comment · May be fixed by #221
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@barrett-ruth
Copy link
Collaborator

Issues

  • I have checked existing issues and there are no existing ones with the same request.

Feature description

I understand that (deep in the weeds of) the documentation is describes that one can debug formatter failures as such:

            check_exit_code = function(code, stderr)
                local success = code <= 1
    
                if not success then
                    -- can be noisy for things that run often (e.g. diagnostics), but can
                    -- be useful for things that run on demand (e.g. formatting)
                    print(stderr)
                end
    
                return success
            end,

However, I think this should be the default. Moreover, I speculate that most people aren't bothered by this not being the default because it is just a minor inconvenience - even though they'd indeed prefer it to be.

For example, when editing a large HTML file using none-ls, prettier may just silently fail, my LSP will not be able to tell what's happening, and the only logical thing is to :!prettier % to debug the error.

I've updated my config here and it works fine, but it really is polluted (and there's an LSP timeout error):

local function check_formatter_exit_code(code, stderr)
    local success = code <= 0

    if not success then
        vim.schedule(function()
            logger:warn(('failed to run formatter: %s'):format(stderr))
        end)
    end

    return success
end

null_ls.setup({
        formatting.buf.with({
            check_exit_code = check_formatter_exit_code,
        }),
        formatting.cbfmt.with({
            check_exit_code = check_formatter_exit_code,
        }),
        formatting.cmake_format.with({
            check_exit_code = check_formatter_exit_code,
        }),
       ...
})

I think this is a sensible default choice but let me know if y'all think otherwise.

Help

Yes

Implementation help

Willing (and would prefer) to help.

@barrett-ruth barrett-ruth added the enhancement New feature or request label Dec 16, 2024
@mochaaP mochaaP added the help wanted Extra attention is needed label Dec 17, 2024
@mochaaP
Copy link
Member

mochaaP commented Dec 17, 2024

I'm positive about this change. :)

Note that some external formatting tools will exit with a non-zero status if checks aren't passing (but fix them anyway), while others don't. If we'd like to use this as the default behavior, we need to review all the builtins and ensure the corresponding behavior.

Aside from that, I think adding check_exit_code to helpers should be a good start.
You can start implementing the changes.

@barrett-ruth barrett-ruth linked a pull request Dec 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants