gopls: no metadata import error

Created on 24 May 2019  路  22Comments  路  Source: golang/go

I am using the latest version of gopls in vscode. On this import:

import . "github.com/onsi/gomega/gstruct" 
I get the error: `could not import github.com/onsi/gomega/gstruct (no metadata for github.com/onsi/gomega/gstruct) LSP` Importing the parent package works fine
import . "github.com/onsi/gomega" 
### What version of Go are you using (`go version`)?
$ go version
go version go1.12.1 darwin/amd64
$ gopls version
golang.org/x/tools/cmd/gopls
    golang.org/x/[email protected] h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=

Does this issue reproduce with the latest release?

Yes

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

go env Output

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nilswerner/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nilswerner/Code/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.1/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/rw/0_ws_7zx40q15hshvt40bdlc0000gn/T/go-build110599491=/tmp/go-build -gno-record-gcc-switches -fno-common"

FrozenDueToAge WaitingForInfo gopls

Most helpful comment

Same exact problem here. killall gopls fixed it for me 馃槖

All 22 comments

/cc @stamblerre

Does this issue persist or does it resolve itself after some amount of time?

I'm able to import this package without problems - can you share your gopls logs for this error? They can be found by going to "View: Debug Console" -> "Output" -> "Tasks" -> "gopls".

I got the same problem. I already checked Use Language Server. The VSCode shows the tip as below even though I added the package in go.mod file.
could not import github.com/stretchr/testify/mock (no metadata for github.com/stretchr/testify/mock) LSP
Does LSP need to access Google Server which may not available in some countries?
灞忓箷蹇収 2019-05-30 涓嬪崍5 02 54

@jiyeyuran: No, gopls should work fine in all countries. Can you confirm that this code compiles?

