如何使VScode Go在多模块仓库中工作

huangapple go评论77阅读模式
英文:

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

问题

我在一个 Golang 项目中有一个 go.mod 文件,同时我还有另一个嵌入在这个项目中的 Golang 项目,但是 VSCode 似乎无法识别这个嵌入的项目。有没有办法在 VSCode 中处理多个 Golang 项目?

英文:

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?

答案1

得分: 7

你必须使用“文件/添加文件夹到工作区”菜单将模块目录添加到你的工作区。

英文:

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

答案2

得分: 2

使用他人建议的 go.work 时要小心。

只是添加 go.work 并将所有模块添加到 use 中会导致所有模块使用相同的依赖项,这可能不是你想要的。特别是如果你希望在不同的子模块中使用不同版本的依赖项。

如果你不在意这个问题,那没关系,但是如果你在意的话,目前 VSCode 不支持多个模块。

英文:

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.

答案3

得分: 1

你所拥有的是一个多模块工作空间,这在 Go 和 VSCode 中都得到了支持。如果你使用的是 Go 1.17 及更早版本,那么 fix 是 VSCode 的一个配置选项(experimentalWorkspaceModule 设置)。如果你使用的是 Go 1.18+,那么 fix 是使用新的 go.work 文件。

请查看这篇文章以获取更多详细信息:https://github.com/golang/tools/blob/master/gopls/doc/workspace.md

英文:

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

huangapple
  • 本文由 发表于 2021年11月7日 17:43:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/69871301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定