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: completions favour imports over local variables once a second letter is typed #65103

Open
Jackenmen opened this issue Jan 15, 2024 · 0 comments
Labels
gopls/completion Issues related to auto-completion in gopls. 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

@Jackenmen
Copy link

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

@Jackenmen Jackenmen added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Jan 15, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jan 15, 2024
@adonovan adonovan added the gopls/completion Issues related to auto-completion in gopls. label Jan 16, 2024
@hyangah hyangah modified the milestones: Unreleased, gopls/backlog Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/completion Issues related to auto-completion in gopls. 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