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 suggest items following invalid code #31687

Open
myitcv opened this issue Apr 25, 2019 · 6 comments

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Apr 25, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.3 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20190425001055-9e44c1c40307

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN="/home/myitcv/gostuff/src/github.com/myitcv/govim/cmd/govim/.bin"
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPROXY=""
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/govim/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build004347189=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This is largely a "port" of mdempsky/gocode#22 to the gopls issue tracker where the issue remains.

// example 1
package main

func main() {
    Do
      ^
}

func DoIt() bool {
    return true
}

If completion is attempted at the position indicated by ^, completion successfully returns the single candidate:

DoIt()

Now consider:

// example 2
package main

func main() {
    if Do
         ^
}

func DoIt() bool {
    return true
}

This time we don't get any candidates.

What did you expect to see?

The single candidate DoIt() returned in example 2.

What did you see instead?

As above


cc @stamblerre @ianthehat

@gopherbot gopherbot added this to the Unreleased milestone Apr 25, 2019
@myitcv

This comment has been minimized.

Copy link
Member Author

@myitcv myitcv commented Apr 29, 2019

Another instance:

package main

func main() {
	var i I
	i.
	  ^
}

type I interface {
	DoIt()
}

The completion request at the cursor position show returns no results.

@stamblerre - is it worth kicking off separate go/parser issues to try and get these issues fixed in parallel?

@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Apr 29, 2019

They're both instances of the same issue actually. Basically when something fails to parse at the top of the file, it creates problems at the end, so anything below where you are will not be handled correctly.

@myitcv

This comment has been minimized.

Copy link
Member Author

@myitcv myitcv commented Apr 29, 2019

Yes indeed; I suspect however these are separate cases in go/parser hence my reason for listing the various instances I find.

@stamblerre stamblerre changed the title x/tools/cmd/gopls: completion of items following invalid if statements x/tools/cmd/gopls: completion fails on items following invalid code May 21, 2019
@stamblerre stamblerre changed the title x/tools/cmd/gopls: completion fails on items following invalid code x/tools/cmd/gopls: completion doesn't suggest items following invalid code May 21, 2019
@stamblerre stamblerre changed the title x/tools/cmd/gopls: completion doesn't suggest items following invalid code x/tools/gopls: completion doesn't suggest items following invalid code Jul 2, 2019
@SteelPhase

This comment has been minimized.

Copy link

@SteelPhase SteelPhase commented Jul 30, 2019

Is there anyway that gopls could fallback to parsing the file on disk in these cases to attempt to return useful autocomplete? Not sure if that's actually the best way to resolve this type of situation.

@gopherbot gopherbot added the Tools label Sep 12, 2019
@myitcv

This comment has been minimized.

Copy link
Member Author

@myitcv myitcv commented Oct 7, 2019

@muirrn as the completion guru, do you think this can be closed now? Or are you using it as a placeholder for future improvements?

@muirdm

This comment has been minimized.

Copy link

@muirdm muirdm commented Oct 7, 2019

I think we can keep it open to track/consolidate this class of problems.

I'm not planning any work in this area but I think the general plan is to expand our AST fixes to include these and other common syntax errors. For example, workarounds for the above cases might look like:

  • Parse if Do\n as if Do {}\n
  • Parse i.\n as i._\n
@stamblerre stamblerre removed the gopls-parse label Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.