language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

formatting results in invalid file modifications in neovim

Open mortezadadgar opened this issue 2 years ago • 4 comments

Describe the bug

formatting files on other lsp is not resulting in modified files in neovim, this can be reviewed by looking at the output of :changes while i don't know which side is causing the problem i have opened an issue there as well see: https://github.com/neovim/neovim/issues/25579

Reproduction

see mentioned issue

Expected behaviour

formatting files should only modifies the lines that has formatted by lsp

System Info

  • OS: Archlinux
  • IDE: NVIM v0.9.4

Which package is the issue about?

svelte-language-server

Additional Information, eg. Screenshots

No response

mortezadadgar avatar Oct 11 '23 20:10 mortezadadgar

I don't understand what you meant by "resulting in modified files in neovim" and "results in invalid file modifications"? But judging by the "expected behaviour", maybe it's because the formatting is currently replacing the whole document. We didn't calculate the difference between before and after.

jasonlyu123 avatar Oct 12 '23 00:10 jasonlyu123

I meant this by modified files and invalid modification my neovim output of :changes: image normally lsp formatter only makes changes to specific lines not the whole document

mortezadadgar avatar Oct 12 '23 05:10 mortezadadgar

Correct me if I misunderstood because I don't fully understand what you want to address, so please explain your intention in detail. There seem to be two issues you want to address. One is the "invalid" in your changes. And the other is that the change doesn't list every single difference in the file.

For "invalid", I can't relate the result of formatting edits to this image. The edit the language server returns is a single replacement instead of two. What exactly is in line 108 before format and after format?

For replacing the whole file, We're using prettier for formatting. The result returned by Prettier is the whole file. It'll take extra effort to calculate the difference between before and after. It also does what it is supposed to do, formatting. So it doesn't make much sense for us to spend the extra time to calculate the difference. Why would you need to know what changes?

jasonlyu123 avatar Oct 12 '23 06:10 jasonlyu123

I try to explain with gopls with a very basic program in go 231012-0943-02 before running formatter I have :changes like this: 231012-0938-39 modifying line 3 to trigger formatter results in 231012-0940-23 so only line 3 is changed by lsp in case of svelte lsp formatter replace the whole file as you said so invalid line remains in :changes output for example this file has 129 line before formatting and 137 lines after, and line 138 is marked as invalid for some reason image image

Why would you need to know what changes?

it's useful in neovim/vim for g; and g, key to bring back and forth to last changed line in a file

Thanks for bearing with me btw

mortezadadgar avatar Oct 12 '23 06:10 mortezadadgar