Closed mrdulin closed 4 years ago
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.
@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
"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
@marco-m: I have not yet had time to investigate this issue, but in the case of https://github.com/golang/go/issues/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.
Thanks @stamblerre for the explanation :-)
@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
.
@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 gopls
☁ 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 go.mod
file). In your case, that would be the golang
directory.
If you are still seeing these errors, can you cd
into the golang
directory and run gopls -rpc.trace -v check path/to/file.go
?
@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 "serverless-functions-go/infrastructure/config"
, got below error:
could not import serverless-functions-go/infrastructure/config (no parsed files for package serverless-functions-go/infrastructure/config)LSP
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 go list -e -json -compiled -test /Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/infrastructure/config
?
@stamblerre
☁ 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 GO111MODULE=on
and then try running both the gopls check
and the go list
commands again? I wonder if something strange is happening because you have have a go.mod
file inside of your $GOPATH
directory.
☁ golang [master] ⚡ export GO111MODULE=on
☁ golang [master] ⚡ echo $GO111MODULE
on
gopls check
☁ 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)
go list
☁ 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 serverless-functions-go
? If so, I could try it out myself and check (it's currently an empty directory).
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, I use spacemacs in macOS
go version go1.12.7 darwin/amd64
GOARCH="amd64"
GOBIN="/Users/alan/work/goprojects/bin"
GOCACHE="/Users/alan/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/alan/work/goprojects"
GOPROXY="https://goproxy.io"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/alan/work/helloworld/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/yn/p3b3s8lx3jzfnslp_pt2b04h0000gn/T/go-build278172779=/tmp/go-build -gno-record-gcc-switches -fno-common"
.
├── api
│ └── apis.go
├── go.mod
└── server.go
import (
"fmt"
api "helloworld/api"
)
LSP: could not import helloworld/api (no parsed files for package helloworld/api) (lsp-ui)
lsp-log
Found the following clients for /Users/alan/work/helloworld/server.go: (server-id gopls, priority 0), (server-id go-bingo, priority -1), (server-id go-ls, priority -2)
The following clients were selected based on priority: (server-id gopls, priority 0)
25.917609ms for GOROOT= GOPATH=/Users/alan/work/goprojects GO111MODULE=auto PWD=/Users/alan/ go "list" "-m" "-json" "all", stderr: <<go list -m: not using modules
>>
32.203691ms for GOROOT= GOPATH=/Users/alan/work/goprojects GO111MODULE=auto PWD=/Users/alan/ go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>
21.685817ms for GOROOT= GOPATH=/Users/alan/work/goprojects GO111MODULE=auto PWD=/Users/alan/ go "env" "GOPATH", stderr: <<>>
Build info
----------
golang.org/x/tools/gopls v0.1.3
golang.org/x/tools/gopls@(devel)
golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/tools@v0.0.0-20190723021737-8bb11ff117ca => ../
golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
Go info
-------
go version go1.12.7 darwin/amd64
GOARCH="amd64"
GOBIN="/Users/alan/work/goprojects/bin"
GOCACHE="/Users/alan/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/alan/work/goprojects"
GOPROXY="https://goproxy.io"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/yn/p3b3s8lx3jzfnslp_pt2b04h0000gn/T/go-build089164657=/tmp/go-build -gno-record-gcc-switches -fno-common"
28.497661ms for GOROOT= GOPATH=/Users/alan/work/goprojects GO111MODULE=auto PWD=/Users/alan/ go "list" "-m" "-json" "all", stderr: <<go list -m: not using modules
>>
29.824497ms for GOROOT= GOPATH=/Users/alan/work/goprojects GO111MODULE=auto PWD=/Users/alan/ go "env" "GOPATH", stderr: <<>>
35.87288ms for GOROOT= GOPATH=/Users/alan/work/goprojects GO111MODULE=auto PWD=/Users/alan/ go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/alan/work/helloworld", stderr: <<>>
356.050461ms for GOROOT= GOPATH=/Users/alan/work/goprojects GO111MODULE=auto PWD=/Users/alan/ go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/alan/work/helloworld/server.go", stderr: <<>>
go/packages.Load
package = command-line-arguments
files = [/Users/alan/work/helloworld/server.go]
go/packages.Load
packages = 1
no signature help
At = {0xc000220140 11475 11475}
Failure = cannot find an enclosing function
no signature help
At = {0xc000220140 11500 11500}
Failure = cannot find an enclosing function
Buffer switched - ignoring reponse. Method textDocument/hover
28.497661ms for GOROOT= GOPATH=/Users/alan/work/goprojects GO111MODULE=auto PWD=/Users/alan/ go "list" "-m" "-json" "all", stderr: <<go list -m: not using modules
So I think I had a similar problem. What I noticed in the above log line was that the PWD
was 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.
@alexrudd First of all, thank you very much for your advice, but I don't seem to be able to repeat your operation. I don't even know how to empty the workspace. I use spacemacs. PWD is a parameter in .spacemacs.env
. My instinct tells me that it is best not to try to change it. I will continue to look for other ways to solve this problem. Question, good luck to me.
@ihaveadrame sorry, my solution applies specifically to vscode. I didn't see you mention spacemacs!
No problem at all, I will do this right away.
After update some golang tools, I found this issue solved:
set GO111MODULE=ON
go get -u -v github.com/mdempsky/gocode
go get -u -v github.com/ramya-rao-a/go-outline
go 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.
@Jiffies-Duke: Those tools are actually not related to gopls
at all. The only command that gopls
relies on is the go
command. I'm glad you were able to resolve your issue, however.
I have the same problem, I use vscode in linux mint
x/tools/gopls: could not import github.com/XXX (no parsed files for package XXXXX.....
Version: 1.38.1 Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0 Date: 2019-09-11T13:30:08.229Z Electron: 4.2.10 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0 OS: Linux x64 4.15.0-20-generic
y@liuhy:~$ gopls version golang.org/x/tools/gopls v0.1.5 golang.org/x/tools/gopls@v0.1.5 h1:bfyquCQT+XBur/qfeq64IXf1fv54Kh4y6/tDWA31M3g=
liuhy@liuhy:~/fabric-examples$ env | grep GO GO111MODULE=on GOPATH=/home/liuhy/work GOROOT=/usr/local/go GOBIN=/home/liuhy/work/bin
set GO111MODULE=ON gopath bin install tools: liuhy@liuhy:~/work/bin$ ls bin gobin godef goimports gomodifytags goplay goreturns govendor src dlv gocode godoctor golint go-outline gopls go-symbols guru ss fillstruct gocode-gomod gogetdoc.bak golsp gopkgs gorename gotests impl swag
@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
main.go
:
package main
import (
"fmt"
"issue-32762/domain/models"
)
func main() {
user := models.User{UserID: 1}
fmt.Printf("user=%v\n", user)
}
user.go
:
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 gopls
tool:
[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 golang
project to GoLand
IDE, it can jump to the models
directory correctly when I hover and click the import statement.
Please fix this issue. I prefer using Vscode rather than GoLand
IDE for programming
go version
:
☁ golang [master] go version
go version go1.12.6 darwin/amd64
go env
:
☁ 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"
vscode-go-extension
user settings:
{
"go.languageServerFlags": [
"-rpc.trace",
"serve",
"--debug=localhost:6060"
],
"go.toolsGopath": "~/workspace/go",
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.useLanguageServer": true,
"go.formatTool": "gofmt",
}
gopls
version:
☁ golang [master] gopls version
golang.org/x/tools/gopls v0.1.7
golang.org/x/tools/gopls@v0.1.7 h1:YwKf8t9h69++qCtVmc2q6fVuetFXmmu9LKoPMYLZid4=
vscode-go
version: 0.11.7
The installed path of go tools for vscode-go
is:
☁ 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 GOPATH
,
/Users/ldu020/workspace/go/bin
is for installing global go tools binary files
/Users/ldu020/workspace/github.com/mrdulin/golang
is for my own projects. /bin
is for storing my own project binary files
And, I add golang
project to vscode workspace, not golang/src/serverless-functions-go
or golang/src/issue-32762
, for GoLand
IDE, the root project is golang
as well.
MINE(workspace)
-- golang
-- bin
-- pkg
-- src/issue-32762
-- other-projects
+1 I am facing the same issue as described by @mrdulin in the previous comment here https://github.com/golang/go/issues/32762#issuecomment-541650371
+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
"go.toolsGopath": "~/workspace/go",
which does not include /Users/ldu020/workspace/github.com/mrdulin/golang
and so all tools run by VSCode cannot find any of your code, including gopls
Also I am suprised that works at all anyway, ~
is a shell feature, I did not thing VSCode would expand it.
What happens if you set
"go.toolsGopath": "/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang",
to match what it is set to in your shell?
@ianthehat "go.toolsGopath"
this configuration was added after this issue happened.
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!
@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 models
package should be imported as github.com/mrdulin/golang/src/issue-32762/domain/models
, not issue-32762/domain/models
.
If you are in GOPATH mode, make sure to explicitly set GO111MODULE=off
, since you have a go.mod
in this directory. Then, with your GOPATH set to the github.com/mrdulin/golang
directory, the current import path should work fine.
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