Skip to content

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

@jhendrixMSFT

Description

@jhendrixMSFT

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/completionIssues related to auto-completion in gopls.gopls/imports

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions