Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

x/tools/gopls: completion incorrectly offers embedded field shadowed by outer field #60069

Open
myitcv opened this issue May 9, 2023 · 10 comments
Labels
gopls/completion Issues related to auto-completion in gopls. gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented May 9, 2023

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

$ go version
go version go1.20.2 linux/arm64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.9.0
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.0.0-20230508221120-0809ec2e45f6

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="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/myitcv/gostuff/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/govim/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2292349384=/tmp/go-build -gno-record-gcc-switches"

What did you do?

With the following input file:

package main

import (
	"fmt"
	"log"
)

type outer struct {
	// outer logger
	logger *log.Logger

	inner
}

type inner struct {
	// inner logger
	logger *log.Logger
}

func main() {
	var v outer
	fmt.Println(v.lo_)
}

The cursor at the position _.

Attempt a completion.

What did you expect to see?

The single candidate outer.logger.

What did you see instead?

Two candidates:

outer.logger
inner.logger

The completion text for both is the plain logger. So this can't be correct, as the outer.logger shadows the embedded inner.logger.

@myitcv myitcv added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. labels May 9, 2023
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 9, 2023
@gopherbot gopherbot added this to the Unreleased milestone May 9, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/later May 9, 2023
@findleyr findleyr added the gopls/completion Issues related to auto-completion in gopls. label May 9, 2023
@findleyr
Copy link
Contributor

findleyr commented May 9, 2023

Thanks for the report. You're right that this is inaccurate. We should instead offer the deep completion of v.inner.logger.

@myitcv
Copy link
Member Author

myitcv commented May 9, 2023

Thanks for the report. You're right that this is inaccurate. We should instead offer the deep completion of v.inner.logger.

I'm not clear that in this case you should. Because I don't have deep completions turned on (intentionally), and hopefully my config reflects that.

@findleyr
Copy link
Contributor

findleyr commented May 9, 2023

@myitcv yes, I mean only in the case where deep completions are enabled.

@findleyr
Copy link
Contributor

findleyr commented May 9, 2023

BTW: @myitcv I'm curious why you have deep completions turned off, if you don't mind providing feedback.

@myitcv
Copy link
Member Author

myitcv commented May 9, 2023

BTW: @myitcv I'm curious why you have deep completions turned off, if you don't mind providing feedback.

Of course!

Please bear in mind that what follows is largely a function of my personal experience and preference using Vim.

I have deep completions turned off for largely the same reason as I'm advocating for search scopes in #37237. 90% of the time I don't want deep completions. So any results that are deep would be noise, and I find that noise incredibly distracting. If I could have a keystroke to opt a particular completion into deep completion I would take that for sure! But much like different search scopes, I don't want the default to be "I'll include everything and you keep typing to be more precise". In both cases, I know the scope of the completion or the search, and am happy to assign a key binding to change the scope. So all or nothing config options don't work for me.

@findleyr findleyr modified the milestones: gopls/later, gopls/v0.13.0 May 10, 2023
@findleyr
Copy link
Contributor

Thanks!

I think proper sorting can come close to providing the best of both worlds. Gopls could improve a lot in this regard.

@myitcv
Copy link
Member Author

myitcv commented May 11, 2023

I think proper sorting can come close to providing the best of both worlds.

I'm not entirely sure I understand what you mean by "proper sorting". Not least because I'm not clear that in this or the the symbol case "proper sorting" (or indeed any ranking algorithm) can ever know the intended scope of my completion/search, and therefore segment the results accordingly.

Per #37236 (comment), the visual noise is, in any case, a major part of the problem for me.

@muirdm
Copy link

muirdm commented Jun 16, 2024

I don't see duplicate "logger" candidates anymore, but I still don't see "inner.logger" with deep completions enabled. I think there is some code somewhere that assumes embedded structs don't need to be searched because their fields were already included in the containing struct's fields, but that is not true for fields with conflicting names.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/592975 mentions this issue: gopls/completion: fix completion of ambiguous fields

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/594242 mentions this issue: gopls/completion: switch to new field/method search

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
gopls/completion Issues related to auto-completion in gopls. gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. 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