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

x/tools/internal/lsp: completion works only when typing first character #30796

Closed
anjmao opened this issue Mar 13, 2019 · 6 comments
Closed

x/tools/internal/lsp: completion works only when typing first character #30796

anjmao opened this issue Mar 13, 2019 · 6 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Milestone

Comments

@anjmao
Copy link

anjmao commented Mar 13, 2019

What version of Go are you using (go version)?

Hi, just tried newest gopls version.

go version go1.12 darwin/amd64

Typing s shows completion items and string is suggested

func fn() {
	var a <>
}

Typing st shows no completion suggestions but should suggest string

func fn() {
	var a s<>
}

My findings

I'm using vscode with gopls. What I noticed is that Completion handler is called only once and until completion popup is visible no more calls are made for completion, this is why completion is not updated. DidChange handler is working fine and called on every character input.

By following vscode language client-server tutorial https://code.visualstudio.com/api/language-extensions/language-server-extension-guide I can see that completion is triggered only once (while completion menu with suggested items is shown) for performance reasons and client does filtering, but for some reasons this doesn't work for gopls and vscode-go. Do you have any ideas that is the problem here?

/cc @stamblerre

@gopherbot gopherbot added this to the Unreleased milestone Mar 13, 2019
@ALTree ALTree added the gopls Issues related to the Go language server, gopls. label Mar 13, 2019
@ALTree
Copy link
Member

ALTree commented Mar 13, 2019

(OT)

@stamblerre can you confirm that the new lsp issue label is spelled correctly? It's gopls but it seems it should be golsp (or even lsp). The tool is at internal/lsp and I can't find instances of it being spelled pls on the internet.

@anjmao
Copy link
Author

anjmao commented Mar 13, 2019

@ALTree it should be gopls meaning Go Please do x task for me.

@ALTree
Copy link
Member

ALTree commented Mar 13, 2019

Ah, my bad. You're right. I also just noticed the wiki page is at https://github.com/golang/go/wiki/gopls too. I was thinking about golang.org/x/tools/internal/lsp since the label is being applied to lsp issues too, so I was expecting it to be named lsp.

Sorry for the noise.

@anjmao
Copy link
Author

anjmao commented Mar 13, 2019

After debugging a bit I found that this issue is due to TextEdit https://github.com/golang/tools/blob/master/internal/lsp/completion.go#L40

If I remove TextEdit from completion item then it works.

@anjmao anjmao changed the title x/tools/internal/lsp: completion works only then typing first character x/tools/internal/lsp: completion works only when typing first character Mar 13, 2019
@stamblerre
Copy link
Contributor

@anjmao: thanks for investigating - it's really interesting that TextEdit is the problem, since as far as I know, InsertText is deprecated in favor of TextEdit (https://microsoft.github.io/language-server-protocol/specification#textDocument_completion). I'll look into this further.

@gopherbot
Copy link

Change https://golang.org/cl/167457 mentions this issue: internal/lsp: stop providing insertText for completion items

movie-travel-code pushed a commit to elastic/go-langserver that referenced this issue Mar 19, 2019
InsertText is deprecated, and it seems that providing both InsertText
and TextEdits causes unexpected behavior from VSCode. Avoid this by
providing only TextEdits.

Fixes golang/go#30796

Change-Id: Ieb5ad2fecd6f7083a4c1bc402634893c7e6ff49f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167457
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Projects
None yet
Development

No branches or pull requests

4 participants