Skip to content

Commit 0cbb72d

Browse files
committed
Fix snippet placeholder formatting
This change fixes some ambiguity in our snippet placeholders to confirm with stricter parsing rules in VS Code 1.12.0. Generally this requires prefixing an index (`${1:Placeholder Text}`) anywhere that a placeholder is used so that the syntax isn't ambiguous with a variable name. Snippet variables are a separate concept now. Resolves PowerShell#767.
1 parent 1a13c43 commit 0cbb72d

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

snippets/PowerShell.json

+34-34
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@
6464
"Example-Class": {
6565
"prefix": "ex-class",
6666
"body": [
67-
"class ${classname:MyClass} {",
67+
"class ${1:MyClass} {",
6868
"\t# Property: Holds name",
6969
"\t[String] \\$Name",
7070
"",
7171
"\t# Constructor: Creates a new MyClass object, with the specified name",
72-
"\t${classname:MyClass}([String] \\$NewName) {",
73-
"\t\t# Set name for ${classname:MyClass}",
72+
"\t${1:MyClass}([String] \\$NewName) {",
73+
"\t\t# Set name for ${1:MyClass}",
7474
"\t\t\\$this.Name = \\$NewName",
7575
"\t}",
7676
"",
@@ -465,7 +465,7 @@
465465
"Class": {
466466
"prefix": "class",
467467
"body": [
468-
"class ${ClassName} {",
468+
"class ${1:ClassName} {",
469469
"\t$0",
470470
"}"
471471
],
@@ -474,7 +474,7 @@
474474
"Constructor": {
475475
"prefix": "ctor",
476476
"body": [
477-
"${ClassName}(${OptionalParameters}) {",
477+
"${1:ClassName}(${2:OptionalParameters}) {",
478478
"\t$0",
479479
"}"
480480
],
@@ -483,21 +483,21 @@
483483
"Hidden Property": {
484484
"prefix": "proph",
485485
"body": [
486-
"hidden [${string}] $${PropertyName}"
486+
"hidden [${1:string}] $${0:PropertyName}"
487487
],
488488
"description": "Class hidden property definition snippet"
489489
},
490490
"Property": {
491491
"prefix": "prop",
492492
"body": [
493-
"[${string}] $${PropertyName}"
493+
"[${1:string}] $${0:PropertyName}"
494494
],
495495
"description": "Class property definition snippet"
496496
},
497497
"Method": {
498498
"prefix": "method",
499499
"body": [
500-
"[${void}] ${MethodName}($${OptionalParameters}) {",
500+
"[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {",
501501
"\t$0",
502502
"}"
503503
],
@@ -506,7 +506,7 @@
506506
"Enum": {
507507
"prefix": "enum",
508508
"body": [
509-
"enum ${EnumName} {",
509+
"enum ${1:EnumName} {",
510510
"\t$0",
511511
"}"
512512
],
@@ -515,7 +515,7 @@
515515
"Cmdlet": {
516516
"prefix": "cmdlet",
517517
"body": [
518-
"function ${name:Verb-Noun} {",
518+
"function ${1:Verb-Noun} {",
519519
"\t[CmdletBinding()]",
520520
"\tparam (",
521521
"\t\t$0",
@@ -557,10 +557,10 @@
557557
"Parameter": {
558558
"prefix": "parameter",
559559
"body": [
560-
"# ${Parameter help description}",
561-
"[Parameter(${AttributeValues})]",
562-
"[${ParameterType}]",
563-
"$${ParameterName}"
560+
"# ${1:Parameter help description}",
561+
"[Parameter(${2:AttributeValues})]",
562+
"[${3:ParameterType}]",
563+
"$${0:ParameterName}"
564564
],
565565
"description": "Parameter declaration snippet"
566566
},
@@ -569,15 +569,15 @@
569569
"body": [
570570
"# Specifies a path to one or more locations.",
571571
"[Parameter(Mandatory=\\$true,",
572-
" Position=${Position:0},",
573-
" ParameterSetName=\"${ParameterSetName:Path}\",",
572+
" Position=${1:0},",
573+
" ParameterSetName=\"${2:ParameterSetName}\",",
574574
" ValueFromPipeline=\\$true,",
575575
" ValueFromPipelineByPropertyName=\\$true,",
576576
" HelpMessage=\"Path to one or more locations.\")]",
577577
"[Alias(\"PSPath\")]",
578578
"[ValidateNotNullOrEmpty()]",
579579
"[string[]]",
580-
"$${ParameterName:Path}$0"
580+
"$${3:ParameterName}$0"
581581
],
582582
"description": "Parameter declaration snippet for Path parameter that does not accept wildcards. Do not use with parameter-literalpath."
583583
},
@@ -586,15 +586,15 @@
586586
"body": [
587587
"# Specifies a path to one or more locations. Wildcards are permitted.",
588588
"[Parameter(Mandatory=\\$true,",
589-
" Position=${Position:0},",
590-
" ParameterSetName=\"${ParameterSetName:Path}\",",
589+
" Position=${1:Position},",
590+
" ParameterSetName=\"${2:ParameterSetName}\",",
591591
" ValueFromPipeline=\\$true,",
592592
" ValueFromPipelineByPropertyName=\\$true,",
593593
" HelpMessage=\"Path to one or more locations.\")]",
594594
"[ValidateNotNullOrEmpty()]",
595595
"[SupportsWildcards()]",
596596
"[string[]]",
597-
"$${ParameterName:Path}$0"
597+
"$${3:ParameterName}$0"
598598
],
599599
"description": "Parameter declaration snippet for Path parameter that accepts wildcards. Add parameter-literalpath to handle paths with embedded wildcard chars."
600600
},
@@ -606,14 +606,14 @@
606606
"# enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any",
607607
"# characters as escape sequences.",
608608
"[Parameter(Mandatory=\\$true,",
609-
" Position=${Position:0},",
610-
" ParameterSetName=\"${ParameterSetName:LiteralPath}\",",
609+
" Position=${1:0},",
610+
" ParameterSetName=\"${2:LiteralPath}\",",
611611
" ValueFromPipelineByPropertyName=\\$true,",
612612
" HelpMessage=\"Literal path to one or more locations.\")]",
613613
"[Alias(\"PSPath\")]",
614614
"[ValidateNotNullOrEmpty()]",
615615
"[string[]]",
616-
"$${ParameterName:LiteralPath}$0"
616+
"$${2:LiteralPath}$0"
617617
],
618618
"description": "Parameter declaration snippet for a LiteralPath parameter"
619619
},
@@ -690,7 +690,7 @@
690690
"body": [
691691
"do {",
692692
"\t$0",
693-
"} until (${condition})"
693+
"} until (${1:condition})"
694694
],
695695
"description": "do-until loop snippet"
696696
},
@@ -699,14 +699,14 @@
699699
"body": [
700700
"do {",
701701
"\t$0",
702-
"} while (${condition})"
702+
"} while (${1:condition})"
703703
],
704704
"description": "do-while loop snippet"
705705
},
706706
"while": {
707707
"prefix": "while",
708708
"body": [
709-
"while (${condition}) {",
709+
"while (${1:condition}) {",
710710
"\t$0",
711711
"}"
712712
],
@@ -715,7 +715,7 @@
715715
"for": {
716716
"prefix": "for",
717717
"body": [
718-
"for ($${variable:i} = 0; $${variable:i} -lt $${array}.Count; $${variable:i}++) {",
718+
"for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {",
719719
"\t$0",
720720
"}"
721721
],
@@ -724,7 +724,7 @@
724724
"for-reversed": {
725725
"prefix": "forr",
726726
"body": [
727-
"for ($${variable:i} = $${array}.Count - 1; $${variable:i} -ge 0 ; $${variable:i}--) {",
727+
"for ($${1:i} = $${2:array}.Count - 1; $${1:i} -ge 0 ; $${1:i}--) {",
728728
"\t$0",
729729
"}"
730730
],
@@ -733,7 +733,7 @@
733733
"foreach": {
734734
"prefix": "foreach",
735735
"body": [
736-
"foreach ($${variable:item} in $${collection:collection}) {",
736+
"foreach ($${1:item} in $${2:collection}) {",
737737
"\t$0",
738738
"}"
739739
],
@@ -742,7 +742,7 @@
742742
"function": {
743743
"prefix": "function",
744744
"body": [
745-
"function ${FunctionName} (${OptionalParameters}) {",
745+
"function ${1:FunctionName} (${2:OptionalParameters}) {",
746746
"\t$0",
747747
"}"
748748
],
@@ -751,7 +751,7 @@
751751
"if": {
752752
"prefix": "if",
753753
"body": [
754-
"if (${condition}) {",
754+
"if (${1:condition}) {",
755755
"\t$0",
756756
"}"
757757
],
@@ -760,7 +760,7 @@
760760
"elseif": {
761761
"prefix": "elseif",
762762
"body": [
763-
"elseif (${condition}) {",
763+
"elseif (${1:condition}) {",
764764
"\t$0",
765765
"}"
766766
],
@@ -778,8 +778,8 @@
778778
"switch": {
779779
"prefix": "switch",
780780
"body": [
781-
"switch (${variable:\\$x}) {",
782-
"\t${condition} { $0 }",
781+
"switch (${1:\\$x}) {",
782+
"\t${2:condition} { $0 }",
783783
"\tDefault {}",
784784
"}"
785785
],

0 commit comments

Comments
 (0)