Add a synchronous version of `:LspFormat`
I'm looking for a solution to format files before writing.
autocmd BufWritePre *.c,*.cpp,*.h :LspFormat
The problem is that :LspFormat is asynchronous and the buffer gets written before formatting.
Moreover, sometimes I get corrupted buffer content. It seems that the formatting happens while the buffer is being written.
Can you try adding a call to lspserver.waitForReponse(req) at the end of the TextDocFormat() function in the autoload/lsp/lspserver.vim file? This is already called if g:LSPTest is defined. You can move this out of this if check.
That workaround solves it!
I have committed 748cea25fc8474b7c6f4a990ed54f5761136d3aa to use sync RPC call for the ":LspFormat" command.