1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:54:42 -07:00
go/internal/lsp/testdata/builtins/builtin_args.go
Muir Manders bc0b458b10 internal/lsp/source: improve completion for "make()" args
Fix type inference to expect a type name for the first "make()"
parameter and an integer for later parameters. For example:

   // Previously we expected "[]int{}", now we expect "[]int".
   var _ []int = make(<>)

Note that we don't currently support actually completing to unnamed
type names like "[]int", but this improvement at least eliminates
nonsensical completion suggestions.

   // Previously we had no expectation, now we expect an int.
   var _ []int = make([]int, <>)

Change-Id: Ifd349767662ab6902d3a3ea9e52de7df70cb37c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/217310
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ingo Oeser <nightlyone@googlemail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-02 23:20:50 +00:00

53 lines
2.5 KiB
Go

package builtins
func _() {
var (
aSlice []int //@item(builtinSlice, "aSlice", "[]int", "var")
aMap map[string]int //@item(builtinMap, "aMap", "map[string]int", "var")
aString string //@item(builtinString, "aString", "string", "var")
aArray [0]int //@item(builtinArray, "aArray", "[0]int", "var")
aArrayPtr *[0]int //@item(builtinArrayPtr, "aArrayPtr", "*[0]int", "var")
aChan chan int //@item(builtinChan, "aChan", "chan int", "var")
aPtr *int //@item(builtinPtr, "aPtr", "*int", "var")
aInt int //@item(builtinInt, "aInt", "int", "var")
)
type (
aSliceType []int //@item(builtinSliceType, "aSliceType", "[]int", "type")
aChanType chan int //@item(builtinChanType, "aChanType", "chan int", "type")
aMapType map[string]int //@item(builtinMapType, "aMapType", "map[string]int", "type")
)
close() //@rank(")", builtinChan, builtinSlice)
append() //@rank(")", builtinSlice, builtinChan)
copy() //@rank(")", builtinSlice, builtinChan)
copy(aSlice, aS) //@rank(")", builtinSlice, builtinString)
copy(aS, aSlice) //@rank(",", builtinSlice, builtinString)
delete() //@rank(")", builtinMap, builtinChan)
delete(aMap, aS) //@rank(")", builtinString, builtinSlice)
len() //@rank(")", builtinSlice, builtinInt),rank(")", builtinMap, builtinInt),rank(")", builtinString, builtinInt),rank(")", builtinArray, builtinInt),rank(")", builtinArrayPtr, builtinPtr),rank(")", builtinChan, builtinInt)
cap() //@rank(")", builtinSlice, builtinMap),rank(")", builtinArray, builtinString),rank(")", builtinArrayPtr, builtinPtr),rank(")", builtinChan, builtinInt)
make() //@rank(")", builtinMapType, int),rank(")", builtinChanType, int),rank(")", builtinSliceType, int),rank(")", builtinMapType, builtinMap)
make(aSliceType, a) //@rank(")", builtinInt, builtinSlice)
var _ []int = make() //@rank(")", builtinSliceType, builtinSlice)
type myStruct struct{} //@item(builtinStructType, "myStruct", "struct{...}", "struct")
new() //@rank(")", builtinStructType, builtinInt)
var _ *myStruct = new() //@rank(")", builtinStructType, int)
for k := range a { //@rank(" {", builtinSlice, builtinInt),rank(" {", builtinString, builtinInt),rank(" {", builtinChan, builtinInt),rank(" {", builtinArray, builtinInt),rank(" {", builtinArrayPtr, builtinInt),rank(" {", builtinMap, builtinInt),
}
for k, v := range a { //@rank(" {", builtinSlice, builtinChan)
}
<-a //@rank(" //", builtinChan, builtinInt)
}