mirror of
https://github.com/golang/go
synced 2024-11-18 13:04:46 -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:
parent
83d82311fd
commit
8f1b74eef3
@ -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)
|
||||
|
18
internal/lsp/testdata/labels/labels.go
vendored
18
internal/lsp/testdata/labels/labels.go
vendored
@ -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
|
||||
}
|
||||
|
2
internal/lsp/testdata/summary.txt.golden
vendored
2
internal/lsp/testdata/summary.txt.golden
vendored
@ -1,5 +1,5 @@
|
||||
-- summary --
|
||||
CompletionsCount = 209
|
||||
CompletionsCount = 211
|
||||
CompletionSnippetCount = 39
|
||||
UnimportedCompletionsCount = 1
|
||||
DeepCompletionsCount = 5
|
||||
|
Loading…
Reference in New Issue
Block a user