vim-autoformat / vim-autoformat

Provide easy code formatting in Vim by integrating existing code formatters.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Display syntax errors in quickfix window

derat opened this issue · comments

Is there a way to configure vim-autoformat to display syntax errors detected by formatters?

For example, when I pipe a file with a syntax error into goimports, it returns exit code 2 after printing nothing to stdout and printing errors to stderr, e.g.

main.go:3:9: expected 'IDENT', found '{'
main.go:4:2: expected '(', found 'IDENT' x
main.go:6:2: expected declaration, found 'IDENT' blah

I'm using au BufWrite * :Autoformat, and I would find it helpful to have those errors displayed in the quickfix window (with setqflist) so that I can see and correct them immediately instead of only seeing them when I try to compile the code. Right now, vim-autoformat appears to silently hide the errors.

#182 looks like a similar request where the quickfix window was mentioned.

And thank you for vim-autoformat! It seems much more reliable than other formatting extensions I had been using, which had unfortunate tendencies to mess up my undo history or mangle the buffer if I made additional edits while the formatter was running.

The aim of a formatting tool is to do a best effort in formatting the code. To display syntax errors and other issues you should use a linter integration plugin instead, such as syntastic. That plugin probably already does what you want.

Thanks for the quick reply! I understand your rationale; at the same time, I'd rather not need to run goimports (or gofmt) twice or use a much-larger plugin like Syntastic. I hacked in rudimentary quickfix support at derat@00bffa4, in case anyone else finds it useful.