sourcegraph / go-langserver

Go language server to add Go support to editors and other tools that use the Language Server Protocol (LSP)
https://sourcegraph.com
MIT License
1.17k stars 89 forks source link

Invalid position in Completions #257

Open mjshashank opened 6 years ago

mjshashank commented 6 years ago

I'm working on a custom client with this language server.

When I requests for a completion with the files contents as: im and line as 0 and character as 2, I get error: go completion error: Error: invalid position: (character 2 is beyond first line boundary)

But when I make a request with a blank line or space appended as: im\n or im and the same line, character values of 0,2 I receive accurate completions.

Is this a known issue or expected behaviour? Else, what am I doing wrong here?

lloiser commented 6 years ago

This is fixed in #83 with commit https://github.com/sourcegraph/go-langserver/pull/83/commits/8b3e27eddc852566b372c0e77472b1a1d9e11f37#diff-78179d406a671306d86895d9604fca17

pwaller commented 6 years ago

I'm seeing this in both vscode and atom in very different environments. (Home Ubuntu Desktop atom, Work OSX vscode). Tested on commit e526744 (Tue May 29 2018).

Here is a characteristic error message, which I've seen in both the vscode console and in atom, if I try to use something like go to def:

[Error - 10:02:02] Request textDocument/definition failed.
  Message: invalid position: /path/to/blah.go:15:17 (character 17 is beyond first line boundary)
  Code: 0 

And here's another one, an error message like this is emitted for every keypress:

jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'\x13' ' '} on "blah.go": character 32 is beyond first line boundary

I have verified that the offset is valid in the text editor. Could it be that go-langserver somehow is not using the content as it appears in the editor? Saving the file does not seem to help, but closing the file and reopening it appears to help at least sometimes. I don't rely on the code formatter to format my code, so usually saving doesn't result in the file changing.

It's not easy to reproduce. It just starts happening at some point, and manifests as completion ceasing and go-to-def not working. If I exit and go back into the editor, it works for a little while. I can't point to a public repository where this manifests, I've only noticed it on two completely different companies' fairly large closed source projects. I don't hit it fast enough editing code separately from these repos to be able to give an independent reproducer.

/xref https://github.com/Microsoft/vscode-go/issues/1628 where there are other vscode users reporting this issue recently. /cc @slimsag hi :) 👋

butterflyfish commented 6 years ago

i'm looking forward to address this problem also. thank you!

butterflyfish commented 6 years ago

this issue still exists on neovim with plugin ncm2 and LanguageClient-neovim

fntlnz commented 6 years ago

I had the exact same problem if I start go-langserver without arguments but I was able to have it working with the following arguments:

go-langserver -gocodecompletion -freeosmemory=false
mikefaille commented 5 years ago

I get this problem too using Emacs 27-trunk + eglot. To fix it, I delete eglot and jsonrpc from emacs using package-delete function. I update go-languageserver and I reinstall eglot. Then everything work without special tweaks.