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

gopls was not able to find modules in your workspace. #2534

Closed
sfpotato opened this issue Nov 16, 2022 · 12 comments
Closed

gopls was not able to find modules in your workspace. #2534

sfpotato opened this issue Nov 16, 2022 · 12 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@sfpotato
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • <go version go1.19 linux/amd64>
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.

golang.org/x/tools/gopls v0.10.1
golang.org/x/tools/[email protected] h1:JoHe17pdZ8Vsa24/GUO8iTVTKPh0EOBiWpPop7XJybI=
github.com/BurntSushi/[email protected] h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/google/[email protected] h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/[email protected] h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp/[email protected] h1:7Xs2YCOpMlNqSQSmrrnhlzBXIE/bpMecZplbLePTJvE=
golang.org/x/[email protected] h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
golang.org/x/[email protected] h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/[email protected] h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/[email protected] h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/[email protected] h1:KBm+UwBaO/tdQ35tfGvxH1FUCiXRg4MoTzkznsdeab8=
golang.org/x/[email protected] h1:KaYZQUtEEaV8aVADIHAuYBTjo77aUcCvC7KTGKM3J1I=
honnef.co/go/[email protected] h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=
mvdan.cc/[email protected] h1:avhhrOmv0IuvQVK7fvwV91oFSGAk5/6Po8GXTzICeu8=
mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.19

  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • <1.73.1 x64>
  • Check your installed extensions to get the version of the VS Code Go extension
    • <v0.36.0>
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • <GO111MODULE="on"
      GOARCH="amd64"
      GOBIN=""
      GOCACHE="/root/.cache/go-build"
      GOENV="/root/.config/go/env"
      GOEXE=""
      GOEXPERIMENT=""
      GOFLAGS=""
      GOHOSTARCH="amd64"
      GOHOSTOS="linux"
      GOINSECURE=""
      GOMODCACHE="/root/go/pkg/mod"
      GONOPROXY=""
      GONOSUMDB=""
      GOOS="linux"
      GOPATH="/root/go"
      GOPRIVATE="">

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.
"go.formatTool": "gofmt", "go.lintOnSave": "workspace", "go.lintTool": "golint",

Describe the bug

My project can pass go build, but extension report some error, like
gopls was not able to find modules in your workspace. When outside of GOPATH, gopls needs to know which modules you are working on.

could not import packageName (cannot find package "packageName" in any of /usr/local/go/src packageName (from $GOROOT)
And I use go.work to include all directory contain go.mod to solve multi modules, these error report still exist.

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

@gopherbot gopherbot added this to the Untriaged milestone Nov 16, 2022
@suzmue
Copy link
Contributor

suzmue commented Nov 17, 2022

@sfpotato Could you provide some more information about your setup? What directory do you have open and where are the relevant go.mod and go.work files?

@sfpotato
Copy link
Author

@sfpotato Could you provide some more information about your setup? What directory do you have open and where are the relevant go.mod and go.work files?

I have a project located at /data/project directory like :
截屏2022-11-17 14 35 03
go.work is

use (
        .
        ./stub/proto
)

@findleyr
Copy link
Member

@sfpotato which directory did you open as your workspace?

@suzmue suzmue added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 17, 2022
@findleyr
Copy link
Member

FWIW this does not reproduce for me, using the suggested layout for /data/project.

@sfpotato
Copy link
Author

FWIW this does not reproduce for me, using the suggested layout for /data/project.

Oh. I see, go.work must be locate at workspace root. My workspace was open at the father directory.

@0xdeafcafe
Copy link

0xdeafcafe commented Jan 24, 2023

Sorry for bumping an old issue, but am I right in believing that this means that if your project looks like the following, you can't open the root of the project in VSCode (monorepo) you have to open the project at monorepo/go to get workspace support to work?

github.com/company/monorepo
├─ go/
│  ├─ lib/
│  │  ├─ library-a/
│  │  ├─ library-b/
│  │  ├─ library-c/
│  ├─ svc/
│  │  ├─ service-a/
│  │  ├─ service-b/
│  │  ├─ service-c/
│  ├─ go.work
│  ├─ go.work.sum
├─ js/
│  ├─ lib/
│  ├─ svc/
├─ README.md

@findleyr
Copy link
Member

@0xdeafcafe in that case you could move your go.work to the monorepo directory, or set GOWORK in your environment.

Note that we're trying to fix this. I just published a design to mitigate this configuration problem: golang/go#57979

@0xdeafcafe
Copy link

Ah setting the GOWORK is a great idea, that totally skipped my mind. I'll give that a go tomorrow, cheers!

@CoderJeffrey
Copy link

I believe for some of the people this issue deserve an easier fix.
If you have create a workspace/ and then clone your projects inside the workspace/, you file structure should look like
workspace/<project name> and inside the sub directory of workspace//, you should see the go.mod

What does it mean to have go.mod? It means you are inside the module.

cd workspace/<project name>
code .

These two commands open VSCode in the project inside of a module.
Then you should be able to resolve the warning from VSCode.

@endvvell
Copy link

endvvell commented Nov 1, 2023

Kinda sucks that I need to open my IDE workplace to the directory where the go.work file resides. So when working on multiple project, I need to have multiple windows open instead of just being able to have them all in one. Feels more like an impediment to an efficient workflow.

@findleyr
Copy link
Member

findleyr commented Nov 1, 2023

@svitan0k golang/go#57979 is my main priority for the rest of this year. Please stay tuned.

@iamshreeram
Copy link

@findleyr , Would this (golang/go#57979) fix if my workspace looks like below? golang/go#45184 (comment)

Any suggestion to fix this temporarily ?

@golang golang locked and limited conversation to collaborators Dec 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

8 participants