go-langserver icon indicating copy to clipboard operation
go-langserver copied to clipboard

Invalid position in Completions

Open mjshashank opened this issue 6 years ago • 6 comments

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?

mjshashank avatar Apr 11 '18 06:04 mjshashank

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

lloiser avatar Apr 11 '18 06:04 lloiser

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 :) 👋

pwaller avatar Jun 13 '18 09:06 pwaller

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

butterflyfish avatar Jul 10 '18 09:07 butterflyfish

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

butterflyfish avatar Aug 06 '18 08:08 butterflyfish

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

fntlnz avatar Aug 21 '18 21:08 fntlnz

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.

mikefaille avatar Dec 02 '18 21:12 mikefaille