vscode 打開多個項目報錯
VSCode 打開多個 Golang 項目
如果你的項目結構如下這樣的話 VSCode 在你的代碼上標紅。
但事實上你的代碼並沒有錯誤,並且可以正常的運行和調試,靜靜是在代碼上會有一個紅色的波浪線。如果你將鼠標懸浮在波浪線上則會提示你:
gopls was not able to find modules in your workspace.
When outside of GOPATH, gopls needs to know which modules you are working on.
You can fix this by opening your workspace to a folder inside a Go module, or
by using a go.work file to specify multiple modules.
See the documentation for more information on setting up your workspace:
https://github.com/golang/tools/blob/master/gopls/doc/workspace.md.
在給出的聯接中有解決辦法:
# 創建一個工作空間
go work init
# 將項目添加到工作空間當中
go work use server client