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
Comments
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? |
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. |
@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. |
Change https://golang.org/cl/172974 mentions this issue: |
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>
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) |
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. |
@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 |
I'd guess it's actually closer to #31973, but either way, that should definitely work. |
@stamblerre hi , i got same error without |
@taigacute: I'm not sure I understand the issue here. Do you mind filing a separate issue with logs? |
@stamblerre same as #33075 |
/cc @flowchartsman This issue has been partially solved, but still needs a bit of work. I believe @flowchartsman will be investigating this. |
Change https://golang.org/cl/194377 mentions this issue: |
The fix for golang/go#29313 just went in, so update so people can fetch it more easily. Change-Id: I60fda011dfdd62d5de429834a6692f6b21074f0d Reviewed-on: https://go-review.googlesource.com/c/tools/+/194377 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This issue should be fixed now. Thanks @muirrn! |
@stamblerre, should I do;
or
|
We haven't made a new release yet, so for now, the fix is only on master. |
Thanks for the fix. I'll use |
Thank you for the fix @stamblerre! Works perfectly. |
A
defer
orgo
statement is expected to be followed by an*ast.CallExpr
. If they are not, the parser treats them as*ast.BadExpr
s, causing completion to fail. We need to handle this particular case.Repro:
Triggering a completion here will result in lexical completions, rather than the expected selector completions for package "fmt".
The text was updated successfully, but these errors were encountered: