Skip to content

Commit 5a6f0d0

Browse files
author
ALX99
committed
gopls: use clear function for the clear postfix
1 parent 977f6f7 commit 5a6f0d0

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

gopls/internal/golang/completion/postfix_snippets.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,8 @@ for {{.VarName .KeyType "k" | .Placeholder}}, {{.VarName .ElemType "v" | .Placeh
175175
label: "clear",
176176
details: "clear map contents",
177177
body: `{{if and (eq .Kind "map") .StmtOK -}}
178-
{{$k := (.VarName .KeyType "k")}}for {{$k}} := range {{.X}} {
179-
delete({{.X}}, {{$k}})
180-
}
181-
{{end}}`,
178+
clear({{.X}})
179+
{{- end}}`,
182180
}, {
183181
label: "keys",
184182
details: "create slice of keys",

gopls/internal/test/integration/completion/postfix_snippet_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ package foo
234234
235235
func _() {
236236
var foo map[string]int
237-
for k := range foo {
238-
delete(foo, k)
239-
}
240-
237+
clear(foo)
241238
}
242239
`,
243240
},

gopls/internal/test/marker/testdata/completion/postfix.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func _() {
8484
foo.fo //@snippet(" //", postfixFor, "for ${1:} := range foo {\n\t$0\n}")
8585
foo.forr //@snippet(" //", postfixForr, "for ${1:}, ${2:} := range foo {\n\t$0\n}")
8686
foo.rang //@snippet(" //", postfixRange, "for ${1:}, ${2:} := range foo {\n\t$0\n}")
87-
foo.clear //@snippet(" //", postfixClear, "for k := range foo {\n\tdelete(foo, k)\n}\n")
87+
foo.clear //@snippet(" //", postfixClear, "clear(foo)")
8888
foo.keys //@snippet(" //", postfixKeys, "keys := make([]int, 0, len(foo))\nfor k := range foo {\n\tkeys = append(keys, k)\n}\n")
8989
}
9090

0 commit comments

Comments
 (0)