| 1 |
This test exercises basic tests for signature help. |
| 2 |
|
| 3 |
-- flags -- |
| 4 |
-ignore_extra_diags |
| 5 |
|
| 6 |
-- go.mod -- |
| 7 |
module golang.org/lsptests |
| 8 |
|
| 9 |
go 1.18 |
| 10 |
|
| 11 |
-- signature/signature.go -- |
| 12 |
// Package signature has tests for signature help. |
| 13 |
package signature |
| 14 |
|
| 15 |
import ( |
| 16 |
"bytes" |
| 17 |
"encoding/json" |
| 18 |
"math/big" |
| 19 |
"fmt" |
| 20 |
) |
| 21 |
|
| 22 |
func Foo(a string, b int) (c bool) { |
| 23 |
return |
| 24 |
} |
| 25 |
|
| 26 |
func Bar(float64, ...byte) { |
| 27 |
} |
| 28 |
|
| 29 |
func FooArr(a []int) { |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
func NoArgs() { |
| 34 |
} |
| 35 |
|
| 36 |
type myStruct struct{} |
| 37 |
|
| 38 |
type Bar struct { |
| 39 |
A, B, C, D string |
| 40 |
} |
| 41 |
|
| 42 |
func (*myStruct) foo(e *json.Decoder) (*big.Int, error) { |
| 43 |
return nil, nil |
| 44 |
} |
| 45 |
|
| 46 |
type MyType struct{} |
| 47 |
|
| 48 |
type MyFunc func(foo int) string |
| 49 |
|
| 50 |
type Alias = int |
| 51 |
type OtherAlias = int |
| 52 |
type StringAlias = string |
| 53 |
|
| 54 |
func AliasSlice(a []*Alias) (b Alias) { return 0 } |
| 55 |
func AliasMap(a map[*Alias]StringAlias) (b, c map[*Alias]StringAlias) { return nil, nil } |
| 56 |
func OtherAliasMap(a, b map[Alias]OtherAlias) map[Alias]OtherAlias { return nil } |
| 57 |
|
| 58 |
func Qux() { |
| 59 |
Foo("foo", 123) //@signature(re"()\\(", "Foo(a string, b int) (c bool)", -1) |
| 60 |
Foo("foo", 123) //@signature(re"()123", "Foo(a string, b int) (c bool)", 1) |
| 61 |
Foo("foo", 123) //@signature(re"(),", "Foo(a string, b int) (c bool)", 0) |
| 62 |
Foo("foo", 123) //@signature(re"() 1", "Foo(a string, b int) (c bool)", 1) |
| 63 |
Foo("foo", 123) //@signature(re"()\\)", "Foo(a string, b int) (c bool)", 1) |
| 64 |
Foo("foo", 123) //@signature(re"()o", "Foo(a string, b int) (c bool)", -1) |
| 65 |
_ = Foo //@signature(re"()o", "Foo(a string, b int) (c bool)", -1) |
| 66 |
Foo //@signature(re"()o", "Foo(a string, b int) (c bool)", -1) |
| 67 |
Foo() //@signature(re"()\\(", "Foo(a string, b int) (c bool)", -1) |
| 68 |
|
| 69 |
Bar(13.37, 0x13) //@signature(re"()13.37", "Bar(float64, ...byte)", 0) |
| 70 |
Bar(13.37, 0x37) //@signature(re"()0x37", "Bar(float64, ...byte)", 1) |
| 71 |
Bar(13.37, 1, 2, 3, 4) //@signature(re"()4", "Bar(float64, ...byte)", 1) |
| 72 |
|
| 73 |
NoArgs() //@signature(re"()\\(", "NoArgs()", -1) |
| 74 |
NoArgs //@signature(re"()s", "NoArgs()", -1) |
| 75 |
|
| 76 |
fn := func(hi, there string) func(i int) rune { |
| 77 |
return func(int) rune { return 0 } |
| 78 |
} |
| 79 |
|
| 80 |
fn("hi", "there") //@signature(re"()hi", "", 0) |
| 81 |
fn("hi", "there") //@signature(re"(),", "fn(hi string, there string) func(i int) rune", 0) |
| 82 |
fn("hi", "there")(1) //@signature(re"()1", "func(i int) rune", 0) |
| 83 |
|
| 84 |
fnPtr := &fn |
| 85 |
(*fnPtr)("hi", "there") //@signature(re"(),", "func(hi string, there string) func(i int) rune", 0) |
| 86 |
|
| 87 |
var fnIntf any = Foo |
| 88 |
fnIntf.(func(string, int) bool)("hi", 123) //@signature(re"()123", "func(string, int) bool", 1) |
| 89 |
|
| 90 |
(&bytes.Buffer{}).Next(2) //@signature(re"()2", "Next(n int) []byte", 0) |
| 91 |
|
| 92 |
myFunc := MyFunc(func(n int) string { return "" }) |
| 93 |
myFunc(123) //@signature(re"()123", "myFunc(foo int) string", 0) |
| 94 |
|
| 95 |
var ms myStruct |
| 96 |
ms.foo(nil) //@signature(re"()nil", "foo(e *json.Decoder) (*big.Int, error)", 0) |
| 97 |
|
| 98 |
_ = make([]int, 1, 2) //@signature(re"()2", "make(t Type, size ...int) Type", 1) |
| 99 |
|
| 100 |
Foo(myFunc(123), 456) //@signature(re"()o\\(", "Foo(a string, b int) (c bool)", -1) |
| 101 |
Foo(myFunc(123), 456) //@signature(re"()\\(m", "Foo(a string, b int) (c bool)", -1) |
| 102 |
Foo( myFunc(123), 456) //@signature(re"() m", "Foo(a string, b int) (c bool)", 0) |
| 103 |
Foo(myFunc(123), 456) //@signature(re"(), ", "Foo(a string, b int) (c bool)", 0) |
| 104 |
Foo(myFunc(123), 456) //@signature(re"()456", "Foo(a string, b int) (c bool)", 1) |
| 105 |
Foo(myFunc) //@signature(re"()\\)", "Foo(a string, b int) (c bool)", 0) |
| 106 |
Foo(myFunc(123), 456) //@signature(re"()\\(1", "myFunc(foo int) string", -1) |
| 107 |
Foo(myFunc(123), 456) //@signature(re"()123", "myFunc(foo int) string", 0) |
| 108 |
|
| 109 |
fmt.Println //@signature(re"()ln", "Println(a ...any) (n int, err error)", -1) |
| 110 |
fmt.Println(myFunc) //@signature(re"()ln", "Println(a ...any) (n int, err error)", -1) |
| 111 |
fmt.Println(myFunc) //@signature(re"()Func", "myFunc(foo int) string", -1) |
| 112 |
|
| 113 |
var hi string = "hello" |
| 114 |
var wl string = " world: %s" |
| 115 |
fmt.Println(fmt.Sprintf(wl, myFunc)) //@signature(re"()Func", "myFunc(foo int) string", -1) |
| 116 |
fmt.Println(fmt.Sprintf(wl, myFunc)) //@signature(re"()wl", "Sprintf(format string, a ...any) string", 0) |
| 117 |
fmt.Println(fmt.Sprintf(wl, myFunc)) //@signature(re"() m", "Sprintf(format string, a ...any) string", 1) |
| 118 |
fmt.Println(hi, fmt.Sprintf(wl, myFunc)) //@signature(re"()Sprint", "Sprintf(format string, a ...any) string", -1) |
| 119 |
fmt.Println(hi, fmt.Sprintf(wl, myFunc)) //@signature(re"() fmt", "Println(a ...any) (n int, err error)", 0) |
| 120 |
fmt.Println(hi, fmt.Sprintf(wl, myFunc)) //@signature(re"()hi", "Println(a ...any) (n int, err error)", 0) |
| 121 |
|
| 122 |
panic("oops!") //@signature(re"()\\)", "panic(v any)", 0) |
| 123 |
println("hello", "world") //@signature(re"(),", "println(args ...Type)", 0) |
| 124 |
|
| 125 |
Hello(func() { |
| 126 |
//@signature(re"()\\/\\/", "", 0) |
| 127 |
}) |
| 128 |
|
| 129 |
AliasSlice() //@signature(re"()\\)", "AliasSlice(a []*Alias) (b Alias)", 0) |
| 130 |
AliasMap() //@signature(re"()\\)", "AliasMap(a map[*Alias]StringAlias) (b map[*Alias]StringAlias, c map[*Alias]StringAlias)", 0) |
| 131 |
OtherAliasMap() //@signature(re"()\\)", "OtherAliasMap(a map[Alias]OtherAlias, b map[Alias]OtherAlias) map[Alias]OtherAlias", 0) |
| 132 |
|
| 133 |
var l []Foo |
| 134 |
l = append(l, Foo{ //@signature(re"(),", "append(slice []Type, elems ...Type) []Type", 0) |
| 135 |
A: "hello", //@signature(re"(),", "", 0) |
| 136 |
B: "world", //@signature(re"(),", "", 0) |
| 137 |
}) |
| 138 |
|
| 139 |
FooArr([]int{1, 2, 3, 4, 5}) //@signature(re"()1", "", 0) |
| 140 |
} |
| 141 |
|
| 142 |
func Hello(func()) {} |
| 143 |
|
| 144 |
-- signature/signature2.go -- |
| 145 |
package signature |
| 146 |
|
| 147 |
func _() { |
| 148 |
Foo(//@signature(re"()\\/\\/", "Foo(a string, b int) (c bool)", 0) |
| 149 |
Foo.//@signature(re"()\\/\\/", "Foo(a string, b int) (c bool)", 0) |
| 150 |
Foo.//@signature(re"()oo", "Foo(a string, b int) (c bool)", 0) |
| 151 |
} |
| 152 |
|
| 153 |
-- signature/signature3.go -- |
| 154 |
package signature |
| 155 |
|
| 156 |
func _() { |
| 157 |
Foo("hello",//@signature(re"()\\/\\/", "Foo(a string, b int) (c bool)", 1) |
| 158 |
} |
| 159 |
|
| 160 |
-- signature/nonsignature.go -- |
| 161 |
package signature |
| 162 |
|
| 163 |
var x = (1) //@signature(re"()1\\)", "", 0) |
| 164 |
|
| 165 |
-- signature/signature_test.go -- |
| 166 |
package signature_test |
| 167 |
|
| 168 |
import ( |
| 169 |
"testing" |
| 170 |
|
| 171 |
sig "golang.org/lsptests/signature" |
| 172 |
) |
| 173 |
|
| 174 |
func TestSignature(t *testing.T) { |
| 175 |
sig.AliasSlice() //@signature(re"()\\)", "AliasSlice(a []*sig.Alias) (b sig.Alias)", 0) |
| 176 |
sig.AliasMap() //@signature(re"()\\)", "AliasMap(a map[*sig.Alias]sig.StringAlias) (b map[*sig.Alias]sig.StringAlias, c map[*sig.Alias]sig.StringAlias)", 0) |
| 177 |
sig.OtherAliasMap() //@signature(re"()\\)", "OtherAliasMap(a map[sig.Alias]sig.OtherAlias, b map[sig.Alias]sig.OtherAlias) map[sig.Alias]sig.OtherAlias", 0) |
| 178 |
} |
| 179 |
|
| 180 |
-- snippets/snippets.go -- |
| 181 |
package snippets |
| 182 |
|
| 183 |
import ( |
| 184 |
"golang.org/lsptests/signature" |
| 185 |
) |
| 186 |
|
| 187 |
type CoolAlias = int //@item(CoolAlias, "CoolAlias", "int", "type") |
| 188 |
|
| 189 |
type structy struct { |
| 190 |
x signature.MyType |
| 191 |
} |
| 192 |
|
| 193 |
func X(_ map[signature.Alias]CoolAlias) (map[signature.Alias]CoolAlias) { |
| 194 |
return nil |
| 195 |
} |
| 196 |
|
| 197 |
func _() { |
| 198 |
X() //@signature(re"()\\)", "X(_ map[signature.Alias]CoolAlias) map[signature.Alias]CoolAlias", 0) |
| 199 |
_ = signature.MyType{} //@item(literalMyType, "signature.MyType{}", "", "var") |
| 200 |
s := structy{ |
| 201 |
x: //@snippet(re"() \\/\\/", literalMyType, "signature.MyType{\\}") |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
-- importedcomplit/importedcomplit.go -- |
| 206 |
package importedcomplit |
| 207 |
|
| 208 |
import ( |
| 209 |
// TODO(rfindley): re-enable after moving to new framework |
| 210 |
// "golang.org/lsptests/foo" |
| 211 |
|
| 212 |
// import completions (separate blocks to avoid comment alignment) |
| 213 |
"crypto/elli" //@complete(re"i()\"", cryptoImport) |
| 214 |
|
| 215 |
"fm" //@complete(re"m()\"", fmtImport) |
| 216 |
|
| 217 |
"go/pars" //@complete(re"s()\"", parserImport) |
| 218 |
|
| 219 |
namedParser "go/pars" //@complete(re"s()\"", parserImport) |
| 220 |
|
| 221 |
"golang.org/lspte" //@complete(re"e()\"", lsptestsImport) |
| 222 |
|
| 223 |
"golang.org/lsptests/sign" //@complete(re"n()\"", signatureImport) |
| 224 |
|
| 225 |
"golang.org/lsptests/sign" //@complete(re"()ests", lsptestsImport) |
| 226 |
|
| 227 |
"golang.org/lsptests/signa" //@complete(re"()na", signatureImport) |
| 228 |
) |
| 229 |
|
| 230 |
func _() { |
| 231 |
var V int //@item(icVVar, "V", "int", "var") |
| 232 |
|
| 233 |
// TODO(rfindley): re-enable after moving to new framework |
| 234 |
// _ = foo.StructFoo{V} // complete("}", Value, icVVar) |
| 235 |
} |
| 236 |
|
| 237 |
func _() { |
| 238 |
var ( |
| 239 |
aa string //@item(icAAVar, "aa", "string", "var") |
| 240 |
ab int //@item(icABVar, "ab", "int", "var") |
| 241 |
) |
| 242 |
|
| 243 |
// TODO(rfindley): re-enable after moving to new framework |
| 244 |
// _ = foo.StructFoo{a} // complete("}", abVar, aaVar) |
| 245 |
|
| 246 |
var s struct { |
| 247 |
AA string //@item(icFieldAA, "AA", "string", "field") |
| 248 |
AB int //@item(icFieldAB, "AB", "int", "field") |
| 249 |
} |
| 250 |
|
| 251 |
// TODO(rfindley): re-enable after moving to new framework |
| 252 |
//_ = foo.StructFoo{s.} // complete("}", icFieldAB, icFieldAA) |
| 253 |
} |
| 254 |
|
| 255 |
/* "fmt" */ //@item(fmtImport, "fmt", "\"fmt\"", "package") |
| 256 |
/* "go/parser" */ //@item(parserImport, "parser", "\"go/parser\"", "package") |
| 257 |
/* "golang.org/lsptests/signature" */ //@item(signatureImport, "signature", "\"golang.org/lsptests/signature\"", "package") |
| 258 |
/* "golang.org/lsptests/" */ //@item(lsptestsImport, "lsptests/", "\"golang.org/lsptests/\"", "package") |
| 259 |
/* "crypto/elliptic" */ //@item(cryptoImport, "elliptic", "\"crypto/elliptic\"", "package") |