Skip to content

x/tools/gopls: use common package name aliases in unimported completion and goimports #62193

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

Open
jhendrixMSFT opened this issue Aug 17, 2023 · 5 comments
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls/completion Issues related to auto-completion in gopls. gopls/imports gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@jhendrixMSFT
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

Version Information

go version go1.21.0 windows/amd64
golang.org/x/tools/gopls v0.13.2
vscode version 1.81.1 x64
vscode go extension version 0.39.1
Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: C:\Users\jhendrix\go
GOROOT: C:\Program Files\Go
PATH: C:\Program Files\PowerShell\7;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\nodejs;C:\Program Files\PowerShell\7;C:\Program Files\Git\cmd;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\Go\bin;C:\Users\jhendrix\AppData\Local\Microsoft\WindowsApps;C:\Users\jhendrix\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\jhendrix\go\bin;C:\Users\jhendrix\AppData\Local\Programs\Fiddler;C:\Program Files\Graphviz\bin;C:\Users\jhendrix.dotnet\tools;C:\Users\jhendrix\AppData\Roaming\npm;C:\Users\jhendrix\go\bin

go:	C:\Program Files\Go\bin\go.exe: go version go1.21.0 windows/amd64

gotests:	C:\Users\jhendrix\go\bin\gotests.exe	(version: v1.6.0 built with go: go1.21.0)
gomodifytags:	C:\Users\jhendrix\go\bin\gomodifytags.exe	(version: v1.16.0 built with go: go1.21.0)
impl:	C:\Users\jhendrix\go\bin\impl.exe	(version: v1.1.0 built with go: go1.21.0)
goplay:	C:\Users\jhendrix\go\bin\goplay.exe	(version: v1.0.0 built with go: go1.21.0)
dlv:	C:\Users\jhendrix\go\bin\dlv.exe	(version: v1.21.0 built with go: go1.21.0)
staticcheck:	C:\Users\jhendrix\go\bin\staticcheck.exe	(version: v0.4.3 built with go: go1.21.0)
gopls:	C:\Users\jhendrix\go\bin\gopls.exe	(version: v0.13.2 built with go: go1.21.0)

go env
Workspace Folder (autocompleterepro): c:\git\jhendrixMSFT\autocompleterepro
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\jhendrix\AppData\Local\go-build
set GOENV=C:\Users\jhendrix\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\jhendrix\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\jhendrix\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=C:\Users\jhendrix\go\tmp
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.0
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=c:\git\jhendrixMSFT\autocompleterepro\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\jhendrix\go\tmp\go-build1620475247=/tmp/go-build -gno-record-gcc-switches

using default Go setting, nothing added/edited

Describe the bug

Using autocomplete to create a stub definition of a func within a struct, the aliased package names for the dependent types aren't preserved. Instead, the non-aliased package names are used.

Steps to reproduce the behavior:

Clone https://github.com/jhendrixMSFT/autocompleterepro
On line 12, note that the package names for resp and errResp are incorrect. They should be azfake but are fake.
To repro, just delete line 12 then recreate it, using the autocomplete prompt to create the stub definition for Get.

@findleyr
Copy link
Member

Thank you very much for the issue, and for the repro. Aliases are notoriously problematic in tools/gopls (primarily because they are not represented properly in go/types). With that said, we have various workarounds, and should apply them here.

Transferring to the gopls issue tracker.

@findleyr findleyr changed the title Autocomplete doesn't propagate package alias name x/tools/gopls: autocomplete doesn't propagate package alias name Aug 21, 2023
@findleyr findleyr transferred this issue from golang/vscode-go Aug 21, 2023
@findleyr findleyr added this to the gopls/v0.14.0 milestone Aug 21, 2023
@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 Aug 21, 2023
@gopherbot gopherbot modified the milestones: gopls/v0.14.0, Unreleased Aug 21, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.15.0 Aug 21, 2023
@findleyr

This comment was marked as off-topic.

@adonovan adonovan added the gopls/completion Issues related to auto-completion in gopls. label Dec 1, 2023
@findleyr

This comment was marked as off-topic.

@findleyr findleyr modified the milestones: gopls/v0.15.0, gopls/v0.16.0 Dec 12, 2023
@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.17.0 May 23, 2024
@findleyr findleyr changed the title x/tools/gopls: autocomplete doesn't propagate package alias name x/tools/gopls: use common package name aliases in unimported completion and goimports Oct 28, 2024
@findleyr
Copy link
Member

Duh, this has nothing to do with go/types.Alias: it's talking about package names.

In other words, the request is for gopls to recognize that azfake is the de-facto alias for fake, by considering peer importers or importers in the azure module itself. That is a much more complicted problem.

@findleyr findleyr added gopls/imports FeatureRequest Issues asking for a new feature that does not need a proposal. labels Oct 28, 2024
@findleyr findleyr modified the milestones: gopls/v0.17.0, gopls/backlog Oct 28, 2024
@findleyr
Copy link
Member

I do agree that this would be a useful feature. Moving to the backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls/completion Issues related to auto-completion in gopls. gopls/imports 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