Skip to content

x/tools/gopls: completions favour imports over local variables once a second letter is typed #65103

@Jackenmen

Description

@Jackenmen

gopls version

v0.14.2

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ubuntu/.cache/go-build"
GOENV="/home/ubuntu/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ubuntu/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ubuntu/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ubuntu/work/go_example/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4259290323=/tmp/go-build -gno-record-gcc-switches"

What did you do?

For reproduction, I made a simple project by:

  1. Creating a new directory
  2. Running go mod init go_example in it.
  3. Creating a file hello.go with following contents:
package main

import "fmt"

func main() {
    resourceName := "XYZ"
    fmt.Printf("Resource name: %v\n")
}

To reproduce, I started typing the name of the variable as the second argument to fmt.Printf, i.e.:

    fmt.Printf("Resource name: %v\n", r)
    #                new characters ^^^

which produces a reasonable list of completions:
image

But then I type a second letter i.e.:

    fmt.Printf("Resource name: %v\n", re)
    #                new characters    ^

and the order of completions becomes less useful:
image

What did you see happen?

Once I started typing more than one letter of the variable name, import names started being favoured over the local variable name, which keeps happening up until I type "resource":
image
image

What did you expect to see?

I expected resourceName local variable to be shown as the first completion over the imports.

Editor and settings

Sublime Text with LSP-gopls extension (v1.14.2) using default settings.

Logs

gopls.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/completionIssues related to auto-completion in gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions