我遇到了可能是Gopls語(yǔ)言服務(wù)器的問(wèn)題:在VSCode中使用帶有Go擴(kuò)展的Go模塊時(shí),我的所有外部包導(dǎo)入語(yǔ)句都被標(biāo)記為不正確。以下是我到目前為止所做的: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}[...]當(dāng)將鼠標(biāo)懸停在導(dǎo)入語(yǔ)句上時(shí),我收到錯(cuò)誤: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))"看起來(lái)它正在尋找沒(méi)有Go模塊的軟件包,即使它們現(xiàn)在被存儲(chǔ)在其中。是否有一些關(guān)于VSCode / Gopls的配置文件,或者我做錯(cuò)了什么?我以前從未使用過(guò)Go / Go模塊。go\srcgo\pkg\mod盡管出現(xiàn)linting錯(cuò)誤,導(dǎo)入和代碼實(shí)際上仍然可以工作,但是該錯(cuò)誤會(huì)禁用所有自動(dòng)完成功能,因此僅忽略它不是可行的解決方案。我重新安裝到VSCode的Go擴(kuò)展,并嘗試重新啟動(dòng)語(yǔ)言服務(wù)器,但這并沒(méi)有改變?nèi)魏螙|西。該錯(cuò)誤消息出現(xiàn)在每個(gè)目錄中的所有外部包導(dǎo)入語(yǔ)句中。我很樂(lè)意得到一些建議。
- 1 回答
- 0 關(guān)注
- 97 瀏覽
添加回答
舉報(bào)
0/150
提交
取消