Closed cacharle closed 2 years ago
The python program already emits errors messages when catching exception, so I'm not sure but I think handling with the messages is users' (such as plugins using this package) responsibilities. What do you think?
For example, vscode run on save extension, which we're using a solution to use the formatter in vscode, allows me to see the messages while executing. (It doesn't automatically appear though)
I made a simple example of handling them in vim script:
function! s:c_formatter_42()
let filepath = expand('%:p')
redir => message
silent execute '!python3 -m c_formatter_42 ' . filepath
redir END
if v:shell_error
echo message
endif
endfunction
augroup fmt
autocmd!
autocmd BufWritePost *.[ch] call s:c_formatter_42() | edit
augroup END
I also think it should be the extensions's job to detect errors but I didn't knew runOnSave could detect them (thought it would just overwrite the file contects with the error)
Thank you for the vimscript example.
thought it would just overwrite the file contects with the error
That's actually my fault. I guess that you tried my run-on-save config, which makes it just overwrites the contents even if on error. (I had assumed that the formatter can't modify the file content, and used pipes to replace file contents with stdout)
"cmd": "python3 -m c_formatter_42 < ${file} | tee _cfdump && cat _cfdump | tee ${file} && rm -f _cfdump"
↓
"cmd": "python3 -m c_formatter_42 ${file}"
Any exception during the execution of the formatter should restore the current file to it's previous state.
The downside of this is that the formatter will fail silently if there is an error.
One solution to that could be to add a line at the beginning or end of the file with the error (can't be seen by the user if he isn't looking at those lines, but still better than silent).