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: handle completion after defer and go statements #29313

Open
stamblerre opened this issue Dec 17, 2018 · 11 comments

Comments

Projects
None yet
6 participants
@stamblerre
Copy link
Contributor

commented Dec 17, 2018

A defer or go statement is expected to be followed by an *ast.CallExpr. If they are not, the parser treats them as *ast.BadExprs, causing completion to fail. We need to handle this particular case.

Repro:

package main

import "fmt"

func main() {
    defer fmt.<>
}

Triggering a completion here will result in lexical completions, rather than the expected selector completions for package "fmt".

@gopherbot gopherbot added this to the Unreleased milestone Dec 17, 2018

@alindeman

This comment has been minimized.

Copy link

commented Dec 18, 2018

I decided to poke at this a bit, but couldn't reproduce it. Is this a short code snippet you have handy that triggers the issue?

@stamblerre stamblerre self-assigned this Dec 18, 2018

@stamblerre

This comment has been minimized.

Copy link
Contributor Author

commented Dec 18, 2018

Updated to add a repro. This may be a tough first issue, if this is something you're interested in tackling, just because it will require special handling after a file has been parsed but before it has been type-checked.

@alindeman

This comment has been minimized.

Copy link

commented Dec 18, 2018

@stamblerre Thanks. I'm mostly using anything tagged as lsp as a way to get familiar with the current codebase. I don't want to get in the way yet :) I'll follow along on the CL if you get to it first.

@gopherbot

This comment has been minimized.

Copy link

commented Apr 24, 2019

Change https://golang.org/cl/172974 mentions this issue: internal/lsp: handle completion after defer, go statements

gopherbot pushed a commit to golang/tools that referenced this issue Apr 24, 2019

internal/lsp: handle completion after defer, go statements
This change adds support for completion of incomplete selectors after a
defer or go statement. We modify the AST before type-checking it with a
fake *ast.CallExpr.

Updates golang/go#29313

Change-Id: Ic9e8c9c49aa569cd7874791692c70a28c3146251
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172974
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
@myitcv

This comment has been minimized.

Copy link
Member

commented May 3, 2019

I might have misunderstood https://go-review.googlesource.com/c/tools/+/172974/, but I still don't see (as of v0.0.0-20190503030157-5cec639030af) completions working for the original example provided in #29313 (comment)

@stamblerre

This comment has been minimized.

Copy link
Contributor Author

commented May 8, 2019

I'm still working on finishing this because it doesn't work on most cases, but it should work OK for the cases in these tests: https://github.com/golang/tools/blob/master/internal/lsp/testdata/badstmt/badstmt.go.

@myitcv

This comment has been minimized.

Copy link
Member

commented Jun 25, 2019

@stamblerre - not quite sure whether the following is an instance of the same issue? Happy to raise a separate issue if not:

package main

import "playground.com/p"

func main() {
	switch {
	case nil:
		s := new(p.)
	}
}

-- go.mod --
module playground.com

-- p/p.go --
package p

type S struct {
	Name string
	Age  int
}

Attempting completion after s. in main.go does not return any candidates.

@stamblerre

This comment has been minimized.

Copy link
Contributor Author

commented Jun 27, 2019

I'd guess it's actually closer to #31973, but either way, that should definitely work.

@stamblerre stamblerre changed the title x/tools/internal/lsp: handle completion after defer and go statements x/tools/gopls: handle completion after defer and go statements Jul 2, 2019

@taigacute

This comment has been minimized.

Copy link

commented Jul 21, 2019

@stamblerre hi , i got same error without go defer statements.
1

@stamblerre

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2019

@taigacute: I'm not sure I understand the issue here. Do you mind filing a separate issue with logs?

@taigacute

This comment has been minimized.

Copy link

commented Jul 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.