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
Milestone

Comments

@mytea003
Copy link

@mytea003 mytea003 commented Apr 12, 2020

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 label Apr 13, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Apr 13, 2020

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 Apr 13, 2020
@andybons
Copy link
Member

@andybons andybons commented Apr 13, 2020

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

@stamblerre stamblerre commented Apr 13, 2020

@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 mytea003 commented Apr 13, 2020

@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

@stamblerre stamblerre commented Apr 13, 2020

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

@mytea003 mytea003 commented Apr 13, 2020

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

@stamblerre stamblerre commented Apr 13, 2020

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.

@stamblerre stamblerre closed this Apr 13, 2020
@mytea003
Copy link
Author

@mytea003 mytea003 commented Apr 13, 2020

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.

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
4 participants
You can’t perform that action at this time.