mirror of https://github.com/golang/go.git
internal/lsp/source: omit assign stmt LHS in RHS completion
In the below example:
fooBar := fooB<>
We will no longer suggest "fooBar" at <>.
Fixes golang/go#39203.
Change-Id: Ie1450397ce3de4f21fb0862c1a4f0fe2812325fd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275693
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
7bb39e4ca9
commit
a835c872fc
|
|
@ -1284,12 +1284,10 @@ func (c *completer) lexical(ctx context.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Don't use LHS of value spec in RHS.
|
||||
if vs := enclosingValueSpec(c.path); vs != nil {
|
||||
for _, ident := range vs.Names {
|
||||
if obj.Pos() == ident.Pos() {
|
||||
continue Names
|
||||
}
|
||||
// Don't use LHS of decl in RHS.
|
||||
for _, ident := range enclosingDeclLHS(c.path) {
|
||||
if obj.Pos() == ident.Pos() {
|
||||
continue Names
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -195,10 +195,21 @@ func enclosingSelector(path []ast.Node, pos token.Pos) *ast.SelectorExpr {
|
|||
return nil
|
||||
}
|
||||
|
||||
func enclosingValueSpec(path []ast.Node) *ast.ValueSpec {
|
||||
// enclosingDeclLHS returns LHS idents from containing value spec or
|
||||
// assign statement.
|
||||
func enclosingDeclLHS(path []ast.Node) []*ast.Ident {
|
||||
for _, n := range path {
|
||||
if vs, ok := n.(*ast.ValueSpec); ok {
|
||||
return vs
|
||||
switch n := n.(type) {
|
||||
case *ast.ValueSpec:
|
||||
return n.Names
|
||||
case *ast.AssignStmt:
|
||||
ids := make([]*ast.Ident, 0, len(n.Lhs))
|
||||
for _, e := range n.Lhs {
|
||||
if id, ok := e.(*ast.Ident); ok {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,3 +16,11 @@ func _() {
|
|||
func _() {
|
||||
var a string = a //@complete(" //")
|
||||
}
|
||||
|
||||
func _() {
|
||||
fooBar := fooBa //@complete(" //"),item(assignFooBar, "fooBar", "", "var")
|
||||
abc, fooBar := 123, fooBa //@complete(" //", assignFooBar)
|
||||
{
|
||||
fooBar := fooBa //@complete(" //", assignFooBar)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
-- summary --
|
||||
CallHierarchyCount = 1
|
||||
CodeLensCount = 5
|
||||
CompletionsCount = 255
|
||||
CompletionsCount = 258
|
||||
CompletionSnippetCount = 88
|
||||
UnimportedCompletionsCount = 5
|
||||
DeepCompletionsCount = 5
|
||||
|
|
|
|||
Loading…
Reference in New Issue