golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/completion/func_rank.txt (about)

     1  This test checks various ranking of completion results within function call
     2  context.
     3  
     4  -- flags --
     5  -ignore_extra_diags
     6  
     7  -- settings.json --
     8  {
     9  	"completeUnimported": false,
    10  	"deepCompletion": false
    11  }
    12  
    13  -- func_rank.go --
    14  package func_rank
    15  
    16  import "net/http"
    17  
    18  var stringAVar = "var"    //@item(stringAVar, "stringAVar", "string", "var")
    19  func stringBFunc() string { return "str" } //@item(stringBFunc, "stringBFunc", "func() string", "func")
    20  type stringer struct{}    //@item(stringer, "stringer", "struct{...}", "struct")
    21  
    22  func _() stringer //@complete("tr", stringer)
    23  
    24  func _(val stringer) {} //@complete("tr", stringer)
    25  
    26  func (stringer) _() {} //@complete("tr", stringer)
    27  
    28  func _() {
    29  	var s struct {
    30  		AA int    //@item(rankAA, "AA", "int", "field")
    31  		AB string //@item(rankAB, "AB", "string", "field")
    32  		AC int    //@item(rankAC, "AC", "int", "field")
    33  	}
    34  	fnStr := func(string) {}
    35  	fnStr(s.A)      //@complete(")", rankAB, rankAA, rankAC)
    36  	fnStr("" + s.A) //@complete(")", rankAB, rankAA, rankAC)
    37  
    38  	fnInt := func(int) {}
    39  	fnInt(-s.A) //@complete(")", rankAA, rankAC, rankAB)
    40  
    41  	// no expected type
    42  	fnInt(func() int { s.A }) //@complete(" }", rankAA, rankAB, rankAC)
    43  	fnInt(s.A())              //@complete("()", rankAA, rankAC, rankAB)
    44  	fnInt([]int{}[s.A])       //@complete("])", rankAA, rankAC, rankAB)
    45  	fnInt([]int{}[:s.A])      //@complete("])", rankAA, rankAC, rankAB)
    46  
    47  	fnInt(s.A.(int)) //@complete(".(", rankAA, rankAC, rankAB)
    48  
    49  	fnPtr := func(*string) {}
    50  	fnPtr(&s.A) //@complete(")", rankAB, rankAA, rankAC)
    51  
    52  	var aaPtr *string //@item(rankAAPtr, "aaPtr", "*string", "var")
    53  	var abPtr *int    //@item(rankABPtr, "abPtr", "*int", "var")
    54  	fnInt(*a)         //@complete(")", rankABPtr, rankAAPtr, stringAVar)
    55  
    56  	_ = func() string {
    57  		return s.A //@complete(" //", rankAB, rankAA, rankAC)
    58  	}
    59  }
    60  
    61  type foo struct {
    62  	fooPrivateField int //@item(rankFooPrivField, "fooPrivateField", "int", "field")
    63  	FooPublicField  int //@item(rankFooPubField, "FooPublicField", "int", "field")
    64  }
    65  
    66  func (foo) fooPrivateMethod() int { //@item(rankFooPrivMeth, "fooPrivateMethod", "func() int", "method")
    67  	return 0
    68  }
    69  
    70  func (foo) FooPublicMethod() int { //@item(rankFooPubMeth, "FooPublicMethod", "func() int", "method")
    71  	return 0
    72  }
    73  
    74  func _() {
    75  	var _ int = foo{}. //@rank(" //", rankFooPrivField, rankFooPubField),rank(" //", rankFooPrivMeth, rankFooPubMeth),rank(" //", rankFooPrivField, rankFooPrivMeth)
    76  }
    77  
    78  func _() {
    79  	HandleFunc //@item(httpHandleFunc, "HandleFunc", "func(pattern string, handler func(http.ResponseWriter, *http.Request))", "func")
    80  	HandlerFunc //@item(httpHandlerFunc, "HandlerFunc", "func(http.ResponseWriter, *http.Request)", "type")
    81  
    82  	http.HandleFunc //@rank(" //", httpHandleFunc, httpHandlerFunc)
    83  }