1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:16:10 -07:00

internal/lsp: fix label completion in range and type switch stmts

Fix label detection to know about *ast.RangeStmt
and *ast.TypeSwitchStmt.

Change-Id: I4061e165884f7064fe486249fe3664d572b7b628
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202621
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Muir Manders 2019-10-22 14:13:24 -07:00 committed by Rebecca Stambler
parent 83d82311fd
commit 8f1b74eef3
3 changed files with 17 additions and 7 deletions

View File

@ -71,10 +71,10 @@ func (c *completer) labels(lt labelType) {
return
case *ast.LabeledStmt:
switch p.Stmt.(type) {
case *ast.ForStmt:
case *ast.ForStmt, *ast.RangeStmt:
// Loop labels can be used for "break" or "continue".
addLabel(p)
case *ast.SwitchStmt, *ast.SelectStmt:
case *ast.SwitchStmt, *ast.SelectStmt, *ast.TypeSwitchStmt:
// Switch and select labels can be used only for "break".
if lt == labelBreak {
addLabel(p)

View File

@ -1,10 +1,10 @@
package labels
func _() {
goto F //@complete(" //", label1, label4)
goto F //@complete(" //", label1, label5)
Foo1: //@item(label1, "Foo1", "label", "const")
for {
for a, b := range []int{} {
Foo2: //@item(label2, "Foo2", "label", "const")
switch {
case true:
@ -16,7 +16,7 @@ Foo1: //@item(label1, "Foo1", "label", "const")
FooUnjumpable:
}
goto F //@complete(" //", label1, label2, label4)
goto F //@complete(" //", label1, label2, label4, label5)
func() {
goto F //@complete(" //", label3)
@ -28,12 +28,22 @@ Foo1: //@item(label1, "Foo1", "label", "const")
Foo3: //@item(label3, "Foo3", "label", "const")
}()
}
Foo4: //@item(label4, "Foo4", "label", "const")
switch interface{}(a).(type) {
case int:
break F //@complete(" //", label4, label1)
}
}
break F //@complete(" //")
continue F //@complete(" //")
Foo4: //@item(label4, "Foo4", "label", "const")
Foo5: //@item(label5, "Foo5", "label", "const")
for {
break F //@complete(" //", label5)
}
return
}

View File

@ -1,5 +1,5 @@
-- summary --
CompletionsCount = 209
CompletionsCount = 211
CompletionSnippetCount = 39
UnimportedCompletionsCount = 1
DeepCompletionsCount = 5