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: empty struct literal providing incorrect completion suggestions #45739

Open
ryanmcnamara opened this issue Apr 23, 2021 · 2 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@ryanmcnamara
Copy link

ryanmcnamara commented Apr 23, 2021

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

$ go version

go version go1.14.4 darwin/amd64

Does this issue reproduce with the latest release?

yes, did a fresh you complete me install

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

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ryan.mcnamara/Library/Caches/go-build"
GOENV="/Users/ryan.mcnamara/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY="github.com/DataDog"
GONOSUMDB="github.com/DataDog"
GOOS="darwin"
GOPATH="/Users/ryan.mcnamara/code"
GOPRIVATE="github.com/DataDog"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="0"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vp/t7z89ng12n7f629v_26str8w0000gn/T/go-build672772168=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I am using vim withthe latest version of YouCompleteMe which I believe uses gopls under the hood. I would like to verify the following using the gopls cli but have not been able to figure out how to get autocomplete suggestions with the cli. Direction there would be appreciated as it would likely help narrow down if this is actually a gopls issue or a you complete me issue.
When autocompleting on empty struct literals

When populating an autocomplete list inside an empty struct I get the same autocomplete recommendations as outside the struct (all available identifiers):
image

image

What did you expect to see?

The list restricted to only the fields of the struct: Asdf, and Qwer in the above case

More info

When the struct literal has any token in it, even if that token is not a valid member, I do see the autocomplete suggestions as desired

image

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Apr 23, 2021
@gopherbot gopherbot added this to the Unreleased milestone Apr 23, 2021
@muirdm
Copy link

muirdm commented Apr 24, 2021

This is what I see in Emacs:
Screen Shot 2021-04-23 at 5 09 01 PM

I recommend you look at an RPC trace to see the back and forth between gopls and your editor. You can enable this on the gopls side (https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#capture-logs) or perhaps your lsp client can also dump out the details.

If you suspect your editor/client may be to blame, you can try VSCode to see how it behaves.

@suzmue
Copy link
Contributor

suzmue commented Apr 26, 2021

The gopls cli does not currently support autocompletion, but as @muirdm suggested, you could try using a different editor or client that also uses gopls (for other vim clients you can check this list: https://github.com/golang/tools/blob/master/gopls/doc/vim.md).

@suzmue suzmue modified the milestones: Unreleased, gopls/unplanned Apr 26, 2021
@stamblerre stamblerre changed the title x/tools/gopls empty struct literal providing incorrect completion suggestions x/tools/gopls: empty struct literal providing incorrect completion suggestions Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants