Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: cannot find module providing package {x} module lookup disabled by GOPROXY=off #56717

Open
angshumanHalder opened this issue Nov 12, 2022 · 0 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@angshumanHalder
Copy link

angshumanHalder commented Nov 12, 2022

ATTENTION: Please answer these questions BEFORE submitting your issue. Thanks!

What did you do?

created a new project with go mod init [project]

go get -u github.com/go-chi/chi/v5

used it inside main.go
Screenshot 2022-11-12 at 4 34 49 PM

What did you expect to see?

gopls shouldn't show error

What did you see instead?

could not import github.com/go-chi/chi/v5 (no required module provides package "github.com/go-chi/chi/v5")

go env

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/angshumanhalder/Library/Caches/go-build"
GOENV="/Users/angshumanhalder/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/angshumanhalder/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/angshumanhalder/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/angshumanhalder/Documents/Tutorials/go-testing/webapp/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s9/_gcs49fx5hgdyksy56nqrzqm0000gn/T/go-build1798901966=/tmp/go-build -gno-record-gcc-switches -fno-common"

Relevant LSPInfo

[ERROR][2022-11-12 16:22:36] ...lsp/handlers.lua:484       "2022/11/12 16:22:36 tidy: diagnosing file:///Users/angshumanhalder/Documents/Tutorials/go-testing/webapp/go.mod: err: exit status 1: stderr: go: finding module for package github.com/go-chi/chi\nwebapp imports\n\tgithub.com/go-chi/chi: cannot find module providing package github.com/go-chi/chi: module lookup disabled by GOPROXY=off\n\n"

lsp.log gopls -rpc.trace

