1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
This test checks completion of Go keywords.
-- flags --
-ignore_extra_diags
-filter_keywords=false
-- settings.json --
{
"completeUnimported": false,
"matcher": "caseInsensitive",
"experimentalPostfixCompletions": false
}
-- keywords.go --
package keywords
//@rank("", type),rank("", func),rank("", var),rank("", const),rank("", import)
func _() {
var test int //@rank(" //", int, interface)
var tChan chan int
var _ m //@complete(" //", map)
var _ f //@complete(" //", func)
var _ c //@complete(" //", chan)
var _ str //@rank(" //", string, struct)
type _ int //@rank(" //", interface, int)
type _ str //@rank(" //", struct, string)
switch test {
case 1: // TODO: trying to complete case here will break because the parser won't return *ast.Ident
b //@complete(" //", break)
case 2:
f //@complete(" //", fallthrough, for)
r //@complete(" //", return)
d //@complete(" //", default, defer)
c //@complete(" //", case, const)
}
switch test.(type) {
case fo: //@complete(":")
case int:
b //@complete(" //", break)
case int32:
f //@complete(" //", for)
d //@complete(" //", default, defer)
r //@complete(" //", return)
c //@complete(" //", case, const)
}
select {
case <-tChan:
b //@complete(" //", break)
c //@complete(" //", case, const)
}
for index := 0; index < test; index++ {
c //@complete(" //", const, continue)
b //@complete(" //", break)
}
for range []int{} {
c //@complete(" //", const, continue)
b //@complete(" //", break)
}
// Test function level keywords
//Using 2 characters to test because map output order is random
sw //@complete(" //", switch)
se //@complete(" //", select)
f //@complete(" //", for)
d //@complete(" //", defer)
g //@rank(" //", go),rank(" //", goto)
r //@complete(" //", return)
i //@complete(" //", if)
e //@complete(" //", else)
v //@complete(" //", var)
c //@complete(" //", const)
for i := r //@complete(" //", range)
}
/* package */ //@item(package, "package", "", "keyword")
/* import */ //@item(import, "import", "", "keyword")
/* func */ //@item(func, "func", "", "keyword")
/* type */ //@item(type, "type", "", "keyword")
/* var */ //@item(var, "var", "", "keyword")
/* const */ //@item(const, "const", "", "keyword")
/* break */ //@item(break, "break", "", "keyword")
/* default */ //@item(default, "default", "", "keyword")
/* case */ //@item(case, "case", "", "keyword")
/* defer */ //@item(defer, "defer", "", "keyword")
/* go */ //@item(go, "go", "", "keyword")
/* for */ //@item(for, "for", "", "keyword")
/* if */ //@item(if, "if", "", "keyword")
/* else */ //@item(else, "else", "", "keyword")
/* switch */ //@item(switch, "switch", "", "keyword")
/* select */ //@item(select, "select", "", "keyword")
/* fallthrough */ //@item(fallthrough, "fallthrough", "", "keyword")
/* continue */ //@item(continue, "continue", "", "keyword")
/* return */ //@item(return, "return", "", "keyword")
/* goto */ //@item(goto, "goto", "", "keyword")
/* struct */ //@item(struct, "struct", "", "keyword")
/* interface */ //@item(interface, "interface", "", "keyword")
/* map */ //@item(map, "map", "", "keyword")
/* chan */ //@item(chan, "chan", "", "keyword")
/* range */ //@item(range, "range", "", "keyword")
/* string */ //@item(string, "string", "", "type")
/* int */ //@item(int, "int", "", "type")
-- accidental_keywords.go --
package keywords
// non-matching candidate - shouldn't show up as completion
var apple = "apple"
func _() {
foo.bar() // insert some extra statements to exercise our AST surgery
variance := 123 //@item(kwVariance, "variance", "int", "var")
foo.bar()
println(var) //@complete(")", kwVariance)
}
func _() {
foo.bar()
var s struct { variance int } //@item(kwVarianceField, "variance", "int", "field")
foo.bar()
s.var //@complete(" //", kwVarianceField)
}
func _() {
channel := 123 //@item(kwChannel, "channel", "int", "var")
chan //@complete(" //", kwChannel)
foo.bar()
}
func _() {
foo.bar()
var typeName string //@item(kwTypeName, "typeName", "string", "var")
foo.bar()
type //@complete(" //", kwTypeName)
}
-- empty_select.go --
package keywords
func _() {
select {
c //@complete(" //", case)
}
}
-- empty_switch.go --
package keywords
func _() {
switch {
//@complete("", case, default)
}
switch test.(type) {
d //@complete(" //", default)
}
}
|