Go: x/tools/gopls: could not import github.com/google/trillian (no parsed files for package github.com/google/trillian)

Created on 2 Jul 2019  路  2Comments  路  Source: golang/go

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

$ go version
go version go1.12.5 linux/amd64

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"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/home/trillian/go"
GOROOT="/usr/lib/google-golang"
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_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=/tmp/go-build732986152=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Updated VS Code settings per instructions:
https://github.com/Microsoft/vscode-go/wiki/Go-modules-support-in-Visual-Studio-Code
https://github.com/golang/go/wiki/gopls#vscode

{
    "go.useLanguageServer": true,
    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    "gopls": {
        "usePlaceholders": true // add parameter placeholders when completing a function
    },
    "files.eol": "\n", // formatting only supports LF line endings    
}

go.mod:

module github.com/DazWilkin/basic-personality

go 1.12

require (
    github.com/gogo/protobuf v1.2.1
    github.com/google/certificate-transparency-go v1.0.21 // indirect
    github.com/google/trillian v1.2.1
    github.com/grpc-ecosystem/grpc-gateway v1.9.2 // indirect
    golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
    golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect
    golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect
    golang.org/x/text v0.3.2 // indirect
    golang.org/x/tools v0.0.0-20190702152245-7e72c71c505f // indirect
    golang.org/x/tools/gopls v0.1.2-0.20190702152245-7e72c71c505f // indirect
    google.golang.org/grpc v1.21.1
)
GOPATH=$PWD/go
cd go/src/github.com/DazWilkin/basic-personality
GO111MODULE=on go get ./...
code --new-window .

What did you expect to see?

  • No import errors.
  • Ability to navigate to godocs
  • Code completion|help

What did you see instead?

image

And both the non-standard library imports error:

  • could not import github.com/google/trillian (no parsed files for package github.com/google/trillian)
  • could not import google.golang.org/grpc (no parsed files for package google.golang.org/grpc)

If, instead, I import old-school:

GO111MODULE=off go get ./...

It works.

I suspect I'm missing something either with this solution or with Go Modules (or both) but I'm expecting to be able to use the Go Modules (GO111MODULE=on) approach with this solution.

Is it because I'm still working under ${GOPATH} and have it set?

Perhaps related to #32762 ?

FrozenDueToAge gopls

Most helpful comment

You will need to set

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

to work with modules in VSCode.

All 2 comments

You will need to set

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

to work with modules in VSCode.

Yes, that works.

I changed the setting, deleted the ${GOPATH}/src/github.com/google/trillian, reloaded and no more import error.

Thank you!!

Was this page helpful?
0 / 5 - 0 ratings