lsp icon indicating copy to clipboard operation
lsp copied to clipboard

Add a synchronous version of `:LspFormat`

Open noscript opened this issue 3 years ago • 2 comments

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.

noscript avatar Mar 08 '22 23:03 noscript

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.

yegappan avatar Mar 09 '22 01:03 yegappan

That workaround solves it!

noscript avatar Mar 09 '22 09:03 noscript

I have committed 748cea25fc8474b7c6f4a990ed54f5761136d3aa to use sync RPC call for the ":LspFormat" command.

yegappan avatar Oct 24 '22 15:10 yegappan