snippets: add forrval snippet for single-variable range loops
Add a new snippet, forrval, that generates a for-range loop with a single variable, commonly used with channels and, in Go 1.23+, for value-only iteration over slices and maps.
The snippet expands to:
for v := range v {
}
Updates golang/vscode-go#4026
Change-Id: Id02283fb9ff6a77b4f76b279ae5196aac0bf0d8b
GitHub-Last-Rev: fa67748787d7da13f3156e2782cd26a1ad21bdcb
GitHub-Pull-Request: golang/vscode-go#4027
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/770800
Auto-Submit: Madeline Kalil <mkalil@google.com>
Reviewed-by: Madeline Kalil <mkalil@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/extension/snippets/go.json b/extension/snippets/go.json
index daa19cf..1d74250 100644
--- a/extension/snippets/go.json
+++ b/extension/snippets/go.json
@@ -80,6 +80,11 @@
"body": "for ${1:_}, ${2:v} := range ${3:v} {\n\t$0\n}",
"description": "Snippet for a for range loop"
},
+ "for range single var statement": {
+ "prefix": "forrval",
+ "body": "for ${1:v} := range ${2:v} {\n\t$0\n}",
+ "description": "Snippet for a for range loop with single variable (e.g. channel)"
+ },
"channel declaration": {
"prefix": "ch",
"body": "chan ${1:type}",