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: go.mod is not detected #38397

Closed
mytea003 opened this issue Apr 12, 2020 · 8 comments
Closed

x/tools/gopls: go.mod is not detected #38397

mytea003 opened this issue Apr 12, 2020 · 8 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mytea003
Copy link

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

$ go version
go version go1.13.8 windows/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
set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\kernel\AppData\Local\go-build
set GOENV=C:\Users\kernel\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\kernel\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,https://goproxy.io,direct
set GOROOT=D:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
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\kernel\AppData\Local\Temp\go-build419348166=/tmp/go-build -gno-record-gcc-switches

What did you do?

What did you expect to see?

Vscdoe in Windows can see the function information in third-party packages.

What did you see instead?

I confirm that I am using modules and in the directory go.mod.
image

@andybons andybons changed the title go.mod error x/tools/gopls: go.mod is not detected Apr 13, 2020
@gopherbot gopherbot added this to the Unreleased milestone Apr 13, 2020
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 13, 2020
@gopherbot
Copy link

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 Issues related to the Go language server, gopls. label Apr 13, 2020
@andybons
Copy link
Member

Please post the literal text instead of an image, as the latter makes it much more difficult to read. The error text in the image states:

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.

However the file tree shows a go.mod file next to main.go

@stamblerre
Copy link
Contributor

@mytea003: It looks like you've opened a directory above the go.mod file, but gopls currently requires you to open your module as the root directory. To work around this, you can use VS Code's File -> Add Folder to Workspace feature for the officeCode folder. We are working on making this work better for gopls/v0.5.0.

@mytea003
Copy link
Author

@mytea003: It looks like you've opened a directory above the go.mod file, but gopls currently requires you to open your module as the root directory. To work around this, you can use VS Code's File -> Add Folder to Workspace feature for the officeCode folder. We are working on making this work better for gopls/v0.5.0.

How do I do it step by step?As you can see from the picture, I have added the project to the workspace.

@stamblerre
Copy link
Contributor

I think the folder is a subdirectory of your top-level workspace directory. You need to add folder explicitly to the workspace, which can be done by clicking the "File" menu and then selecting "Add Folder to Workspace". You can then select the officeCode folder. Once it's added, gopls should work as expected.

@mytea003
Copy link
Author

I think the folder is a subdirectory of your top-level workspace directory. You need to add folder explicitly to the workspace, which can be done by clicking the "File" menu and then selecting "Add Folder to Workspace". You can then select the officeCode folder. Once it's added, gopls should work as expected.


I see. After testing, we got the expectation.But I thought it was strange.Adding the current go.mod directory directly to the workspace is expected.But according to my previous method, there are certain items that can also get the expected (hover message), so is this a BUG of gopls?

@stamblerre
Copy link
Contributor

That warning is meant to indicate that all of the features of gopls won't necessarily work, but some may, which is probably why you were seeing hovers. We are working on fixing this for the next release of gopls (https://github.com/golang/go/milestone/138), so the user experience will be smoother then. I'll close this issue since we're working on it.

@mytea003
Copy link
Author

That warning is meant to indicate that all of the features of gopls won't necessarily work, but some may, which is probably why you were seeing hovers. We are working on fixing this for the next release of gopls (https://github.com/golang/go/milestone/138), so the user experience will be smoother then. I'll close this issue since we're working on it.

thank you.Thank you again.

@golang golang locked and limited conversation to collaborators Apr 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants