我遇到了可能是Gopls語言服務器的問題:在VSCode中使用帶有Go擴展的Go模塊時,我的所有外部包導入語句都被標記為不正確。以下是我到目前為止所做的:Inside my GOPATH/src/github.com/Kozie1337/projectname:跑go mod init github.com/Kozie1337/projectname跑go get -u github.com/gorilla/muxInside go.main:package mainimport ( "log" "net/http" "github.com/gorilla/mux" // This is being marked as wrong with the err. msg. down below)func main() { r := mux.NewRouter() // This actually works, even though the go linter says that mux isn't imported http.ListenAndServe(":9000", r)) // server starts too with mux routes}[...]當將鼠標懸停在導入語句上時,我收到錯誤:github.com/gorilla/muxcould not import github.com/gorilla/mux (cannot find package "github.com/gorilla/mux" in any of C:\Program Files\Go\src\github.com\gorilla\mux (from $GOROOT) C\src\github.com\gorilla\mux (from $GOPATH) \Users\max\go\src\github.com\gorilla\mux (from $GOPATH))"看起來它正在尋找沒有Go模塊的軟件包,即使它們現在被存儲在其中。是否有一些關于VSCode / Gopls的配置文件,或者我做錯了什么?我以前從未使用過Go / Go模塊。go\srcgo\pkg\mod盡管出現linting錯誤,導入和代碼實際上仍然可以工作,但是該錯誤會禁用所有自動完成功能,因此僅忽略它不是可行的解決方案。我重新安裝到VSCode的Go擴展,并嘗試重新啟動語言服務器,但這并沒有改變任何東西。該錯誤消息出現在每個目錄中的所有外部包導入語句中。我很樂意得到一些建議。
- 1 回答
- 0 關注
- 98 瀏覽
添加回答
舉報
0/150
提交
取消