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/gopls: textDocument/completion suggests internal packages from other modules #45707

Closed
gudvinr opened this issue Apr 22, 2021 · 2 comments
Closed

Comments

@gudvinr
Copy link

@gudvinr gudvinr commented Apr 22, 2021

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

$ go version
go version go1.16.3 linux/amd64

gopls version

$ gopls version
golang.org/x/tools/gopls v0.6.10

vscode-go version

Id: golang.go
Version: 0.24.2

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="~/.cache/go-build"
GOENV="~/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="~/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="~/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1429872732=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'll take Tag from golang.org/x/text/language as an example.

  1. I create variable and start typing language.Tag
  2. LSP client (vscode-go in my case) tries to make a code completion for package that isn't yet imported in current scope

What did you expect to see?

I expect to not see suggestions for internal packages from golang.org/x when I'm working inside my own modules since these imports will be restricted and cannot be used.

What did you see instead?

Sometimes (actually quite a lot of times) first suggestion comes from x/text/internal/language instead of x/text/language.

gopls trace
[Trace - 19:50:58.056 PM] Received response 'textDocument/completion - (57)' in 47ms.
Result: {"isIncomplete":true,"items":[{"label":"language.Language","kind":7,"detail":"uint16 (from \"golang.org/x/text/internal/language\")","preselect":true,"sortText":"00000","filterText":"language.Language","insertTextFormat":2,"textEdit":{"range":{"start":{"line":36,"character":1},"end":{"line":36,"character":9}},"newText":"language.Language"},"additionalTextEdits":[{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":2}},"newText":"golang.org/x/text/internal/language\"\n\t\""}]},{"label":"language","kind":9,"detail":"\"golang.org/x/text/language\"","sortText":"00001","filterText":"language","insertTextFormat":2,"textEdit":{"range":{"start":{"line":36,"character":1},"end":{"line":36,"character":9}},"newText":"language"},"additionalTextEdits":[{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":2}},"newText":"golang.org/x/text/language\"\n\t\""}]},{"label":"language","kind":9,"detail":"\"golang.org/x/text/internal/language\"","sortText":"00002","filterText":"language","insertTextFormat":2,"textEdit":{"range":{"start":{"line":36,"character":1},"end":{"line":36,"character":9}},"newText":"language"},"additionalTextEdits":[{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":2}},"newText":"golang.org/x/text/internal/language\"\n\t\""}]},{"label":"language.BaseLanguages","kind":3,"detail":"func() []language.Language (from \"golang.org/x/text/internal/language\")","documentation":"BaseLanguages returns the list of all supported base languages. It generates\nthe list by traversing the internal structures.\n","sortText":"00003","filterText":"language.BaseLanguages","insertTextFormat":2,"textEdit":{"range":{"start":{"line":36,"character":1},"end":{"line":36,"character":9}},"newText":"language.BaseLanguages()"},"additionalTextEdits":[{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":2}},"newText":"golang.org/x/text/internal/language\"\n\t\""}]},{"label":"language.ParseAcceptLanguage","kind":3,"detail":"func(s string) (tag []language.Tag, q []float32, err error) (from \"golang.org/x/text/language\")","documentation":"ParseAcceptLanguage parses the contents of an Accept-Language header as\ndefined in http://www.ietf.org/rfc/rfc2616.txt and returns a list of Tags and\na list of corresponding quality weights. It is more permissive than RFC 2616\nand may return non-nil slices even if the input is not valid.\nThe Tags will be sorted by highest weight first and then by first occurrence.\nTags with a weight of zero will be dropped. An error will be returned if the\ninput could not be parsed.\n","sortText":"00004","filterText":"language.ParseAcceptLanguage","insertTextFormat":2,"textEdit":{"range":{"start":{"line":36,"character":1},"end":{"line":36,"character":9}},"newText":"language.ParseAcceptLanguage(${1:})"},"additionalTextEdits":[{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":2}},"newText":"golang.org/x/text/language\"\n\t\""}]},{"label":"language","kind":9,"detail":"\"google.golang.org/genproto/googleapis/cloud/language/v1\"","sortText":"00007","filterText":"language","insertTextFormat":2,"textEdit":{"range":{"start":{"line":36,"character":1},"end":{"line":36,"character":9}},"newText":"language"},"additionalTextEdits":[{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":2}},"newText":"google.golang.org/genproto/googleapis/cloud/language/v1\"\n\t\""}]},{"label":"language","kind":9,"detail":"\"google.golang.org/api/language/v1\"","sortText":"00008","filterText":"language","insertTextFormat":2,"textEdit":{"range":{"start":{"line":36,"character":1},"end":{"line":36,"character":9}},"newText":"language"},"additionalTextEdits":[{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":2}},"newText":"google.golang.org/api/language/v1\"\n\t\""}]}]}
@muirdm
Copy link

@muirdm muirdm commented Apr 22, 2021

Probably dupe of #44890.

@gudvinr
Copy link
Author

@gudvinr gudvinr commented Apr 22, 2021

Probably dupe of #44890.

I think you right! Closing it as duplicate then

@gudvinr gudvinr closed this Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants