我遇到了可能是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 关注
- 76 浏览
添加回答
举报
0/150
提交
取消