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

VSCode-Go: improper warning about project root #39845

Closed
xrfang opened this issue Jun 25, 2020 · 3 comments
Closed

VSCode-Go: improper warning about project root #39845

xrfang opened this issue Jun 25, 2020 · 3 comments

Comments

@xrfang
Copy link

xrfang commented Jun 25, 2020

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

$ go version

go version go1.14 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

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xrfang/.cache/go-build"
GOENV="/home/xrfang/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xrfang/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/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-build145582574=/tmp/go-build -gno-record-gcc-switches"

What did you do?

My Go projects usually have the following directory structure:

/

  • Makefile
  • bin/ //compiled binaries go here
  • conf/ //for possible configurations
  • docs/
  • resources/ //static resources, e.g. images, html / css / js files
  • src/ //go source code, including go.mod and go.sum, may have subdirectories

What did you expect to see?

I expect vscode-go to analyze code structrue and assist editing smoothly.

What did you see instead?

It often add warnings about code errors here and there, which are abosolutely correct, (compiles ok), and consistantly shows warning:

You are neither in a module nor in your GOPATH. If you are using modules, please open your editor at the directory containing the go.mod. If you believe this warning is incorrect, please file an issue: https://github.com/golang/go/issues/new.

I would suggest the vscode-go plugin to add an option like go.source.root, which defaults to the project root, but may be changed, such as src in my case, so that the tools can work as expected.

@stamblerre
Copy link
Contributor

This is a known issue, and one that we are currently working on addressing in gopls (before it reaches v1.0). In the meantime, I recommend using VS Code's "Add Folder to Workspace" feature, which allows you to open your directory at the root, but to also have gopls still work on your subdirectory.

@xrfang
Copy link
Author

xrfang commented Jun 26, 2020

Good to know. I'd like to propose a better option than adding a configuration, just let gopls to find where is go.mod located, and use that directory and its project root.

@xrfang
Copy link
Author

xrfang commented Jun 26, 2020

I also found that by using your suggestion of adding folder to project workspace, I will have to deal with the .gitignore file, otherwise, vscode will show a LOT of changed files under pkg/ which was already ignored.

@golang golang locked and limited conversation to collaborators Jun 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants