Banon
Banon

Reputation: 63

How to make VScode Go work in a Multi-Module Repo

I have a go.mod file in a golang project, and I also have another go project which is embedded in this project, but vscode does not seem to recognize this embedded project. Is there a way to work with multiple golang project with vscode?

Upvotes: 5

Views: 10388

Answers (3)

Karel Bílek
Karel Bílek

Reputation: 37658

Be careful when using go.work which others suggest.

Just adding go.work and adding all modules to use will cause all your modules use the same dependencies, which might not be what you want. Especially if you want to have different versions of dependencies at different submodules.

It’s fine if you don’t care about that, but if you do, VSCode does not support multiple modules currently.

Upvotes: 6

Gustavo Coelho
Gustavo Coelho

Reputation: 1010

What you have is a multi-module workspace and this is supported by Go and VSCode. If you are using Go 1.17 and earlier then fix is a configuration option on VSCode (experimentalWorkspaceModule setting). If you have Go 1.18+ then fix is using the new go.work file.

Check this article for more details https://github.com/golang/tools/blob/master/gopls/doc/workspace.md

Upvotes: 1

Cadet
Cadet

Reputation: 354

You have to add the modules directory to your workspace using the "file / add folder to work space" menu.

Upvotes: 13

Related Questions