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: Use source from GOMODCACHE if available even if the dependant module is vendored #52952

Closed
Frederick888 opened this issue May 18, 2022 · 2 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@Frederick888
Copy link

gopls version

Build info
----------
golang.org/x/tools/gopls v0.8.3
    golang.org/x/tools/gopls@v0.8.3 h1:Mxm94ix8oSARQ6svioO6SxKEYWT/VCP54/448LOHzrk=
    github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
    golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.11-0.20220407163324-91bcfb1bdf9c h1:rYiuK/jn6TCxjAq1hQ6MR6pgOeP3A5gIHDxgrQ8Vbys=
    golang.org/x/vuln@v0.0.0-20220324005316-18fd808f5c7f h1:9dMzk88fnONra7zrEalqkRMGa9jMGf9B5mdzhYVyI28=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.3.0 h1:2LdYUZ7CIxnYgskbUZfY7FPggmqnh6shBqfWa8Tn3XU=
    mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18.2

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/frederick.zhang/.go/bin"
GOCACHE="/Users/frederick.zhang/Library/Caches/go-build"
GOENV="/Users/frederick.zhang/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/frederick.zhang/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/frederick.zhang/.go"
GOPRIVATE=""
GOPROXY="<redacted>"
GOROOT="/Users/frederick.zhang/.asdf/installs/golang/1.18.2/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/Users/frederick.zhang/.asdf/installs/golang/1.18.2/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="<redacted>"
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/t6/h6qmyp4n1kv19s7pj58k7sy40000gq/T/go-build3478975185=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Vendor a module, which contains for example 3 packages. Only one of them is used in main module initially so only that module's source code is actually vendored
  2. Open a Go file in the main module, try to use something from the other two packages

What did you expect to see?

Auto-completion and auto-import from the two packages that are not currently vendored.

What did you see instead?

No completion. I have to check the package path, import it in some file in main module, go vendor, then gopls will start providing auto-completion and auto-import.

Alternatively I can delete vendor/ temporarily.

Editor and settings

I'm using Neovim with coc.nvim.

{
  "go.goplsPath": "/Users/frederick.zhang/.go/bin/gopls",
  "go.goplsOptions": {
    "local": "<redacted>",
    "staticcheck": true,
    "analyses": {
      "ST1005": false
    }
  }
}

Logs

[Trace - 3:08:38 pm] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/frederick.zhang/<redacted>",
    "version": 8,
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 34,
                    "character": 1
                },
                "end": {
                    "line": 34,
                    "character": 7
                }
            },
            "severity": 1,
            "code": "UndeclaredName",
            "codeDescription": {
                "href": "https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UndeclaredName"
            },
            "source": "compiler",
            "message": "undeclared name: <a currently unused package from a vendored module>"
        }
    ]
}
@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 May 18, 2022
@gopherbot gopherbot added this to the Unreleased milestone May 18, 2022
@findleyr
Copy link
Contributor

This hybrid functionality will be difficult for gopls to support, as it integrates with the behavior of go list.

We could theoretically turn off vendoring, but I don't think that's desirable either. Many users will not have the necessary modules in their module cache. We could run go mod vendor for the user, but that also has significant downsides.

The status quo has the advantage of being explicit, and consistent with the Go command.

@findleyr findleyr added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 23, 2022
@findleyr findleyr modified the milestones: Unreleased, gopls/later May 23, 2022
@findleyr
Copy link
Contributor

We just discussed this in our triage meeting and decided that the cost of implementing this feature would not be worth its benefit.

Closing now. Please re-open if you think we have missed something.

@findleyr findleyr closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2022
@golang golang locked and limited conversation to collaborators Oct 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants