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: failure to import package #32762

Open
mrdulin opened this issue Jun 25, 2019 · 8 comments

Comments

Projects
None yet
5 participants
@mrdulin
Copy link

commented Jun 25, 2019

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

$ go version
go version go1.12.6 darwin/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ldu020/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ldu020/workspace/github.com/mrdulin/golang/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 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/38/s8g_rsm13yxd26nwyqzdp2shd351xb/T/go-build050424632=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Here is the code:

import (
	"fmt"
	"go-clean-arch/domain/models"
	"go-clean-arch/domain/repositories"
)

I am using vscode and golang extension. When I hover to the import statement, the output of gopls give me this error.

What did you expect to see?

I try it using goland IDE, it works fine.

What did you see instead?

This error when hover to the import statement:

could not import go-clean-arch/domain/repositories (no parsed files for package go-clean-arch/domain/repositories)LSP

[Trace - 11:42:13 AM] Sending request 'textDocument/hover - (36)'.
Params: {"textDocument":{"uri":"file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go"},"position":{"line":4,"character":23}}


[Error - 11:42:14 AM] send textDocument/hover#36 no import for "go-clean-arch/domain/models"


[Error - 11:42:14 AM] Request textDocument/hover failed.
  Message: no import for "go-clean-arch/domain/models"
  Code: 0 

@agnivade agnivade changed the title Request textDocument/hover failed x/tools/gopls: Request textDocument/hover failed Jun 25, 2019

@gopherbot gopherbot added this to the Unreleased milestone Jun 25, 2019

@gopherbot gopherbot added the gopls label Jun 25, 2019

@agnivade agnivade removed the Documentation label Jun 25, 2019

@stamblerre stamblerre changed the title x/tools/gopls: Request textDocument/hover failed x/tools/gopls: failure to import package Jun 27, 2019

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2019

It looks like gopls was unable to find any files for this import. What happens if you run go list -e -compiled -json /path/to/package where /path/to/package is the absolute path to the package you are working in?

Also, can you try to repro with the latest version of gopls on master (go get -u golang.org/x/tools/gopls@master)? We have recently made some changes that may have fixed this.

@mrdulin

This comment has been minimized.

Copy link
Author

commented Jun 28, 2019

@stamblerre Thanks for reply.

☁  golang [master] go list -e -compiled -json /Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go
{
        "Dir": "/Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services",
        "ImportPath": "command-line-arguments",
        "Name": "services",
        "Root": "/Users/ldu020/workspace/github.com/mrdulin/golang",
        "Match": [
                "/Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go"
        ],
        "Stale": true,
        "StaleReason": "stale dependency: go-clean-arch/domain/models",
        "GoFiles": [
                "googleAccount.go"
        ],
        "CompiledGoFiles": [
                "googleAccount.go"
        ],
        "Imports": [
                "fmt",
                "go-clean-arch/domain/models",
                "go-clean-arch/domain/repositories"
        ],
        "Deps": [
                "bufio",
                "bytes",
                "context",
                "database/sql",
                "database/sql/driver",
                "encoding",
                "encoding/xml",
                "errors",
                "fmt",
                "go-clean-arch/domain/models",
                "go-clean-arch/domain/models/adChannel",
                "go-clean-arch/domain/repositories",
                "internal/bytealg",
                "internal/cpu",
                "internal/fmtsort",
                "internal/poll",
                "internal/race",
                "internal/syscall/unix",
                "internal/testlog",
                "io",
                "math",
                "math/bits",
                "os",
                "reflect",
                "runtime",
                "runtime/internal/atomic",
                "runtime/internal/math",
                "runtime/internal/sys",
                "sort",
                "strconv",
                "strings",
                "sync",
                "sync/atomic",
                "syscall",
                "time",
                "unicode",
                "unicode/utf8",
                "unsafe"
        ]
}

Here are more informations. I am using vscode and go extension and I already installed each go tools to the latest version according below way:

image

Here is my repo: https://github.com/mrdulin/golang/tree/master/src/go-clean-arch

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Jun 28, 2019

Thanks for sharing the repro. I was able to reproduce your issue and will investigate it.

@marco-m

This comment has been minimized.

Copy link

commented Jul 10, 2019

For my understanding: what is the difference with #32903 ?

@mrdulin

This comment has been minimized.

Copy link
Author

commented Jul 10, 2019

After set

  "go.toolsEnvVars": {
    "GO111MODULE": "on"
  },

and reload vscode window. Still got these errors in gopls output tab

[Error - 8:09:06 PM] unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go
[Trace - 8:09:07 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go"}


[Error - 8:09:07 PM] unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go
[Error - 8:09:07 PM] send textDocument/hover#29 no AST for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go


[Trace - 8:09:07 PM] Sending request 'textDocument/definition - (30)'.
Params: {"textDocument":{"uri":"file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go"},"position":{"line":5,"character":26}}


[Error - 8:09:07 PM] Request textDocument/hover failed.
  Message: no AST for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go
  Code: 0 
[Trace - 8:09:09 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go"}


[Error - 8:09:09 PM] unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go
[Trace - 8:09:11 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go"}


[Error - 8:09:11 PM] send textDocument/definition#30 no AST for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go


[Error - 8:09:11 PM] unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go
[Error - 8:09:11 PM] Request textDocument/definition failed.
  Message: no AST for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/go-clean-arch/domain/services/googleAccount.go
  Code: 0 
@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2019

@marco-m: I have not yet had time to investigate this issue, but in the case of #32903, the user was trying to use modules, but did not have modules enabled in VSCode itself. gopls is started via VSCode, so it needs to propagate the value of the GO111MODULES environment variable.

@marco-m

This comment has been minimized.

Copy link

commented Jul 10, 2019

Thanks @stamblerre for the explanation :-)

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Jul 22, 2019

@mrdulin: Can you share your gopls version (gopls version)? Make sure you are using the latest version by running go get golang.org/x/tools/gopls@latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.