github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/internal/lsp/testdata/typdef/typdef.go (about)

     1  package typdef
     2  
     3  type Struct struct { //@item(Struct, "Struct", "struct{...}", "struct")
     4  	Field string
     5  }
     6  
     7  type Int int //@item(Int, "Int", "int", "type")
     8  
     9  func _() {
    10  	var (
    11  		value Struct
    12  		point *Struct
    13  	)
    14  	_ = value //@typdef("value", Struct)
    15  	_ = point //@typdef("point", Struct)
    16  
    17  	var (
    18  		array   [3]Struct
    19  		slice   []Struct
    20  		ch      chan Struct
    21  		complex [3]chan *[5][]Int
    22  	)
    23  	_ = array   //@typdef("array", Struct)
    24  	_ = slice   //@typdef("slice", Struct)
    25  	_ = ch      //@typdef("ch", Struct)
    26  	_ = complex //@typdef("complex", Int)
    27  
    28  	var s struct {
    29  		x struct {
    30  			xx struct {
    31  				field1 []Struct
    32  				field2 []Int
    33  			}
    34  		}
    35  	}
    36  	s.x.xx.field1 //@typdef("field1", Struct)
    37  	s.x.xx.field2 //@typdef("field2", Int)
    38  }
    39  
    40  func F1() Int                              { return 0 }
    41  func F2() (Int, float64)                   { return 0, 0 }
    42  func F3() (Struct, int, bool, error)       { return Struct{}, 0, false, nil }
    43  func F4() (**int, Int, bool, *error)       { return nil, Struct{}, false, nil }
    44  func F5() (int, float64, error, Struct)    { return 0, 0, nil, Struct{} }
    45  func F6() (int, float64, ***Struct, error) { return 0, 0, nil, nil }
    46  
    47  func _() {
    48  	F1() //@typdef("F1", Int)
    49  	F2() //@typdef("F2", Int)
    50  	F3() //@typdef("F3", Struct)
    51  	F4() //@typdef("F4", Int)
    52  	F5() //@typdef("F5", Struct)
    53  	F6() //@typdef("F6", Struct)
    54  
    55  	f := func() Int { return 0 }
    56  	f() //@typdef("f", Int)
    57  }
    58  
    59  // https://github.com/golang/go/issues/38589#issuecomment-620350922
    60  func _() {
    61  	type myFunc func(int) Int //@item(myFunc, "myFunc", "func", "type")
    62  
    63  	var foo myFunc
    64  	bar := foo() //@typdef("foo", myFunc)
    65  }