golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/completion/postfix_placeholder.txt (about) 1 These tests check that postfix completions when enable usePlaceholders 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/snippets 13 14 go 1.18 15 16 -- postfix.go -- 17 package snippets 18 19 import ( 20 "strconv" 21 ) 22 23 func _() { 24 /* for! */ //@item(postfixFor, "for!", "range over slice by index", "snippet") 25 /* forr! */ //@item(postfixForr, "forr!", "range over slice by index and value", "snippet") 26 /* range! */ //@item(postfixRange, "range!", "range over slice", "snippet") 27 /* var! */ //@item(postfixVar, "var!", "assign to variable", "snippet") 28 29 var foo []int 30 31 foo.fo //@snippet(" //", postfixFor, "for ${1:i} := range foo {\n\t$0\n}") 32 foo.forr //@snippet(" //", postfixForr, "for ${1:i}, ${2:v} := range foo {\n\t$0\n}") 33 foo.rang //@snippet(" //", postfixRange, "for ${1:i}, ${2:v} := range foo {\n\t$0\n}") 34 foo.va //@snippet(" //", postfixVar, "${1:i} := foo") 35 } 36 37 func _() { 38 /* for! */ //@item(postfixForMap, "for!", "range over map by key", "snippet") 39 /* forr! */ //@item(postfixForrMap, "forr!", "range over map by key and value", "snippet") 40 /* range! */ //@item(postfixRangeMap, "range!", "range over map", "snippet") 41 42 var foo map[int]int 43 44 foo.fo //@snippet(" //", postfixFor, "for ${1:k} := range foo {\n\t$0\n}") 45 foo.forr //@snippet(" //", postfixForr, "for ${1:k}, ${2:v} := range foo {\n\t$0\n}") 46 foo.rang //@snippet(" //", postfixRange, "for ${1:k}, ${2:v} := range foo {\n\t$0\n}") 47 } 48 49 func _() { 50 /* for! */ //@item(postfixForChannel, "for!", "range over channel", "snippet") 51 /* range! */ //@item(postfixRangeChannel, "range!", "range over channel", "snippet") 52 53 var foo chan int 54 55 foo.fo //@snippet(" //", postfixForChannel, "for ${1:e} := range foo {\n\t$0\n}") 56 foo.rang //@snippet(" //", postfixRangeChannel, "for ${1:e} := range foo {\n\t$0\n}") 57 } 58 59 type T struct { 60 Name string 61 } 62 63 func _() (string, T, map[string]string, error) { 64 /* iferr! */ //@item(postfixIfErr, "iferr!", "check error and return", "snippet") 65 /* variferr! */ //@item(postfixVarIfErr, "variferr!", "assign variables and check error", "snippet") 66 /* var! */ //@item(postfixVars, "var!", "assign to variables", "snippet") 67 68 69 var err error 70 err.iferr //@snippet(" //", postfixIfErr, "if err != nil {\n\treturn \"\", T{}, nil, ${1:err}\n}\n") 71 strconv.Atoi("32").iferr //@snippet(" //", postfixIfErr, "if _, err := strconv.Atoi(\"32\"); err != nil {\n\treturn \"\", T{}, nil, ${1:err}\n}\n") 72 strconv.Atoi("32").variferr //@snippet(" //", postfixVarIfErr, "${1:i}, ${2:err} := strconv.Atoi(\"32\")\nif ${2:err} != nil {\n\treturn \"\", T{}, nil, ${3:${2:err}}\n}\n") 73 74 // test function return multiple errors 75 var foo func() (error, error) 76 foo().iferr //@snippet(" //", postfixIfErr, "if _, err := foo(); err != nil {\n\treturn \"\", T{}, nil, ${1:err}\n}\n") 77 foo().variferr //@snippet(" //", postfixVarIfErr, "${1:err2}, ${2:err} := foo()\nif ${2:err} != nil {\n\treturn \"\", T{}, nil, ${3:${2:err}}\n}\n") 78 79 // test function just return error 80 var bar func() error 81 bar().iferr //@snippet(" //", postfixIfErr, "if err := bar(); err != nil {\n\treturn \"\", T{}, nil, ${1:err}\n}\n") 82 bar().variferr //@snippet(" //", postfixVarIfErr, "${1:err2} := bar()\nif ${1:err2} != nil {\n\treturn \"\", T{}, nil, ${2:${1:err2}}\n}\n") 83 }