mirror of
https://github.com/golang/go
synced 2024-11-19 06:04:39 -07:00
de15caf068
Fix the following issues: - We were trying to complete struct literal field names for selector expressions (e.g. "Foo{a.B<>}"). Now we only complete field names in this case if the expression is an *ast.Ident. - We weren't including lexical completions in cases where you might be completing a field name or a variable name (e.g. "Foo{A<>}"). I refactored composite literal logic to live mostly in one place. Now enclosingCompositeLiteral computes all the bits of information related to composite literals. The expected type, completion, and snippet code make use of those precalculated facts instead of redoing the work. Change-Id: I29fc808544382c3c77f0bba1843520e04f38e79b GitHub-Last-Rev: 3489062be342ab0f00325d3b3ae9ce681df7cf2e GitHub-Pull-Request: golang/tools#96 Reviewed-on: https://go-review.googlesource.com/c/tools/+/176601 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package complit
|
|
|
|
type position struct { //@item(structPosition, "position", "struct{...}", "struct")
|
|
X, Y int //@item(fieldX, "X", "int", "field"),item(fieldY, "Y", "int", "field")
|
|
}
|
|
|
|
func _() {
|
|
_ = position{
|
|
//@complete("", fieldX, fieldY, structPosition)
|
|
}
|
|
_ = position{
|
|
X: 1,
|
|
//@complete("", fieldY)
|
|
}
|
|
_ = position{
|
|
//@complete("", fieldX)
|
|
Y: 1,
|
|
}
|
|
}
|
|
|
|
func _() {
|
|
var (
|
|
aa string //@item(aaVar, "aa", "string", "var")
|
|
ab int //@item(abVar, "ab", "int", "var")
|
|
)
|
|
|
|
_ = map[int]int{
|
|
a: a, //@complete(":", abVar, aaVar),complete(",", abVar, aaVar)
|
|
}
|
|
|
|
_ = map[int]int{
|
|
//@complete("", abVar, aaVar, structPosition)
|
|
}
|
|
|
|
_ = []string{a: ""} //@complete(":", abVar, aaVar)
|
|
_ = [1]string{a: ""} //@complete(":", abVar, aaVar)
|
|
|
|
_ = position{X: a} //@complete("}", abVar, aaVar)
|
|
_ = position{a} //@complete("}", abVar, aaVar)
|
|
_ = position{a, } //@complete("}", abVar, aaVar, structPosition)
|
|
|
|
_ = []int{a} //@complete("a", abVar, aaVar, structPosition)
|
|
_ = [1]int{a} //@complete("a", abVar, aaVar, structPosition)
|
|
|
|
type myStruct struct {
|
|
AA int //@item(fieldAA, "AA", "int", "field")
|
|
AB string //@item(fieldAB, "AB", "string", "field")
|
|
}
|
|
|
|
_ = myStruct{
|
|
AB: a, //@complete(",", aaVar, abVar)
|
|
}
|
|
|
|
var s myStruct
|
|
|
|
_ = map[int]string{1: "" + s.A} //@complete("}", fieldAB, fieldAA)
|
|
_ = map[int]string{1: (func(i int) string { return "" })(s.A)} //@complete(")}", fieldAA, fieldAB)
|
|
_ = map[int]string{1: func() string { s.A }} //@complete(" }", fieldAA, fieldAB)
|
|
|
|
_ = position{s.A} //@complete("}", fieldAA, fieldAB)
|
|
|
|
var X int //@item(varX, "X", "int", "var")
|
|
_ = position{X} //@complete("}", fieldX, varX)
|
|
}
|
|
|
|
func _() {
|
|
_ := position{
|
|
X: 1, //@complete("X", fieldX),complete(" 1", structPosition)
|
|
Y: , //@complete(":", fieldY),complete(" ,", structPosition)
|
|
}
|
|
}
|