[ERROR][2022-11-13 19:34:05] .../vim/lsp/rpc.lua:733    "rpc"   "gopls" "stderr"        "[Trace - 19:34:05.799 PM] Sending notification 'textDocument/didChange'.\nParams: {\"contentChanges\":[{\"rangeLength\":2,\"text\":\"\\t\",\"range\":{\"start\":{\"line\":5,\"character\":0},\"end\":{\"line\":5,\"character\":2}}}],\"textDocument\":{\"uri\":\"file:\\/\\/\\/Users\\/angshumanhalder\\/Documents\\/Tutorials\\/go-testing\\/webapp\\/main.go\",\"version\":142}}\r\n\r\n\r\n"
[ERROR][2022-11-13 19:34:05] .../vim/lsp/rpc.lua:733    "rpc"   "gopls" "stderr"        "[Trace - 19:34:05.800 PM] Received notification 'window/logMessage'.\nParams: {\"type\":1,\"message\":\"2022/11/13 19:34:05 github.com/angshumanHalder/webapp: no dep handle for github.com/go-chi/chi/v5: no metadata for github.com/go-chi/chi/v5\\n\\tsnapshot=72\\n\"}\r\n\r\n\r\n[Trace - 19:34:05.801 PM] Received notification 'textDocument/publishDiagnostics'.\nParams: {\"uri\":\"file:///Users/angshumanhalder/Documents/Tutorials/go-testing/webapp/main.go\",\"version\":142,\"diagnostics\":[{\"range\":{\"start\":{\"line\":2,\"character\":7},\"end\":{\"line\":2,\"character\":33}},\"severity\":1,\"code\":\"BrokenImport\",\"codeDescription\":{\"href\":\"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#BrokenImport\"},\"source\":\"compiler\",\"message\":\"could not import github.com/go-chi/chi/v5 (no required module provides package \\\"github.com/go-chi/chi/v5\\\")\"},{\"range\":{\"start\":{\"line\":5,\"character\":1},\"end\":{\"line\":5,\"character\":4}},\"severity\":1,\"code\":\"UnusedVar\",\"codeDescription\":{\"href\":\"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UnusedVar\"},\"source\":\"compiler\",\"message\":\"mux declared but not used\",\"tags\":[1]},{\"range\":{\"start\":{\"line\":5,\"character\":8},\"end\":{\"line\":5,\"character\":11}},\"severity\":1,\"code\":\"UndeclaredName\",\"codeDescription\":{\"href\":\"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName\"},\"source\":\"compiler\",\"message\":\"undeclared name: chi\"}]}\r\n\r\n\r\n"
[ERROR][2022-11-13 19:34:05] .../vim/lsp/rpc.lua:733    "rpc"   "gopls" "stderr"        "[Trace - 19:34:05.803 PM] Sending notification 'textDocument/didSave'.\nParams: {\"textDocument\":{\"uri\":\"file:\\/\\/\\/Users\\/angshumanhalder\\/Documents\\/Tutorials\\/go-testing\\/webapp\\/main.go\"}}\r\n\r\n\r\n[Trace - 19:34:05.803 PM] Received notification 'window/logMessage'.\nParams: {\"type\":1,\"message\":\"2022/11/13 19:34:05 github.com/angshumanHalder/webapp: no dep handle for github.com/go-chi/chi/v5: no metadata for github.com/go-chi/chi/v5\\n\\tsnapshot=73\\n\"}\r\n\r\n\r\n"
[ERROR][2022-11-13 19:34:05] ...lsp/handlers.lua:485    "2022/11/13 19:34:05 github.com/angshumanHalder/webapp: no dep handle for github.com/go-chi/chi/v5: no metadata for github.com/go-chi/chi/v5\n\tsnapshot=72\n"
[ERROR][2022-11-13 19:34:05] ...lsp/handlers.lua:485    "2022/11/13 19:34:05 github.com/angshumanHalder/webapp: no dep handle for github.com/go-chi/chi/v5: no metadata for github.com/go-chi/chi/v5\n\tsnapshot=73\n"
[ERROR][2022-11-13 19:34:06] .../vim/lsp/rpc.lua:733    "rpc"   "gopls" "stderr"        "[Trace - 19:34:06.072 PM] Received notification 'window/logMessage'.\nParams: {\"type\":1,\"message\":\"2022/11/13 19:34:06 tidy: diagnosing file:///Users/angshumanhalder/Documents/Tutorials/go-testing/webapp/go.mod: err: exit status 1: stderr: go: finding module for package github.com/go-chi/chi/v5\\ngithub.com/angshumanHalder/webapp imports\\n\\tgithub.com/go-chi/chi/v5: cannot find module providing package github.com/go-chi/chi/v5: module lookup disabled by GOPROXY=off\\n\\n\"}\r\n\r\n\r\n"
[ERROR][2022-11-13 19:34:06] ...lsp/handlers.lua:485    "2022/11/13 19:34:06 tidy: diagnosing file:///Users/angshumanhalder/Documents/Tutorials/go-testing/webapp/go.mod: err: exit status 1: stderr: go: finding module for package github.com/go-chi/chi/v5\ngithub.com/angshumanHalder/webapp imports\n\tgithub.com/go-chi/chi/v5: cannot find module providing package github.com/go-chi/chi/v5: module lookup disabled by GOPROXY=off\n\n"
[ERROR][2022-11-13 19:34:06] .../vim/lsp/rpc.lua:733    "rpc"   "gopls" "stderr"        "[Trace - 19:34:06.072 PM] Received notification 'textDocument/publishDiagnostics'.\nParams: {\"uri\":\"file:///Users/angshumanhalder/Documents/Tutorials/go-testing/webapp/main.go\",\"version\":142,\"diagnostics\":[{\"range\":{\"start\":{\"line\":2,\"character\":7},\"end\":{\"line\":2,\"character\":33}},\"severity\":1,\"code\":\"BrokenImport\",\"codeDescription\":{\"href\":\"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#BrokenImport\"},\"source\":\"compiler\",\"message\":\"could not import github.com/go-chi/chi/v5 (no required module provides package \\\"github.com/go-chi/chi/v5\\\")\"},{\"range\":{\"start\":{\"line\":5,\"character\":1},\"end\":{\"line\":5,\"character\":4}},\"severity\":1,\"code\":\"UnusedVar\",\"codeDescription\":{\"href\":\"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UnusedVar\"},\"source\":\"compiler\",\"message\":\"mux declared but not used\",\"tags\":[1]},{\"range\":{\"start\":{\"line\":5,\"character\":8},\"end\":{\"line\":5,\"character\":11}},\"severity\":1,\"code\":\"UndeclaredName\",\"codeDescription\":{\"href\":\"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName\"},\"source\":\"compiler\",\"message\":\"undeclared name: chi\"}]}\r\n\r\n\r\n"

