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

     1  This test checks behavior of completion within append expressions.
     2  
     3  -- flags --
     4  -ignore_extra_diags
     5  
     6  -- go.mod --
     7  module golang.org/lsptests/append
     8  
     9  go 1.18
    10  
    11  -- append.go --
    12  package append
    13  
    14  func foo([]string)  {}
    15  func bar(...string) {}
    16  
    17  func _() {
    18  	var (
    19  		aInt     []int    //@item(appendInt, "aInt", "[]int", "var")
    20  		aStrings []string //@item(appendStrings, "aStrings", "[]string", "var")
    21  		aString  string   //@item(appendString, "aString", "string", "var")
    22  	)
    23  
    24  	append(aStrings, a)                     //@rank(")", appendString, appendInt)
    25  	var _ interface{} = append(aStrings, a) //@rank(")", appendString, appendInt)
    26  	var _ []string = append(oops, a)        //@rank(")", appendString, appendInt)
    27  
    28  	foo(append())                  //@rank("))", appendStrings, appendInt),rank("))", appendStrings, appendString)
    29  	foo(append([]string{}, a))     //@rank("))", appendStrings, appendInt),rank("))", appendString, appendInt),snippet("))", appendStrings, "aStrings...")
    30  	foo(append([]string{}, "", a)) //@rank("))", appendString, appendInt),rank("))", appendString, appendStrings)
    31  
    32  	// Don't add "..." to append() argument.
    33  	bar(append()) //@snippet("))", appendStrings, "aStrings")
    34  
    35  	type baz struct{}
    36  	baz{}                       //@item(appendBazLiteral, "baz{}", "", "var")
    37  	var bazzes []baz            //@item(appendBazzes, "bazzes", "[]baz", "var")
    38  	var bazzy baz               //@item(appendBazzy, "bazzy", "baz", "var")
    39  	bazzes = append(bazzes, ba) //@rank(")", appendBazzy, appendBazLiteral, appendBazzes)
    40  
    41  	var b struct{ b []baz }
    42  	b.b                  //@item(appendNestedBaz, "b.b", "[]baz", "field")
    43  	b.b = append(b.b, b) //@rank(")", appendBazzy, appendBazLiteral, appendNestedBaz)
    44  
    45  	var aStringsPtr *[]string  //@item(appendStringsPtr, "aStringsPtr", "*[]string", "var")
    46  	foo(append([]string{}, a)) //@snippet("))", appendStringsPtr, "*aStringsPtr...")
    47  
    48  	foo(append([]string{}, *a)) //@snippet("))", appendStringsPtr, "aStringsPtr...")
    49  }
    50  
    51  -- append2.go --
    52  package append
    53  
    54  func _() {
    55  	_ = append(a, struct) //@complete(")")
    56  }