Skip to content
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: does not conform to Go documentation on non-scalar GOPATH #36120

Closed
maverickwoo opened this issue Dec 13, 2019 · 3 comments
Closed

Comments

@maverickwoo
Copy link

@maverickwoo maverickwoo commented Dec 13, 2019

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

$ go version
go version go1.13.4 darwin/amd64

Does this issue reproduce with the latest release?

I am currently one patch level behind. But based on the source code on current master shown below, I believe it will reproduce with the latest release.

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

go env Output
$ go env | sed s/$USER/user/g
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/user/go:/Users/user/go-work"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/local/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/local/lib/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="/usr/bin/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/q_/jc67mj41687gcm21gq1z853m0000gn/T/go-build770602489=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

VSCode installed gopls for me, and it shows an error message when I get to a go file that is (i) in my GOPATH but (ii) imports an unsatisfied dependency. For example, try:

package main

import "missingpackagehere"

The error message is:

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.

I believe this is because my GOPATH is a colon-separated string:

GOPATH="/Users/user/go:/Users/user/go-work"

This type of non-scalar GOPATHs is supported in Go 1 according to the current Go documentation https://golang.org/cmd/go/#hdr-GOPATH_environment_variable:

The GOPATH environment variable lists places to look for Go code. On Unix, the value is a colon-separated string. On Windows, the value is a semicolon-separated string. On Plan 9, the value is a list.

However, this line of code at current master does not appear to support such non-scalar GOPATHs. https://github.com/golang/tools/blob/0f69de236bb709847e215a792a40aaee1cba60d9/internal/lsp/source/errors.go#L50:

inGopath := strings.HasPrefix(uri.Filename(), filepath.Join(gopath, "src"))

What did you expect to see?

I expect gopls to support GOPATHs allowed by the Go documentation and therefore not return the error message shown above.

What did you see instead?

I saw the error message shown above.

@gopherbot gopherbot added this to the Unreleased milestone Dec 13, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 13, 2019

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.

@gopherbot gopherbot added the gopls label Dec 13, 2019
@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Dec 13, 2019

The filepath.SplitList function should be useful for resolving this issue.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 13, 2019

Change https://golang.org/cl/211304 mentions this issue: internal/lsp/source: fix error message for multiple GOPATHs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.