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

Wrong textEdit position in import statement completion

Open 231tr0n opened this issue 3 months ago • 6 comments

Describe the bug

Hi! If I start the svelte language server with the following settings

svelte = {
		settings = {
			typescript = {
				inlayHints = {
					parameterNames = { enabled = "all" },
					parameterTypes = { enabled = true },
					variableTypes = { enabled = true },
					propertyDeclarationTypes = { enabled = true },
					functionLikeReturnTypes = { enabled = true },
					enumMemberValues = { enabled = true },
				},
			},
		},
	},

During the 'completionItem/resolve' request, svelte language server seems to change the textedit value thus not following LSP spec by default which throws error in neovim with plugins like mini.completion.

https://github.com/nvim-mini/mini.nvim/issues/2008

Please take a look at this issue above for the reproduction steps. Although the author of the plugin has fixed it, He suggested that svelte-language-server does not follow lsp spec in this scenario. Hence, I am raising this issue.

Please let me know If I can help in any way. Below is the LSP response returned by the server when typing import ass and select the asset, which is the first entry in the completion menu.

textEdit = {
  newText = "{ asset$1 } from '\\$app/paths';",
  range = {
    start = { line = 5, character = 8 },
    ["end"] = { line = 6, character = 0 },
  }
}
textEdit = {
  newText = "{ asset$1 } from '\\$app/paths';",
  range = {
    start = { line = 5, character = 8 },
    ["end"] = { line = 5, character = 11 },
  }
}

Reproduction

  1. Make sure to have nodejs, npm and svelte-language-server installed. I use arch btw 😏 ~~in WSL2~~, so with arch using yay yay -Syu --noconfirm svelte-language-server nodejs-lts npm does the job.
  2. Below is the config to use to reproduce the issue.
-- Clone latest 'mini.nvim' (requires Git CLI installed)
vim.cmd('echo "Installing `mini.nvim`" | redraw')
local mini_path = vim.fn.stdpath("data") .. "/site/pack/deps/start/mini.nvim"
local clone_cmd = { "git", "clone", "--depth=1", "https://github.com/nvim-mini/mini.nvim", mini_path }
vim.fn.system(clone_cmd)
vim.cmd('echo "`mini.nvim` is installed" | redraw')

-- Make sure 'mini.nvim' is available
vim.cmd("packadd mini.nvim")
require("mini.deps").setup()
require("mini.snippets").setup()
require("mini.completion").setup()

MiniDeps.add("neovim/nvim-lspconfig")

local lsp_servers = {
	svelte = {
		settings = {
			typescript = {
				inlayHints = {
					parameterNames = { enabled = "all" },
					parameterTypes = { enabled = true },
					variableTypes = { enabled = true },
					propertyDeclarationTypes = { enabled = true },
					functionLikeReturnTypes = { enabled = true },
					enumMemberValues = { enabled = true },
				},
			},
		},
	},
}

vim.lsp.config("*", {
	capabilities = lsp_capabilities,
	root_markers = { ".git" },
})
for server, config in pairs(lsp_servers) do
	vim.lsp.config(server, config)
	vim.lsp.enable(server)
end
  1. Clone this repo https://github.com/231tr0n/231tr0n.github.io.git.
  2. Navigate into the git root directory.
  3. Run npm install to install all packages. This step is necessary for the svelte language server to work, as it does not seem to work properly without installing all the packages.
  4. Run NVIM_APPNAME=repro nvim -- src/routes/+layout.svelte.
  5. Go to line number 5 and press o to create a new line 6.
  6. Type import ass and press Ctrl-n to select the first element in the completion menu named asset and press Enter to get the error.

Expected behaviour

Text edit property to not change during 'completionItem/resolve' request.

System Info

  • OS: Archlinux WSL2
  • IDE: Neovim

Which package is the issue about?

svelte-language-server

Additional Information, eg. Screenshots

No response

231tr0n avatar Sep 16 '25 15:09 231tr0n

That's strange, I didn't find any places where we changed the textEdit during completionItem/resolve. We changed detail, documentation and additionalTextEdits. However, in the import statement completion, every edit is calculated in the first step (textDocument/completion). We don't even change the additionalTextEdits. Maybe there is something wrong with the lsp client side? Maybe they have a step to remove the snippet text from the edit, but that triggered at a weird time?

jasonlyu123 avatar Sep 17 '25 01:09 jasonlyu123

That's strange, I didn't find any places where we changed the textEdit during completionItem/resolve. We changed detail, documentation and additionalTextEdits. However, in the import statement completion, every edit is calculated in the first step (textDocument/completion). We don't even change the additionalTextEdits. Maybe there is something wrong with the lsp client side? Maybe they have a step to remove the snippet text from the edit, but that triggered at a weird time?

Please give me some time, by this weekend I should be free enough to do some basic testing. Will let you know once done.

231tr0n avatar Sep 17 '25 03:09 231tr0n

Hi! Please use this log file instead of the one above.

lsp.log

231tr0n avatar Sep 21 '25 20:09 231tr0n

The number is the same, it's all range = { ["end"] = { character = 10, line = 5 }, start = { character = 8, line = 5 } }. This doesn't seem to demonstrate the issue.

jasonlyu123 avatar Sep 22 '25 01:09 jasonlyu123

The number is the same, it's all range = { ["end"] = { character = 10, line = 5 }, start = { character = 8, line = 5 } }. This doesn't seem to demonstrate the issue.

Hi! Sorry for the delayed reply, I am looking into this a bit and have reported about this issue to the plugin author. I will make sure to keep you posted on this. Till then can this issue be open. If it is confirmed that it is a client issue, I will close this issue myself.

231tr0n avatar Sep 22 '25 08:09 231tr0n

Hi! Sorry for the wrong info so the issue is with the character count when we type import ass as described in this issue https://github.com/nvim-mini/mini.nvim/issues/2008. The character count appears to be incorrect. textEdits are not changed.

231tr0n avatar Sep 22 '25 11:09 231tr0n