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

Closed
stamblerre opened this issue Dec 17, 2018 · 18 comments
Closed

x/tools/gopls: handle completion after defer and go statements #29313

stamblerre opened this issue Dec 17, 2018 · 18 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@stamblerre
Copy link
Contributor

stamblerre 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
Copy link

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
Copy link
Contributor Author

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
Copy link

@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.

@stamblerre stamblerre added gopls Issues related to the Go language server, gopls. and removed gopls Issues related to the Go language server, gopls. labels Mar 12, 2019
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 12, 2019
@gopherbot
Copy link

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
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
Copy link
Member

myitcv 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
Copy link
Contributor Author

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
Copy link
Member

myitcv 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
Copy link
Contributor Author

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
@glepnir
Copy link

glepnir commented Jul 21, 2019

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

@stamblerre
Copy link
Contributor Author

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

@glepnir
Copy link

glepnir commented Jul 22, 2019

@stamblerre same as #33075

@stamblerre
Copy link
Contributor Author

/cc @flowchartsman

This issue has been partially solved, but still needs a bit of work. I believe @flowchartsman will be investigating this.

@gopherbot
Copy link

Change https://golang.org/cl/194377 mentions this issue: internal/lsp: update to latest version of x/tools

gopherbot pushed a commit to golang/tools that referenced this issue Sep 9, 2019
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>
@stamblerre
Copy link
Contributor Author

This issue should be fixed now. Thanks @muirrn!

@gencer
Copy link

gencer commented Sep 9, 2019

@stamblerre, should I do;

go get golang.org/x/tools/gopls@master

or

go get golang.org/x/tools/gopls@latest

@stamblerre
Copy link
Contributor Author

We haven't made a new release yet, so for now, the fix is only on master.

@gencer
Copy link

gencer commented Sep 9, 2019

Thanks for the fix. I'll use master branch for now.

@blixenkrone
Copy link

Thank you for the fix @stamblerre! Works perfectly.

@stamblerre stamblerre modified the milestones: gopls/v1.0.0, gopls/v0.4.0 Jul 22, 2020
@golang golang locked and limited conversation to collaborators Jul 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants