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

[BUG] LSP Message (dartls) Invalid line number #403

Open
1 task done
p4-k4 opened this issue Nov 2, 2024 · 8 comments
Open
1 task done

[BUG] LSP Message (dartls) Invalid line number #403

p4-k4 opened this issue Nov 2, 2024 · 8 comments

Comments

@p4-k4
Copy link

p4-k4 commented Nov 2, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Pasting 60-odd lines of code crashes LSP with LSP Message (dartls) Invalid line number.

Restart neovim to continue until next paste (LSP crashes and cannot be restarted).

Expected Behavior

LSP to remain active without errors.

Steps To Reproduce

  1. Copy/yank around 60 lines of text.
  2. Paste into file.

Environment

NVIM v0.10.1
MacOS

paka  ~/.config/nvim  ♥ 21:16  which flutter 
/opt/homebrew/bin/flutter

[] Flutter (Channel master, 3.26.0-1.0.pre.372, on macOS 15.0 24A335 darwin-arm64, locale en-US)

Anything else?

No response

@Mike20403
Copy link

got the same problems , when copy & paste a whole block a code
image

@p4-k4
Copy link
Author

p4-k4 commented Nov 9, 2024

What's your workaround @Mike20403 ? I don't know Lua well at all but trying to look into it.

@p4-k4
Copy link
Author

p4-k4 commented Nov 9, 2024

Found out that this may only occur when yanking/pasting using a G in visual mode to select to bottom.

If you yank/paste from the start of your selection and manually select the last character, no error occurs.

@Mike20403
Copy link

Mike20403 commented Nov 9, 2024

yep, that's what I'm suffering right now, but I feel a little inconvenient to do so, cause I frequent use ggVG to yank and copy the whole think and paste to another file with the same command "ggVG". Do you know what caused this problem?

@bytecodevet
Copy link

bytecodevet commented Dec 13, 2024

Hello guys, I also encountered this problem and solved it in the following way:
After saving (BufWritePost), I checked whether dartls was running. If it wasn't, I restarted it (asynchronously).

Here is an example code:

-- lua/plugins/lsp.lua
-- Dart
lsp.dartls.setup({})

local function reload_dartls_if_inactive()
	local dartls_client
	for _, client in ipairs(vim.lsp.get_clients()) do
		if client.name == "dartls" then
			dartls_client = client
			break
		end
	end

	vim.defer_fn(function()
		if dartls_client and not dartls_client.is_stopped() then
			return
		end

		if dartls_client and dartls_client.stop then
			dartls_client.stop()
		end

		print("Restarting Dartls")

		local lspconfig = require("lspconfig")
		lspconfig.dartls.setup({})
	end, 2000)
end

vim.api.nvim_create_autocmd("BufWritePost", {
	pattern = "*.dart",
	callback = reload_dartls_if_inactive,
})

@p4-k4
Copy link
Author

p4-k4 commented Dec 13, 2024

A decent workaround for now, cheers @bytecodevet

@bytecodevet
Copy link

bytecodevet commented Dec 14, 2024

Hi guys. The previous code worked quite stable. But when I tried using settings (dartls.setup({settings=this})), it didn't work at all, for example, completeFunctionCalls, and closing tags from flutter-tools also didn't work.

After a few hours of digging through the source code of flutter-tools, I finally found a solution.

-- Dart
-- if you use flutter-tools lspconfig.dartls.setup you don't need to.
local function reload_dartls_if_inactive()
	local dartls_client
	for _, client in ipairs(vim.lsp.get_clients()) do
		if client.name == "dartls" then
			dartls_client = client
			break
		end
	end

	vim.defer_fn(function()
		if dartls_client and not dartls_client.is_stopped() then
			return
		end

		if dartls_client and dartls_client.stop then
			dartls_client.stop()
		end

		require("flutter-tools.lsp").attach() -- <--- this line.
	end, 2000)
end

vim.api.nvim_create_autocmd("BufWritePost", {
	pattern = "*.dart",
	callback = reload_dartls_if_inactive,
})

I dug through the code for several hours, and in the end, it was just one line of code to fix it. 😅

I believe this issue has been resolved with the recent changes. Could you please close it? If further action is required, feel free to let me know. Thanks!

@Mike20403
Copy link

perfect solution, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants