Skip to content

x/tools/gopls: Code completion in gopls is not working, unable to find the packages to import #71462

Open
@tyanxie

Description

@tyanxie

What did you do?

I have enabled gopls in Neovim through configuring lspconfig. When I am working in a new project and type http, gopls does not provide code completion suggestions for net/http. And this issue is not limited to the http module, it affects all modules.

I have noticed that when I manually add import net/http to the import block, the code completion starts to work properly, and it also begins to suggest other modules correctly.

I guess that maybe gopls only indexes the modules in the import block and does not index the standard library or the modules listed in go.mod by default. I believe this is not the expected behavior. I think indexing the standard library and the modules in go.mod should be considered an expected behavior.

What did you expect to see?

Neovim should provide suggestions for packages that have not yet been imported, such as directly using http in a new project as I mentioned earlier.

Image

What did you see instead?

Neovim does not suggest packages that have not yet been imported.

Image

Build info

{
        "GoVersion": "go1.23.5",
        "Path": "golang.org/x/tools/gopls",
        "Main": {
                "Path": "golang.org/x/tools/gopls",
                "Version": "v0.17.1",
                "Sum": "h1:Mt/DSfnnSe3dyf6MH/dZZ0iww+viHNhAFc4rEYDiOAw=",
                "Replace": null
        },
        "Deps": [
                {
                        "Path": "github.com/BurntSushi/toml",
                        "Version": "v1.4.1-0.20240526193622-a339e1f7089c",
                        "Sum": "h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=",
                        "Replace": null
                },
                {
                        "Path": "github.com/google/go-cmp",
                        "Version": "v0.6.0",
                        "Sum": "h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=",
                        "Replace": null
                },
                {
                        "Path": "golang.org/x/exp/typeparams",
                        "Version": "v0.0.0-20231108232855-2478ac86f678",
                        "Sum": "h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=",
                        "Replace": null
                },
                {
                        "Path": "golang.org/x/mod",
                        "Version": "v0.22.0",
                        "Sum": "h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=",
                        "Replace": null
                },
                {
                        "Path": "golang.org/x/sync",
                        "Version": "v0.9.0",
                        "Sum": "h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=",
                        "Replace": null
                },
                {
                        "Path": "golang.org/x/telemetry",
                        "Version": "v0.0.0-20241106142447-58a1122356f5",
                        "Sum": "h1:TCDqnvbBsFapViksHcHySl/sW4+rTGNIAoJJesHRuMM=",
                        "Replace": null
                },
                {
                        "Path": "golang.org/x/text",
                        "Version": "v0.20.0",
                        "Sum": "h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=",
                        "Replace": null
                },
                {
                        "Path": "golang.org/x/tools",
                        "Version": "v0.27.1-0.20241219162658-575221bfbda3",
                        "Sum": "h1:kgwdasJRsdDWYgWcEgMF424DiXwwXHSb3V8xVTi//i8=",
                        "Replace": null
                },
                {
                        "Path": "golang.org/x/vuln",
                        "Version": "v1.0.4",
                        "Sum": "h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=",
                        "Replace": null
                },
                {
                        "Path": "honnef.co/go/tools",
                        "Version": "v0.5.1",
                        "Sum": "h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=",
                        "Replace": null
                },
                {
                        "Path": "mvdan.cc/gofumpt",
                        "Version": "v0.7.0",
                        "Sum": "h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=",
                        "Replace": null
                },
                {
                        "Path": "mvdan.cc/xurls/v2",
                        "Version": "v2.5.0",
                        "Sum": "h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=",
                        "Replace": null
                }
        ],
        "Settings": [
                {
                        "Key": "-buildmode",
                        "Value": "exe"
                },
                {
                        "Key": "-compiler",
                        "Value": "gc"
                },
                {
                        "Key": "CGO_ENABLED",
                        "Value": "1"
                },
                {
                        "Key": "CGO_CFLAGS",
                        "Value": ""
                },
                {
                        "Key": "CGO_CPPFLAGS",
                        "Value": ""
                },
                {
                        "Key": "CGO_CXXFLAGS",
                        "Value": ""
                },
                {
                        "Key": "CGO_LDFLAGS",
                        "Value": ""
                },
                {
                        "Key": "GOARCH",
                        "Value": "arm64"
                },
                {
                        "Key": "GOOS",
                        "Value": "darwin"
                },
                {
                        "Key": "GOARM64",
                        "Value": "v8.0"
                }
        ],
        "Version": "v0.17.1"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions