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

     1  This test exercises completion around various statements.
     2  
     3  -- flags --
     4  -ignore_extra_diags
     5  
     6  -- settings.json --
     7  {
     8  	"usePlaceholders": true
     9  }
    10  
    11  -- go.mod --
    12  module golang.org/lsptests/statements
    13  
    14  -- append.go --
    15  package statements
    16  
    17  func _() {
    18  	type mySlice []int
    19  
    20  	var (
    21  		abc    []int   //@item(stmtABC, "abc", "[]int", "var")
    22  		abcdef mySlice //@item(stmtABCDEF, "abcdef", "mySlice", "var")
    23  	)
    24  
    25  	/* abcdef = append(abcdef, ) */ //@item(stmtABCDEFAssignAppend, "abcdef = append(abcdef, )", "", "func")
    26  
    27  	// don't offer "abc = append(abc, )" because "abc" isn't necessarily
    28  	// better than "abcdef".
    29  	abc //@complete(" //", stmtABC, stmtABCDEF)
    30  
    31  	abcdef //@complete(" //", stmtABCDEF, stmtABCDEFAssignAppend)
    32  
    33  	/* append(abc, ) */ //@item(stmtABCAppend, "append(abc, )", "", "func")
    34  
    35  	abc = app //@snippet(" //", stmtABCAppend, "append(abc, ${1:})")
    36  }
    37  
    38  func _() {
    39  	var s struct{ xyz []int }
    40  
    41  	/* xyz = append(s.xyz, ) */ //@item(stmtXYZAppend, "xyz = append(s.xyz, )", "", "func")
    42  
    43  	s.x //@snippet(" //", stmtXYZAppend, "xyz = append(s.xyz, ${1:})")
    44  
    45  	/* s.xyz = append(s.xyz, ) */ //@item(stmtDeepXYZAppend, "s.xyz = append(s.xyz, )", "", "func")
    46  
    47  	sx //@snippet(" //", stmtDeepXYZAppend, "s.xyz = append(s.xyz, ${1:})")
    48  }
    49  
    50  func _() {
    51  	var foo [][]int
    52  
    53  	/* append(foo[0], ) */ //@item(stmtFooAppend, "append(foo[0], )", "", "func")
    54  
    55  	foo[0] = app //@complete(" //", stmtFooAppend),snippet(" //", stmtFooAppend, "append(foo[0], ${1:})")
    56  }
    57  
    58  -- if_err_check_return.go --
    59  package statements
    60  
    61  import (
    62  	"bytes"
    63  	"io"
    64  	"os"
    65  )
    66  
    67  func one() (int, float32, io.Writer, *int, []int, bytes.Buffer, error) {
    68  	/* if err != nil { return err } */ //@item(stmtOneIfErrReturn, "if err != nil { return err }", "", "")
    69  	/* err != nil { return err } */ //@item(stmtOneErrReturn, "err != nil { return err }", "", "")
    70  
    71  	_, err := os.Open("foo")
    72  	//@snippet("", stmtOneIfErrReturn, "if err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}")
    73  
    74  	_, err = os.Open("foo")
    75  	i //@snippet(" //", stmtOneIfErrReturn, "if err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}")
    76  
    77  	_, err = os.Open("foo")
    78  	if er //@snippet(" //", stmtOneErrReturn, "err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}")
    79  
    80  	_, err = os.Open("foo")
    81  	if //@snippet(" //", stmtOneIfErrReturn, "if err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}")
    82  
    83  	_, err = os.Open("foo")
    84  	if //@snippet("//", stmtOneIfErrReturn, "if err != nil {\n\treturn 0, 0, nil, nil, nil, bytes.Buffer{\\}, ${1:err}\n\\}")
    85  }
    86  
    87  -- if_err_check_return2.go --
    88  package statements
    89  
    90  import "os"
    91  
    92  func two() error {
    93  	var s struct{ err error }
    94  
    95  	/* if s.err != nil { return s.err } */ //@item(stmtTwoIfErrReturn, "if s.err != nil { return s.err }", "", "")
    96  
    97  	_, s.err = os.Open("foo")
    98  	//@snippet("", stmtTwoIfErrReturn, "if s.err != nil {\n\treturn ${1:s.err}\n\\}")
    99  }
   100  
   101  -- if_err_check_test.go --
   102  package statements
   103  
   104  import (
   105  	"os"
   106  	"testing"
   107  )
   108  
   109  func TestErr(t *testing.T) {
   110  	/* if err != nil { t.Fatal(err) } */ //@item(stmtOneIfErrTFatal, "if err != nil { t.Fatal(err) }", "", "")
   111  
   112  	_, err := os.Open("foo")
   113  	//@snippet("", stmtOneIfErrTFatal, "if err != nil {\n\tt.Fatal(err)\n\\}")
   114  }
   115  
   116  func BenchmarkErr(b *testing.B) {
   117  	/* if err != nil { b.Fatal(err) } */ //@item(stmtOneIfErrBFatal, "if err != nil { b.Fatal(err) }", "", "")
   118  
   119  	_, err := os.Open("foo")
   120  	//@snippet("", stmtOneIfErrBFatal, "if err != nil {\n\tb.Fatal(err)\n\\}")
   121  }
   122  
   123  -- return.go --
   124  package statements
   125  
   126  //@item(stmtReturnZeroValues, `return 0, "", nil`)
   127  
   128  func foo() (int, string, error) {
   129  	ret //@snippet(" ", stmtReturnZeroValues, "return ${1:0}, ${2:\"\"}, ${3:nil}")
   130  }
   131  
   132  func bar() (int, string, error) {
   133  	return //@snippet(" ", stmtReturnZeroValues, "return ${1:0}, ${2:\"\"}, ${3:nil}")
   134  }