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: autoimport keeps importing the wrong package #46471

Closed
Zyl9393 opened this issue May 31, 2021 · 1 comment
Closed

x/tools/gopls: autoimport keeps importing the wrong package #46471

Zyl9393 opened this issue May 31, 2021 · 1 comment
Labels
FrozenDueToAge 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

@Zyl9393
Copy link

Zyl9393 commented May 31, 2021

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

$ go version
go version go1.16.3 windows/amd64
$ gopls version
golang.org/x/tools/gopls v0.6.11
    golang.org/x/tools/gopls@v0.6.11 h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=

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
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Zyl\AppData\Local\go-build
set GOENV=C:\Users\Zyl\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\Projects\Code\Go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\Projects\Code\Go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.3
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Zyl\AppData\Local\Temp\go-build1411503252=/tmp/go-build -gno-record-gcc-switches

What did you do?

In a newly added .go file, write a function which refers to the OpenGL package gl, which does not yet have a matching import-statement in the file, such as:

func glFontAtlas(img []byte, w, h int) (texId uint32) {
	gl.ActiveTexture(gl.TEXTURE0)
	gl.GenTextures(1, &texId)
	gl.BindTexture(gl.TEXTURE_2D, texId)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.SRGB8, int32(w), int32(h), 0, gl.RED, gl.UNSIGNED_BYTE, unsafe.Pointer(&img[0]))
	gl.GenerateMipmap(gl.TEXTURE_2D)
	return texId
}

Then save the file.

What did you expect to see?

The package to be auto-imported (save action) by the same path already used in many other .go files within the workspace, namely:
"github.com/go-gl/gl/v3.3-core/gl"

What did you see instead?

The following import is being added automatically instead:
"github.com/go-gl/gl/v2.1/gl"

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label May 31, 2021
@Zyl9393 Zyl9393 changed the title gopls: autoimport keeps importing the wrong package x/tools/gopls: autoimport keeps importing the wrong package May 31, 2021
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 31, 2021
@gopherbot gopherbot added this to the Unreleased milestone May 31, 2021
@stamblerre
Copy link
Contributor

Thank you for this report! I believe this is actually already a known issue, tracked in #36077. Specifically, see the comment here: #36077 (comment). I will close this issue as a duplicate.

@golang golang locked and limited conversation to collaborators Jun 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

3 participants