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: completion doesn't work correctly in some conditions #65529

Open
worlpaker opened this issue Feb 5, 2024 · 6 comments · May be fixed by golang/tools#477
Open

x/tools/gopls: completion doesn't work correctly in some conditions #65529

worlpaker opened this issue Feb 5, 2024 · 6 comments · May be fixed by golang/tools#477
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

@worlpaker
Copy link

gopls version

v0.14.2

go env

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\worlpaker\AppData\Local\go-build
set GOENV=C:\Users\worlpaker\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\worlpaker\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\worlpaker\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.6
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\worlpaker\AppData\Local\Temp\go-build2689359370=/tmp/go-build -gno-record-gcc-switches

What did you do?

Completion doesn't work correctly in some conditions.

variable completion after comma:

package main

func main(){
	minimum, maximum := 0, 0
	minimum, max
}

Demonstration

test.mp4

What did you see happen?

The completion of max became maxmaximum.

What did you expect to see?

The completion for max should be maximum.

Editor and settings

No response

Logs

No response

@worlpaker worlpaker 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 Feb 5, 2024
@gopherbot gopherbot added this to the Unreleased milestone Feb 5, 2024
@worlpaker
Copy link
Author

This also happens when the source code has syntax errors: missing a comma inside parentheses or accidentally putting a comma inside parentheses.

missing comma:

package main

import "fmt"

func main() {
	value := 0
	fmt.Println("value:" val)
}

The completion for val will be valvalue.

accidentally putting comma:

Similar issue from #58833

package main

import (
	"fmt"
	"math"
)

func main() {
	math.Sqrt(,0)
	math.ab
}

The completion for math.ab will be math.abmath.Abs().

@gopherbot
Copy link

Change https://go.dev/cl/561417 mentions this issue: gopls/internal/golang/completion: fix completion behavior when the source has syntax errors

@findleyr
Copy link
Contributor

findleyr commented Feb 6, 2024

Thank you. This looks like a duplicate of #58833, right?

Thanks for digging into this and working on a fix! As commented on the CL, it would be helpful to explain a theory of how to handle syntax errors.

@worlpaker
Copy link
Author

Yes, it is. Although the first scenario (max<>) logically doesn't have any syntax errors.

@findleyr
Copy link
Contributor

findleyr commented Feb 8, 2024

Thanks. For what it's worth, the first scenario does have syntax errors (e.g. https://go.dev/play/p/lVxgY6Dczjf notes a syntax error).

@findleyr
Copy link
Contributor

findleyr commented Feb 8, 2024

I will take a look at the fix. We can keep this issue open since the other issue is about go/parser.

@findleyr findleyr modified the milestones: Unreleased, gopls/backlog Feb 8, 2024
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
3 participants