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
Comments
It looks like Also, can you try to repro with the latest version of |
@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: Here is my repo: https://github.com/mrdulin/golang/tree/master/src/go-clean-arch |
Thanks for sharing the repro. I was able to reproduce your issue and will investigate it. |
For my understanding: what is the difference with #32903 ? |
After set
and reload vscode window. Still got these errors in [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 |
Thanks @stamblerre for the explanation :-) |
@mrdulin: Can you share your |
@stamblerre Thanks for the reply. ☁ golang [master] gopls version
version v0.1.3-cmd.gopls, built in $GOPATH mode Try to install the latest version of ☁ golang [master] go get golang.org/x/tools/gopls@latest
go: cannot use path@version syntax in GOPATH mode |
@mrdulin: Are you still encountering this issue? Note that when you open VSCode, you have to open it from the module root (the directory that contains the If you are still seeing these errors, can you |
@stamblerre Yes. this issue still there. import (
"fmt"
"serverless-functions-go/domain/models"
"serverless-functions-go/domain/services"
"serverless-functions-go/domain/services/adChannel/reports/adPerformance"
"serverless-functions-go/infrastructure/config"
) When I hover my mouse to
Here is the output for running the command you provided. ☁ golang [master] ⚡ gopls -rpc.trace -v check ./src/serverless-functions-go/infrastructure/config/config.go
2019/08/07 11:06:00 Info:42.543279ms for GOROOT= GOPATH=/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang GO111MODULE= PWD=/Users/ldu020/workspace/github.com/mrdulin/golang go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>
2019/08/07 11:06:00 Info:Build info
----------
version v0.1.3, built in $GOPATH mode
Go info
-------
go version go1.12.6 darwin/amd64
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-build861790958=/tmp/go-build -gno-record-gcc-switches -fno-common"
2019/08/07 11:06:03 Info:2.603490358s for GOROOT= GOPATH=/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang GO111MODULE= PWD=/Users/ldu020/workspace/github.com/mrdulin/golang go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config", stderr: <<go: finding github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config latest
go: finding github.com/mrdulin/golang/src/serverless-functions-go/infrastructure latest
go: finding github.com/mrdulin/golang/src/serverless-functions-go latest
go: finding github.com/mrdulin/golang/src latest
>>
2019/08/07 11:06:05 Info:2.32500393s for GOROOT= GOPATH=/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang GO111MODULE= PWD=/Users/ldu020/workspace/github.com/mrdulin/golang go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config/config.go", stderr: <<>>
2019/08/07 11:06:05 Info:go/packages.Load
packages = 1
2019/08/07 11:06:05 Info:go/packages.Load
package = command-line-arguments
files = [/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config/config.go]
/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config/config.go:10:2-59: could not import serverless-functions-go/infrastructure/gcloud/datastore (no parsed files for package serverless-functions-go/infrastructure/gcloud/datastore)
☁ golang [master] ⚡ |
And what is the output of |
☁ golang [master] ⚡ go list -e -json -compiled -test /Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config
go: finding github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config latest
go: finding github.com/mrdulin/golang/src/serverless-functions-go/infrastructure latest
go: finding github.com/mrdulin/golang/src/serverless-functions-go latest
go: finding github.com/mrdulin/golang/src latest
{
"ImportPath": "github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config",
"Match": [
"/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config"
],
"Incomplete": true,
"Error": {
"ImportStack": [
"github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config"
],
"Pos": "",
"Err": "unknown import path \"github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config\": cannot find module providing package github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config"
}
} |
Can you try explicitly setting |
☁ golang [master] ⚡ export GO111MODULE=on
☁ golang [master] ⚡ echo $GO111MODULE
on
☁ golang [master] ⚡ gopls -rpc.trace -v check ./src/serverless-functions-go/infrastructure/config/config.go
2019/08/08 13:18:41 Info:132.397084ms for GOROOT= GOPATH=/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang GO111MODULE=on PWD=/Users/ldu020/workspace/github.com/mrdulin/golang go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>
2019/08/08 13:18:41 Info:Build info
----------
version v0.1.3, built in $GOPATH mode
Go info
-------
go version go1.12.6 darwin/amd64
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-build684880075=/tmp/go-build -gno-record-gcc-switches -fno-common"
2019/08/08 13:18:44 Info:2.536632473s for GOROOT= GOPATH=/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang GO111MODULE=on PWD=/Users/ldu020/workspace/github.com/mrdulin/golang go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config", stderr: <<go: finding github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config latest
go: finding github.com/mrdulin/golang/src/serverless-functions-go/infrastructure latest
go: finding github.com/mrdulin/golang/src/serverless-functions-go latest
go: finding github.com/mrdulin/golang/src latest
>>
2019/08/08 13:18:44 Info:769.01801ms for GOROOT= GOPATH=/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang GO111MODULE=on PWD=/Users/ldu020/workspace/github.com/mrdulin/golang go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config/config.go", stderr: <<>>
2019/08/08 13:18:44 Info:go/packages.Load
packages = 1
2019/08/08 13:18:44 Info:go/packages.Load
package = command-line-arguments
files = [/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config/config.go]
/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config/config.go:10:2-59: could not import serverless-functions-go/infrastructure/gcloud/datastore (no parsed files for package serverless-functions-go/infrastructure/gcloud/datastore)
☁ golang [master] ⚡ go list -e -json -compiled -test /Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config
go: finding github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config latest
go: finding github.com/mrdulin/golang/src/serverless-functions-go/infrastructure latest
go: finding github.com/mrdulin/golang/src/serverless-functions-go latest
go: finding github.com/mrdulin/golang/src latest
{
"ImportPath": "github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config",
"Match": [
"/Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config"
],
"Incomplete": true,
"Error": {
"ImportStack": [
"github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config"
],
"Pos": "",
"Err": "unknown import path \"github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config\": cannot find module providing package github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config"
}
} |
Thanks for checking. I've tried a few of the other directories in your repository myself, and they all seem to work fine for me. Are you planning to commit your changes in If not, do the other directories/files work for you? Is there another example that I could try to repro? |
I have the same problem, go version
go env
What did you do?
What did you see instead?
Maybe you need to look at thislsp-log
|
No problem at all, I will do this right away. |
After update some golang tools, I found this issue solved:
|
@Jiffies-Duke: Those tools are actually not related to |
I have the same problem, x/tools/gopls: could not import github.com/XXX (no parsed files for package XXXXX..... |
Version: 1.38.1 y@liuhy:~$ gopls version |
liuhy@liuhy:~/fabric-examples$ env | grep GO |
set GO111MODULE=ON |
@liuhangyu: Please open a new issue and I can help you investigate there. Please include the information requested on the Troubleshooting guide. |
@stamblerre Sorry for replying lately. This issue still there. I create a minimal code sample for reproducing it. Here is the directory structure: ☁ issue-32762 [master] ⚡ tree -L 3
.
├── domain
│ └── models
│ └── user.go
└── main.go
2 directories, 2 files
package main
import (
"fmt"
"issue-32762/domain/models"
)
func main() {
user := models.User{UserID: 1}
fmt.Printf("user=%v\n", user)
}
package models
import "database/sql"
// User Model
type User struct {
UserID int `db:"user_id"`
UserNme string `db:"user_nme"`
UserEmail string `db:"user_email"`
UserAddressID sql.NullInt64 `db:"user_address_id"`
} This code sample can be executed correctly. ☁ issue-32762 [master] ⚡ go run main.go
user={1 {0 false}} But, when I hover the import statement Here are the debug information what I got from the OUTPUT tab of Vscode for [Trace - 20:30:22.298 PM] Sending request 'textDocument/hover - (6602)'.
Params: {"textDocument":{"uri":"file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/issue-32762/main.go"},"position":{"line":4,"character":18}}
[Trace - 20:30:22.298 PM] Received response 'textDocument/hover - (6602)' in 0ms.
Result: {}
[Trace - 20:30:22.456 PM] Sending request 'textDocument/codeAction - (6603)'.
Params: {"textDocument":{"uri":"file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/issue-32762/main.go"},"range":{"start":{"line":4,"character":1},"end":{"line":4,"character":28}},"context":{"diagnostics":[{"range":{"start":{"line":4,"character":1},"end":{"line":4,"character":28}},"message":"could not import issue-32762/domain/models (no package data for import path issue-32762/domain/models)","severity":1,"source":"LSP"}]}}
[Trace - 20:30:22.457 PM] Received response 'textDocument/codeAction - (6603)' in 0ms.
Result: [{"title":"Organize Imports","kind":"source.organizeImports","edit":{"changes":{"file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/issue-32762/main.go":[]}}}] The minimal code sample for reproducing this issue: https://github.com/mrdulin/golang/tree/master/src/issue-32762 P.S. I add this Please fix this issue. I prefer using Vscode rather than
☁ golang [master] go version
go version go1.12.6 darwin/amd64
☁ golang [master] 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-build939687880=/tmp/go-build -gno-record-gcc-switches -fno-common"
{
"go.languageServerFlags": [
"-rpc.trace",
"serve",
"--debug=localhost:6060"
],
"go.toolsGopath": "~/workspace/go",
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.useLanguageServer": true,
"go.formatTool": "gofmt",
}
☁ golang [master] gopls version
golang.org/x/tools/gopls v0.1.7
golang.org/x/tools/gopls@v0.1.7 h1:YwKf8t9h69++qCtVmc2q6fVuetFXmmu9LKoPMYLZid4=
The installed path of go tools for ☁ golang [master] ls ~/workspace/go/bin
dep fillstruct go-symbols gocode godef gogetdoc golangci-lint gometalinter gopkgs gopls goreturns guru revive
dlv go-outline goaddimport gocode-gomod godoctor goimports golint gomodifytags goplay gorename gotests impl Because I have two
And, I add MINE(workspace)
-- golang
-- bin
-- pkg
-- src/issue-32762
-- other-projects |
+1 |
+1 |
I do not think this is not a gopls issue, the problem is that you are not telling VSCode about your GOPATH, you are setting it to
which does not include
to match what it is set to in your shell? |
@ianthehat |
Same problem here, which is preventing me from developing in go using vscode. Base packages aren't being imported (ex. "could not import fmt (no package for import fmt)"). And then structs defined in the same package but a separate file in the same directory don't import (ex. "undeclared name: Listener"). |
@garethjensen: Do you mind opening a separate issue for the problem you're encountering? Please follow the steps on the Troubleshooting guide and include the information requested there. Thanks! |
Yes! I can do that. I found out it was because my go path was different than the default, even though my GOPATH was set correctly... even setting the go tools path to where they were installed didn't work properly. I'll write up something. |
@mrdulin: I'm so sorry for missing this issue and the delayed response. However, I think the issue is that you have the incorrect import path in your program. When you are using modules, the |
If you are in GOPATH mode, make sure to explicitly set I'm going to go ahead and close this issue. Please reopen if this doesn't fix the issue. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Here is the code:
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
The text was updated successfully, but these errors were encountered: