Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim.lsp.buf.format() invalidates changes list #21783

Open
Baehn opened this issue Jan 13, 2023 · 5 comments
Open

vim.lsp.buf.format() invalidates changes list #21783

Baehn opened this issue Jan 13, 2023 · 5 comments
Labels
lsp status:blocked-external Needs a third-party / external change or fix
Milestone

Comments

@Baehn
Copy link

Baehn commented Jan 13, 2023

Describe the bug

I noticed that with some language servers (e.g. sumneko_lua) after calling vim.lsp.buf.format() entries in :changes are marked as invalid (-invalid-). This only seems to happen for lsp's sending the whole formatted document as response instead of actual text edits.

Steps to reproduce

  1. open new lua file with attached lsp "sumneko_lua"
  2. insert two lines:
print("1")
print("2")
  1. :lua vim.lsp.buf.format()
  2. open changes list with :changes

Expected behavior

calling :changes should result in

change line  col text
    2     1    9 print("1")
    1     2    7 print("2")
>

but instead shows

change line  col text
    3     1    9 print("1")
    2     1    0 print("1")
    1     3    0 -invalid-
>

Neovim version (nvim -v)

v0.9.0-dev-581+gcb9d68fe6

Vim (not Nvim) behaves the same?

na

Operating system/version

5.15.0-10056-tuxedo

Terminal name/version

konsole 21.12.3

$TERM environment variable

xterm-256color

Installation

build from repo

@Baehn Baehn added the bug issues reporting wrong behavior label Jan 13, 2023
@glepnir glepnir added the lsp label Jan 13, 2023
@Baehn
Copy link
Author

Baehn commented Jan 14, 2023

other vim features are affected too:

  • jumplist: all entries are collapsed to the first line in buffer
  • marks: all lowercase entries are removed
  • extmarks: all entries are collapsed to last line

@justinmk
Copy link
Member

only seems to happen for lsp's sending the whole formatted document as response instead of actual text edits.

what can we do about that?

@justinmk justinmk added status:blocked-external Needs a third-party / external change or fix and removed bug issues reporting wrong behavior labels Jan 16, 2023
@Baehn
Copy link
Author

Baehn commented Jan 16, 2023

what can we do about that?

you don't think that this is something neovim should handle? Looking at the lsp specification I'm not sure if this is actually prohibited. For example, one could compute the actual diff to the current buffer and then apply this as text edits.

@justinmk
Copy link
Member

For example, one could compute the actual diff to the current buffer and then apply this as text edits.

i mean yeah we could do that, or ... the language server could do that, since that is its job 😏

@marconetto
Copy link

marconetto commented Oct 30, 2023

I noticed that if I use vim.lsp.buf.format in a lua file, the marks disappear. I found this issue and if I understood correctly there is a limitation in the lua language server---which indeed I don't have issues with python and other language servers.

I'm wondering if there is any suggestion of a temporary workaround to avoid having the marks disappear for lua files when running the autoformating?

EDIT:
I found this plugin which seems to solve the issue:
https://github.com/stevearc/conform.nvim
"Diffs the format results and applies the changes using the same utilities as LSP formatting. This preserves extmarks, folds, and cursor/window position."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lsp status:blocked-external Needs a third-party / external change or fix
Projects
None yet
Development

No branches or pull requests

4 participants