go: x/tools/gopls: failure to import package
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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 14
- Comments: 39 (14 by maintainers)
After update some golang tools, I found this issue solved:
set GO111MODULE=ONgo get -u -v github.com/mdempsky/gocodego get -u -v github.com/ramya-rao-a/go-outlinego get -u -v golang.org/x/tools/cmd/gorename… I guess that gopls or vscode may need the golang tools to implement some lsp functions. If these tools are not updated to be located at $GOPATH/pkg/, gopls may fail.So I think I had a similar problem. What I noticed in the above log line was that the
PWDwas set to the root of the workspace directory I’d opened, rather than the root of the go project I was working on. I cleared my workspace and opened just the root of the project I was working on and all errors resolved.Hope that helps.
It looks like
goplswas unable to find any files for this import. What happens if you rungo list -e -compiled -json /path/to/packagewhere/path/to/packageis the absolute path to the package you are working in?Also, can you try to repro with the latest version of
goplson master (go get -u golang.org/x/tools/gopls@master)? We have recently made some changes that may have fixed this.