Go: x/tools/gopls: go modules in subfolders of VSCode folder are not recognized

Created on 13 Mar 2020  Β·  6Comments  Β·  Source: golang/go

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

$ go version
go version go1.13.4 linux/amd64
golang.org/x/tools/gopls v0.3.3
    golang.org/x/tools/[email protected] h1:mTFqRDJQmpSsgDDWvbtGnSva1z9uX2XcDszSWa6DhBQ=

Does this issue reproduce with the latest release?

Unknown, as a golang 1.14 package is not available for Ubuntu Xenial.

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

go env Output

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/marc/.cache/go-build"
GOENV="/home/marc/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/mnt/c/Users/Marc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build013358927=/tmp/go-build -gno-record-gcc-switches

What did you do?

I am using a Go project folder structure like this:

β”œβ”€β”€ npiperelay
β”‚   β”œβ”€β”€ LICENSE
β”‚   β”œβ”€β”€ npiperelay.go
β”‚   β”œβ”€β”€ overlappedfile.go
β”‚   β”œβ”€β”€ README.md
β”‚   └── scripts
β”‚       β”œβ”€β”€ docker-relay
β”‚       β”œβ”€β”€ gpg-relay
β”‚       β”œβ”€β”€ serial-relay
β”‚       └── vmserial-connect
└── wsl-ssh-pageant
    β”œβ”€β”€ assets
    β”‚   └── icon.ico
    β”œβ”€β”€ assets.go
    β”œβ”€β”€ azure-pipelines.yml
    β”œβ”€β”€ build.ps1
    β”œβ”€β”€ go.mod
    β”œβ”€β”€ go.sum
    β”œβ”€β”€ LICENSE
    β”œβ”€β”€ main.go
    β”œβ”€β”€ Readme.md

As you can see there is a go.mod file in the wsl-ssh-pageant project.

In Visual Studio Code I am opening the folder go-projects instead of the individual subfolders for reach project in order to quickly jump between them. You could think of it as my mono-repo-like approach with VSCode even though the individual projects are individual repos.

What did you expect to see?

I expected gopls to recognize the go.mod file in the wsl-ssh-pageant project.

What did you see instead?

Instead I am getting this error message:

You are neither in a module nor in your GOPATH. Please see https://github.com/golang/go/wiki/Modules for information on how to set up your Go project.

Tools gopls

Most helpful comment

gopls currently doesn't support editing opening directories that are above a module. We will be working on fixing this for gopls/v0.5.0. A work-around is to add the root of the module to your workspace - in VS Code, that can be done by navigating to File -> Add Folder to Workspace. Sorry about the inconvenience, and we hope to have this fixed soon.

All 6 comments

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

gopls currently doesn't support editing opening directories that are above a module. We will be working on fixing this for gopls/v0.5.0. A work-around is to add the root of the module to your workspace - in VS Code, that can be done by navigating to File -> Add Folder to Workspace. Sorry about the inconvenience, and we hope to have this fixed soon.

@stamblerre Thanks for your feedback, but why is this issue closed if it is not already solved yet?

We will be working on fixing this for gopls/v0.5.0.

This is an issue we are already aware of, and we have a number of issues related to it in the gopls/v0.5.0 milestone, so I closed this as a duplicate.

It’s been almost 3 months, and it’s still not fixed.

Looks like there are some updates on this topic over here: https://github.com/golang/go/issues/32394

Was this page helpful?
0 / 5 - 0 ratings