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: prefer dependencies from the go.mod when populating imports #45209

Closed
artyom opened this issue Mar 24, 2021 · 1 comment
Closed
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.

Comments

@artyom
Copy link
Member

artyom commented Mar 24, 2021

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

$ go version
go version go1.16.2 darwin/arm64

$ gopls version
golang.org/x/tools/gopls v0.6.9
    golang.org/x/tools/gopls@v0.6.9 h1:LBBcE2y3Tb4bp79JVLWCQBbvYCFEs5ADGWsQDoSLk1Q=

Does this issue reproduce with the latest release?

N/a.

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/artyom/Library/Caches/go-build"
GOENV="/Users/artyom/Library/Application Support/go/env"
GOEXE=""
GOFLAGS="-ldflags=-w -trimpath"
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/artyom/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/artyom/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/artyom/Library/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/artyom/Library/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/tmp/fail/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lb/3rk8rqs53czgb4v35w_342xc0000gn/T/go-build1158719527=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Create an empty directory, initialize a new module there with go init demo

  2. Add dependency: go get github.com/aws/aws-sdk-go-v2/aws

  3. Open VS Code with Go extension that relies on gopls v0.6.9, and type the following:

    package main
    
    func main() {
    	_ = aws.String("demo")
    }
  4. Save the file, triggering gopls to fill the import section

What did you expect to see?

gopls uses the dependency from the go.mod:

package main

import "github.com/aws/aws-sdk-go-v2/aws"

func main() {
	_ = aws.String("demo")
}

What did you see instead?

gopls incorrectly populated imports with the github.com/aws/aws-sdk-go/aws package.

package main

import "github.com/aws/aws-sdk-go/aws"

func main() {
	_ = aws.String("demo")
}
gopls log from VS Code Problems view
[Info  - 4:04:57 PM] 2021/03/24 16:04:57 go env for /private/tmp/fail
(root /private/tmp/fail)
(go version go version go1.16.2 darwin/arm64)
(valid build configuration = true)
(build flags: [])
GOFLAGS=-ldflags=-w -trimpath
GOMODCACHE=/Users/artyom/go/pkg/mod
GOPATH=/Users/artyom/go
GOPROXY=https://proxy.golang.org,direct
GOROOT=/Users/artyom/Library/go
GONOSUMDB=
GOSUMDB=sum.golang.org
GO111MODULE=on
GOINSECURE=
GONOPROXY=
GOPRIVATE=
GOCACHE=/Users/artyom/Library/Caches/go-build
GOMOD=/private/tmp/fail/go.mod

[Info - 4:04:58 PM] 2021/03/24 16:04:58 go/packages.Load
snapshot=0
directory=/private/tmp/fail
query=[builtin demo/...]
packages=2

[Error - 4:05:21 PM] Request textDocument/codeAction failed.
Message: context canceled
Code: 0
[Info - 4:05:23 PM] 2021/03/24 16:05:23 go/packages.Load
snapshot=3
directory=/private/tmp/fail
query=[file=/private/tmp/fail/main.go]
packages=1

[Info - 4:05:23 PM] 2021/03/24 16:05:23 go/packages.Load
snapshot=3
package="demo"
files=[/private/tmp/fail/main.go]

[Error - 4:05:23 PM] 2021/03/24 16:05:23 demo: no dep handle for github.com/aws/aws-sdk-go/aws: no metadata for github.com/aws/aws-sdk-go/aws
snapshot=3

[Error - 4:05:23 PM] 2021/03/24 16:05:23 diagnosing go.mod: err: exit status 1: stderr: go: finding module for package github.com/aws/aws-sdk-go/aws
demo imports
github.com/aws/aws-sdk-go/aws: cannot find module providing package github.com/aws/aws-sdk-go/aws: module lookup disabled by GOPROXY=off

[Error - 4:05:23 PM] 2021/03/24 16:05:23 demo: no dep handle for github.com/aws/aws-sdk-go/aws: no metadata for github.com/aws/aws-sdk-go/aws
snapshot=4

[Error - 4:05:24 PM] 2021/03/24 16:05:24 diagnosing go.mod: err: exit status 1: stderr: go: finding module for package github.com/aws/aws-sdk-go/aws
demo imports
github.com/aws/aws-sdk-go/aws: cannot find module providing package github.com/aws/aws-sdk-go/aws: module lookup disabled by GOPROXY=off

@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 Mar 24, 2021
@gopherbot gopherbot added this to the Unreleased milestone Mar 24, 2021
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Mar 24, 2021
@stamblerre
Copy link
Contributor

Thank you for this detailed issue report! This is the same as #36077, so I will close it as a duplicate.

@stamblerre stamblerre removed this from the gopls/v1.0.0 milestone Mar 24, 2021
@golang golang locked and limited conversation to collaborators Mar 24, 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