autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 272 forks source link

textDocument_formatting() writes even if unchanged #1161

Closed OJFord closed 3 years ago

OJFord commented 3 years ago

I want to autocmd CursorHold <buffer> call LanguageClient#textDocument_formatting(), but currently the problem is that it writes out even if unchanged; so the buffer constantly reverts to being unsaved (unless I quit soon enough after writing that CursorHold doesn't kick in).

martskins commented 3 years ago

What language server are you seeing this in? I think this may be a server issue, as I can't reproduce in Go or Rust (for example). In any case, you could do something like this if you want to avoid this and even avoid the first re-save you have to do now.

function! AfterFormat abort
  noautocmd w
endfunction

autocmd CursorHold <buffer> call LanguageClient#textDocument_formatting({}, 'AfterFormat')

I'm not 100% sure if this can introduce any issues with your flow but I would suspect it's fine given that you are already using the async version of formatting.

OJFord commented 3 years ago

vls (Vue) when I reported it, but it is indeed fine with pyls (Python) so not a bug here, at least. (And I'm in no mood to look at any Vue code over a weekend..! :smile:)