gopls -rpc.trace -v check main.go

(root /Users/angshumanhalder/Documents/Tutorials/go-testing/webapp)
(go version go version go1.19.3 darwin/arm64)
(valid build configuration = true)
(build flags: [])
GOCACHE=/Users/angshumanhalder/Library/Caches/go-build
GOFLAGS=-mod=mod
GONOPROXY=
GOPRIVATE=
GOMODCACHE=/Users/angshumanhalder/go/pkg/mod
GONOSUMDB=
GOMOD=/Users/angshumanhalder/Documents/Tutorials/go-testing/webapp/go.mod
GOWORK=
GOPATH=/Users/angshumanhalder/go
GO111MODULE=
GOROOT=/usr/local/go
GOPROXY=https://proxy.golang.org,direct
GOSUMDB=sum.golang.org
GOINSECURE=

2022/11/13 19:35:51 Info:2022/11/13 19:35:51 go/packages.Load #1
        snapshot=0
        directory=/Users/angshumanhalder/Documents/Tutorials/go-testing/webapp
        query=[builtin github.com/angshumanHalder/webapp/...]
        packages=2
2022/11/13 19:35:51 Info:2022/11/13 19:35:51 go/packages.Load #1: updating metadata for 127 packages
/Users/angshumanhalder/Documents/Tutorials/go-testing/webapp/main.go:6:2-5: mux declared but not used

LSPconfig

lspconfig.gopls.setup {
  capabilities = capabilities,
  on_attach = on_attach,
  filetypes = { "go", "gomod", "tmpl", "gotmpl" },
  root_dir = require("lspconfig/util").root_pattern("go.work", "go.sum", "go.mod", ".git"),
  cmd = { "gopls" },
  settings = {
    gopls = {
      analyses = {
        unusedparams = true,
      },
      staticcheck = true,
    },
  },
}

Behaviour

Only happens while using go get or go mod tidy.

Build info

golang.org/x/tools/gopls v0.10.1
    golang.org/x/tools/gopls@v0.10.1 h1:JoHe17pdZ8Vsa24/GUO8iTVTKPh0EOBiWpPop7XJybI=
    github.com/BurntSushi/toml@v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
    github.com/google/go-cmp@v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp@v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
    golang.org/x/exp/typeparams@v0.0.0-20220722155223-a9213eeb770e h1:7Xs2YCOpMlNqSQSmrrnhlzBXIE/bpMecZplbLePTJvE=
    golang.org/x/mod@v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
    golang.org/x/sync@v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
    golang.org/x/sys@v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
    golang.org/x/text@v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
    golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2 h1:KBm+UwBaO/tdQ35tfGvxH1FUCiXRg4MoTzkznsdeab8=
    golang.org/x/vuln@v0.0.0-20221010193109-563322be2ea9 h1:KaYZQUtEEaV8aVADIHAuYBTjo77aUcCvC7KTGKM3J1I=
    honnef.co/go/tools@v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=
    mvdan.cc/gofumpt@v0.3.1 h1:avhhrOmv0IuvQVK7fvwV91oFSGAk5/6Po8GXTzICeu8=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.19.3

I tried gopls with VSCode and it works. The one difference I noticed is go/packages.Load is triggered when the I fetch new packages with go get in VSCode + gopls but the same doesn't happen when I use neovim native lsp + gopls. The packages.Load triggers only on LspRestart in neovim.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 12, 2022
@gopherbot gopherbot added this to the Unreleased milestone Nov 12, 2022
@suzmue suzmue modified the milestones: Unreleased, gopls/later Nov 14, 2022
@findleyr findleyr modified the milestones: gopls/later, gopls/v0.11.0 Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants