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

Text edits from efm-langserver are applied in reverse #29392

Open
kyoh86 opened this issue Jun 18, 2024 · 5 comments
Open

Text edits from efm-langserver are applied in reverse #29392

kyoh86 opened this issue Jun 18, 2024 · 5 comments
Labels
bug issues reporting wrong behavior lsp

Comments

@kyoh86
Copy link

kyoh86 commented Jun 18, 2024

Problem

Formatting some continuous lines with efm-langserver, text lines are reversed.

It depends on the commit: 2ce4a4d and the issue: #29202.

Maybe the changes in the commit is intended to conform to specifications of LSP, but they looks like not still enough.
(Specs doesn't require sorting of text-edits)
So I don't know that which product (efm, Neovim or VSCode?) should fix the bug.

Steps to reproduce

Prepare environment

We needs nvim-lspconfig, efm-langserver and jq for example (in Linux):

$ export NVIM_APPNAME=nvim_issue_29392
$ NVIM_APPDIR="~/.config/$NVIM_APPNAME"
$ EFM_NAME=efm-langserver_v0.0.53_linux_amd64
$ JQ_NAME=jq-linux-amd64 

$ mkdir -p "$NVIM_APPDIR/bin"
$ git clone https://github.com/neovim/nvim-lspconfig "$NVIM_APPDIR/rtp/nvim-lspconfig"
$ curl -Lo "$NVIM_APPDIR/bin/efm.tar.gz" "https://github.com/mattn/efm-langserver/releases/download/v0.0.53/$EFM_NAME.tar.gz"
$ curl -Lo "$NVIM_APPDIR/bin/jq" "https://github.com/jqlang/jq/releases/download/jq-1.7.1/$JQ_NAME"
$ chmod +x "$NVIM_APPDIR/bin/jq"
$ cd "$NVIM_APPDIR/bin"
$ tar -xvzf efm.tar.gz
$ mv $EFM_NAME/efm-langserver .

Setup neovim

And set-up nvim like below (~/.config/nvim_issue_29392/init.lua):

vim.opt.rtp:append("~/.config/nvim_fmt/rtp/nvim-lspconfig")

local lspconfig = require("lspconfig")
lspconfig.efm.setup({
  init_options = {
    documentFormatting = true,
  },
  settings = {
    languages = {
      json = { {
        formatStdin = true,
        formatCommand = "jq .",
      } },
    },
  },
})

Reproduce in Neovim

Prepare target file:

  {
    "foo": "bar"
  }

Start neovim:

$ export NVIM_APPNAME=nvim_issue_29392
$ export PATH="~/.config/$NVIM_APPNAME/bin:$PATH"
$ nvim foo.json

Call lua vim.lsp.buf.format().

And get the invalid result:

}
  "foo": "bar"
{

Expected behavior

Formatted right:

{
  "foo": "bar"
}

Neovim version (nvim -v)

v0.11.0-dev-b0c336e

Vim (not Nvim) behaves the same?

no

Operating system/version

Arch Linux

Terminal name/version

WezTerm

$TERM environment variable

xterm-256color

Installation

Build from repo

@kyoh86 kyoh86 added the bug issues reporting wrong behavior label Jun 18, 2024
@clason clason added the lsp label Jun 18, 2024
@scohen
Copy link

scohen commented Jun 18, 2024

Maybe the changes in the commit is intended to conform to specifications of LSP, but they looks like not still enough.
(Specs doesn't require sorting of text-edits)

For what it's worth, the spec specifically says that the order of edits matters. The language server I run sends them in a specific order, and they work fine in VSCode. Neovim is the only client that we've had this issue with.

@kyoh86
Copy link
Author

kyoh86 commented Jun 18, 2024

Just to be clear: I am not sure if the problem @scohen is facing is the same as the one caused by the compatibility with efm-langserver.

@scohen
Copy link

scohen commented Jun 18, 2024

My take is that the client shouldn't be reordering edits, neovim's client does. Right now, my LS doesn't have a problem with neovim, the commits mentioned in the bug fixed the problems we were having, but I felt that was not a correct fix.

@kyoh86
Copy link
Author

kyoh86 commented Jun 19, 2024

Maybe it should be reported as another issue.

@geril2207
Copy link

geril2207 commented Jun 19, 2024

I also have kind of the same problem with tsserver after 2ce4a4d, #29286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior lsp
Projects
None yet
Development

No branches or pull requests

4 participants