Skip to content

Commit ba2dfd9

Browse files
vinaycharlie01madelinekalil
authored andcommitted
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 #4026 Change-Id: Id02283fb9ff6a77b4f76b279ae5196aac0bf0d8b GitHub-Last-Rev: fa67748 GitHub-Pull-Request: #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>
1 parent b598774 commit ba2dfd9

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

extension/snippets/go.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@
8080
"body": "for ${1:_}, ${2:v} := range ${3:v} {\n\t$0\n}",
8181
"description": "Snippet for a for range loop"
8282
},
83+
"for range single var statement": {
84+
"prefix": "forrval",
85+
"body": "for ${1:v} := range ${2:v} {\n\t$0\n}",
86+
"description": "Snippet for a for range loop with single variable (e.g. channel)"
87+
},
8388
"channel declaration": {
8489
"prefix": "ch",
8590
"body": "chan ${1:type}",

0 commit comments

Comments
 (0)