I run into this issue all the time, I have to close the editor and re-open it (don't know how to reload the LSP server any other way) and it will basically go away until I do the next import in which case it will do it again.

I am using neovim with autozimu/LanguageClient-neovim.

After I restart the error will disappear, and then reappear later.

@stamblerre The code can compile normally. The problem also happens on std library. The error disappear after I restart.
灞忓箷蹇収 2019-05-31 涓婂崍9 39 01
灞忓箷蹇収 2019-05-31 涓婂崍9 39 36

I got the same problem when I use vscode-go

image

image

functions in strings can autocomplete, functions in net/http not working at all. It looks like sub-package can not imported.

gopls log info

[Info  - 涓嬪崍1:54:35] #### Build info

golang.org/x/tools/cmd/gopls
    golang.org/x/[email protected] h1:vBgi/AgEje1rNScpWGJqe+RPHHZvBqrk9UH+LOXWN6Q=
    golang.org/x/[email protected] h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=


#### Go info

go version go1.12.5 windows/amd64

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\will\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\code\go
set GOPROXY=https://goproxy.io
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=d:\code\go\src\github.com\mgxian\tdd-practice\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\will\AppData\Local\Temp\go-build575106766=/tmp/go-build -gno-record-gcc-switches

[Error - 涓嬪崍1:55:42] Request textDocument/codeAction failed.
  Message: d:\code\go\src\github.com\mgxian\tdd-practice\task3\args\args_test.go:7:2: invalid import path: ""
  Code: 0 
[Error - 涓嬪崍1:55:45] Request textDocument/codeAction failed.
  Message: d:\code\go\src\github.com\mgxian\tdd-practice\task3\args\args_test.go:7:2: invalid import path: ""
  Code: 0 
[Error - 涓嬪崍1:55:54] Request textDocument/codeAction failed.
  Message: d:\code\go\src\github.com\mgxian\tdd-practice\task3\args\args_test.go:8:2: invalid import path: ""
  Code: 0 
[Error - 涓嬪崍1:55:54] Request textDocument/codeAction failed.
  Message: d:\code\go\src\github.com\mgxian\tdd-practice\task3\args\args_test.go:8:2: invalid import path: ""
  Code: 0 
[Error - 涓嬪崍1:56:02] Request textDocument/hover failed.
  Message: no identifier found
  Code: 0 

@NilsJPWerner: And the error reappears even if you have not just added the imports? That is, you've had the same import in your file for a while and then the error comes back?

Can the other people who are experiencing this error also attach their logs?

Same exact problem here. killall gopls fixed it for me 馃槖

Thanks for the reports. I think the issue is that we don't re-run go/packages.Load if an import has gone from unresolved to resolved, only if the list of imports has changed. I will aim to have a fix ASAP.

Change https://golang.org/cl/180537 mentions this issue: internal/lsp: track missing imports, re-running packages.Load

Does this issue fixed? With this bug I can not use vscode write go any more! I feel so bad!

@mgxian - Please be patient. The issue will be closed when this is fixed.

@mgxian: You can also disable the language server by go.useLanguageServer: false. In the case of your error message, could you provide some additional logs? It seems like the error in your screenshots don't actually correspond to the errors in the logs.

This is my test code, when I import package "fmt". I got the follow error.

image

image

This is my gopls log

[Info  - 涓婂崍8:16:19] Build info
----------
golang.org/x/tools/cmd/gopls
    golang.org/x/[email protected] h1:fTfk6GjmihJbK0mSUFgPPgYpsdmApQ86Mcd4GuKax9U=
    golang.org/x/[email protected] h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=

Go info
-------
go version go1.12 windows/amd64

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\will\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\code\go
set GOPROXY=https://goproxy.io
set GORACE=
set GOROOT=C:\Users\will\scoop\apps\go\current
set GOTMPDIR=
set GOTOOLDIR=C:\Users\will\scoop\apps\go\current\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=d:\code\go\src\github.com\mgxian\tdd-practice\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\will\AppData\Local\Temp\go-build439364714=/tmp/go-build -gno-record-gcc-switches

[Error - 涓婂崍8:17:18] Request textDocument/codeAction failed.
  Message: d:\code\go\src\github.com\mgxian\tdd-practice\task3\hello\test.go:3:1: expected declaration, found imp
  Code: 0 
[Error - 涓婂崍8:17:19] Request textDocument/codeAction failed.
  Message: d:\code\go\src\github.com\mgxian\tdd-practice\task3\hello\test.go:5:1: expected 'STRING', found 'func'
  Code: 0 
[Info  - 涓婂崍8:17:20] no signature help for file:///d:/code/go/src/github.com/mgxian/tdd-practice/task3/hello/test.go:2:8 : cannot find an enclosing function
[Info  - 涓婂崍8:17:20] no signature help for file:///d:/code/go/src/github.com/mgxian/tdd-practice/task3/hello/test.go:3:1 : cannot find an enclosing function
[Error - 涓婂崍8:17:22] Request textDocument/codeAction failed.
  Message: d:\code\go\src\github.com\mgxian\tdd-practice\task3\hello\test.go:4:2: invalid import path: ""
  Code: 0 

When I reload the vscode window, the error disappear.

image

Every time I import a new package, The error will appear, and autocomplete is not work on the new package, When I reload the vscode window the error disappear and autocomplete work well. So what I should do to avoid this.

image

The CL I submitted above should address this problem. Can you sync to the latest gopls and see if it helps?

Change https://golang.org/cl/181578 mentions this issue: internal/lsp: fix check for changed imports

Thanks @stamblerre It works !

It seems the latest version of gopls resolved at least some of the problems for at least some of the people who reported issues here.

Is there anyone who reported a problem above that is still seeing the same problem with the latest version of gopls?

If you are still seeing the same problem , would you be able to supply the logs and other diagnostic information suggested in the troubleshooting section here:

https://github.com/golang/go/wiki/gopls

The issue no longer shows with this fix for me. Thanks! :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bradfitz picture bradfitz  路  3Comments

natefinch picture natefinch  路  3Comments

rakyll picture rakyll  路  3Comments

longzhizhi picture longzhizhi  路  3Comments

ajstarks picture ajstarks  路  3Comments