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

Enable working on multi-module project without workspace #3007

Closed
cletter7 opened this issue Oct 12, 2023 · 6 comments
Closed

Enable working on multi-module project without workspace #3007

cletter7 opened this issue Oct 12, 2023 · 6 comments

Comments

@cletter7
Copy link

Is your feature request related to a problem? Please describe.
I am working on a monorepo with a bunch of go modules:

root
└── plugins
    └── plugin1
        ├── main.go
        └── go.mod
    └── plugin2
        ├── main.go
        └── go.mod
    ...

And in VS Code I get errors in the import section of the Go files:

could not import github.com/.../... (cannot find package "github.com/.../..." in GOROOT or GOPATH)

image

Also, VS Code fails to go to the definition or show type on hover when working with the go files inside modules.

And I intentionally don't want to add workspace to the repo root. That's because the modules in the monorepo depend on different versions of same packages and there is no intention to keep those dependencies in sync. But if I enable go workspace then all those modules start to use the same version of the dependecy even though go.mod specifies another version. According to this comment this is by design:

By design, a workspace can have only one set of consistent dependencies. (If you want to work with the dependencies of each module separately, don't combine them in a workspace.)

Describe the solution you'd like
I'd like VS Code to be able to work with modules even though they are not located in a root of the repo and even though there is no workspace (just like it works with frontend packages).

Describe alternatives you've considered

  • Considered adding workspace but this doesn't work in my case.
  • Considered opening modules folder as separate folders in VS Code but this is not a convenient way of working with the monorepo.
@gopherbot gopherbot added this to the Untriaged milestone Oct 12, 2023
@adonovan
Copy link
Member

I think this feature comes under the "zero-config gopls" umbrella, on which work is underway.

@findleyr

@cletter7
Copy link
Author

cletter7 commented Oct 19, 2023

@adonovan @findleyr Is there a way to work this around at the moment until the proper solution arrives?
Maybe I can add some additional config to make VS Code handle those modules properly?

@findleyr
Copy link
Member

@cletter7 you can add additional workspace folders manually in VS Code.

I expect zero-config gopls to land in Q4 of this year (I'm resuming work on it as soon as [email protected] goes out).

@cletter7
Copy link
Author

@findleyr could you please share more details on:

you can add additional workspace folders manually in VS Code

I have a bunch of modules in nested folders (not in the root folder of the repo) and I don't have a root go.work file. Where should I add those additional workspaces for the VS Code to work properly?

@findleyr
Copy link
Member

@cletter7 you can set up vs code to have a workspace folder for each module. There is some documentation for this approach here: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md#multiple-workspace-folders

@findleyr
Copy link
Member

findleyr commented Nov 2, 2023

I'm going to close this as a dupe of golang/go#57979, which is one of my main priorities for the rest of the year. Please stay tuned!

@findleyr findleyr closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
@golang golang locked and limited conversation to collaborators Nov 1, 2024
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

4 participants