github.com/jhump/golang-x-tools@v0.0.0-20220218190644-4958d6d39439/internal/lsp/testdata/signature/signature.go (about)

     1  // Package signature has tests for signature help.
     2  package signature
     3  
     4  import (
     5  	"bytes"
     6  	"encoding/json"
     7  	"math/big"
     8  )
     9  
    10  func Foo(a string, b int) (c bool) {
    11  	return
    12  }
    13  
    14  func Bar(float64, ...byte) {
    15  }
    16  
    17  type myStruct struct{}
    18  
    19  func (*myStruct) foo(e *json.Decoder) (*big.Int, error) {
    20  	return nil, nil
    21  }
    22  
    23  type MyType struct{}
    24  
    25  type MyFunc func(foo int) string
    26  
    27  type Alias = int
    28  type OtherAlias = int
    29  type StringAlias = string
    30  
    31  func AliasSlice(a []*Alias) (b Alias)                                 { return 0 }
    32  func AliasMap(a map[*Alias]StringAlias) (b, c map[*Alias]StringAlias) { return nil, nil }
    33  func OtherAliasMap(a, b map[Alias]OtherAlias) map[Alias]OtherAlias    { return nil }
    34  
    35  func Qux() {
    36  	Foo("foo", 123) //@signature("(", "Foo(a string, b int) (c bool)", 0)
    37  	Foo("foo", 123) //@signature("123", "Foo(a string, b int) (c bool)", 1)
    38  	Foo("foo", 123) //@signature(",", "Foo(a string, b int) (c bool)", 0)
    39  	Foo("foo", 123) //@signature(" 1", "Foo(a string, b int) (c bool)", 1)
    40  	Foo("foo", 123) //@signature(")", "Foo(a string, b int) (c bool)", 1)
    41  
    42  	Bar(13.37, 0x13)       //@signature("13.37", "Bar(float64, ...byte)", 0)
    43  	Bar(13.37, 0x37)       //@signature("0x37", "Bar(float64, ...byte)", 1)
    44  	Bar(13.37, 1, 2, 3, 4) //@signature("4", "Bar(float64, ...byte)", 1)
    45  
    46  	fn := func(hi, there string) func(i int) rune {
    47  		return func(int) rune { return 0 }
    48  	}
    49  
    50  	fn("hi", "there")    //@signature("hi", "", 0)
    51  	fn("hi", "there")    //@signature(",", "fn(hi string, there string) func(i int) rune", 0)
    52  	fn("hi", "there")(1) //@signature("1", "func(i int) rune", 0)
    53  
    54  	fnPtr := &fn
    55  	(*fnPtr)("hi", "there") //@signature(",", "func(hi string, there string) func(i int) rune", 0)
    56  
    57  	var fnIntf interface{} = Foo
    58  	fnIntf.(func(string, int) bool)("hi", 123) //@signature("123", "func(string, int) bool", 1)
    59  
    60  	(&bytes.Buffer{}).Next(2) //@signature("2", "Next(n int) []byte", 0)
    61  
    62  	myFunc := MyFunc(func(n int) string { return "" })
    63  	myFunc(123) //@signature("123", "myFunc(foo int) string", 0)
    64  
    65  	var ms myStruct
    66  	ms.foo(nil) //@signature("nil", "foo(e *json.Decoder) (*big.Int, error)", 0)
    67  
    68  	_ = make([]int, 1, 2) //@signature("2", "make(t Type, size ...int) Type", 1)
    69  
    70  	Foo(myFunc(123), 456) //@signature("myFunc", "Foo(a string, b int) (c bool)", 0)
    71  	Foo(myFunc(123), 456) //@signature("123", "myFunc(foo int) string", 0)
    72  
    73  	panic("oops!")            //@signature(")", "panic(v interface{})", 0)
    74  	println("hello", "world") //@signature(",", "println(args ...Type)", 0)
    75  
    76  	Hello(func() {
    77  		//@signature("//", "", 0)
    78  	})
    79  
    80  	AliasSlice()    //@signature(")", "AliasSlice(a []*Alias) (b Alias)", 0)
    81  	AliasMap()      //@signature(")", "AliasMap(a map[*Alias]StringAlias) (b map[*Alias]StringAlias, c map[*Alias]StringAlias)", 0)
    82  	OtherAliasMap() //@signature(")", "OtherAliasMap(a map[Alias]OtherAlias, b map[Alias]OtherAlias) map[Alias]OtherAlias", 0)
    83  }
    84  
    85  func Hello(func()) {}