Skip to content

Commit 86de851

Browse files
travisclagroneTylerLeonhardt
authored andcommitted
Edit snippets to support $TM_SELECTED_TEXT (#1945)
Edit all-and-only applicable snippets to support $TM_SELECTED_TEXT, where "applicable" is approximated by whether a snippet contains a user-specified PowerShell expression, block, or body. Do not add, remove, or otherwise change any placeholder number or name in order to preserve backwards-compatibility. Edit the following snippets (listed by name, not prefix): - Class - Constructor - Method - Enum - Cmdlet - Function-Advanced - DSC Resource Provider (class-based) - DSC Resource Provider (function-based) - comment block - do-until - do-while - while - for - for-reversed - foreach - function - Function-Inline - if - elseif - else - switch - try-catch - try-catch-finally - try-finally - Workflow - Workflow ForEachParallel - Workflow InlineScript - Workflow Parallel - Workflow Sequence - Region Block - IfShouldProcess - CalculatedProperty - PesterDescribeContextIt - PesterDescribeBlock - PesterContextIt - PesterContext - PesterIt
1 parent 5c756e4 commit 86de851

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

snippets/PowerShell.json

+41-35
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@
466466
"prefix": "class",
467467
"body": [
468468
"class ${1:ClassName} {",
469-
"\t$0",
469+
"\t${0:$TM_SELECTED_TEXT}",
470470
"}"
471471
],
472472
"description": "Class definition snippet"
@@ -475,7 +475,7 @@
475475
"prefix": "ctor",
476476
"body": [
477477
"${1:ClassName}(${2:OptionalParameters}) {",
478-
"\t$0",
478+
"\t${0:$TM_SELECTED_TEXT}",
479479
"}"
480480
],
481481
"description": "Class constructor definition snippet"
@@ -498,7 +498,7 @@
498498
"prefix": "method",
499499
"body": [
500500
"[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {",
501-
"\t$0",
501+
"\t${0:$TM_SELECTED_TEXT}",
502502
"}"
503503
],
504504
"description": "Class method definition snippet"
@@ -507,7 +507,7 @@
507507
"prefix": "enum",
508508
"body": [
509509
"enum ${1:EnumName} {",
510-
"\t$0",
510+
"\t${0:$TM_SELECTED_TEXT}",
511511
"}"
512512
],
513513
"description": "Enum definition snippet"
@@ -522,12 +522,15 @@
522522
"\t)",
523523
"\t",
524524
"\tbegin {",
525+
"\t\t",
525526
"\t}",
526527
"\t",
527528
"\tprocess {",
529+
"\t\t$TM_SELECTED_TEXT",
528530
"\t}",
529531
"\t",
530532
"\tend {",
533+
"\t\t",
531534
"\t}",
532535
"}"
533536
],
@@ -543,12 +546,15 @@
543546
"\t)",
544547
"\t",
545548
"\tbegin {",
549+
"\t\t",
546550
"\t}",
547551
"\t",
548552
"\tprocess {",
553+
"\t\t$TM_SELECTED_TEXT",
549554
"\t}",
550555
"\t",
551556
"\tend {",
557+
"\t\t",
552558
"\t}",
553559
"}"
554560
],
@@ -658,7 +664,7 @@
658664
"\t",
659665
"\t# Gets the resource's current state.",
660666
"\t[${ResourceName:NameOfResource}] Get() {",
661-
"\t\t$0",
667+
"\t\t${0:$TM_SELECTED_TEXT}",
662668
"\t\treturn \\$this",
663669
"\t}",
664670
"\t",
@@ -682,7 +688,7 @@
682688
"\tparam (",
683689
"\t)",
684690
"\t",
685-
"\t$0",
691+
"\t${0:$TM_SELECTED_TEXT}",
686692
"}",
687693
"function Set-TargetResource {",
688694
"\tparam (",
@@ -701,7 +707,7 @@
701707
"prefix": "comment",
702708
"body": [
703709
"<#",
704-
" # $0",
710+
" # ${0:$TM_SELECTED_TEXT}",
705711
" #>"
706712
],
707713
"description": "Comment block snippet"
@@ -710,7 +716,7 @@
710716
"prefix": "do-until",
711717
"body": [
712718
"do {",
713-
"\t$0",
719+
"\t${0:$TM_SELECTED_TEXT}",
714720
"} until (${1:condition})"
715721
],
716722
"description": "do-until loop snippet"
@@ -719,7 +725,7 @@
719725
"prefix": "do-while",
720726
"body": [
721727
"do {",
722-
"\t$0",
728+
"\t${0:$TM_SELECTED_TEXT}",
723729
"} while (${1:condition})"
724730
],
725731
"description": "do-while loop snippet"
@@ -728,7 +734,7 @@
728734
"prefix": "while",
729735
"body": [
730736
"while (${1:condition}) {",
731-
"\t$0",
737+
"\t${0:$TM_SELECTED_TEXT}",
732738
"}"
733739
],
734740
"description": "while loop snippet"
@@ -737,7 +743,7 @@
737743
"prefix": "for",
738744
"body": [
739745
"for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {",
740-
"\t$0",
746+
"\t${0:$TM_SELECTED_TEXT}",
741747
"}"
742748
],
743749
"description": "for loop snippet"
@@ -746,7 +752,7 @@
746752
"prefix": "forr",
747753
"body": [
748754
"for ($${1:i} = $${2:array}.Count - 1; $${1:i} -ge 0 ; $${1:i}--) {",
749-
"\t$0",
755+
"\t${0:$TM_SELECTED_TEXT}",
750756
"}"
751757
],
752758
"description": "reversed for loop snippet"
@@ -755,7 +761,7 @@
755761
"prefix": "foreach",
756762
"body": [
757763
"foreach ($${1:item} in $${2:collection}) {",
758-
"\t$0",
764+
"\t${0:$TM_SELECTED_TEXT}",
759765
"}"
760766
],
761767
"description": "foreach loop snippet"
@@ -767,7 +773,7 @@
767773
"\tparam (",
768774
"\t\t${2:OptionalParameters}",
769775
"\t)",
770-
"\t$0",
776+
"\t${0:$TM_SELECTED_TEXT}",
771777
"}"
772778
],
773779
"description": "Function definition snippet that contains a param block"
@@ -776,7 +782,7 @@
776782
"prefix": "Function-Inline",
777783
"body": [
778784
"function ${1:FunctionName} (${2:OptionalParameters}) {",
779-
"\t$0",
785+
"\t${0:$TM_SELECTED_TEXT}",
780786
"}"
781787
],
782788
"description": "Function definition snippet that does not contain a param block, but defines parameters inline. This syntax is commonly used in other languages"
@@ -785,7 +791,7 @@
785791
"prefix": "if",
786792
"body": [
787793
"if (${1:condition}) {",
788-
"\t$0",
794+
"\t${0:$TM_SELECTED_TEXT}",
789795
"}"
790796
],
791797
"description": "if statement snippet"
@@ -794,7 +800,7 @@
794800
"prefix": "elseif",
795801
"body": [
796802
"elseif (${1:condition}) {",
797-
"\t$0",
803+
"\t${0:$TM_SELECTED_TEXT}",
798804
"}"
799805
],
800806
"description": "elseif statement snippet"
@@ -803,7 +809,7 @@
803809
"prefix": "else",
804810
"body": [
805811
"else {",
806-
"\t$0",
812+
"\t${0:$TM_SELECTED_TEXT}",
807813
"}"
808814
],
809815
"description": "else statement snippet"
@@ -812,7 +818,7 @@
812818
"prefix": "switch",
813819
"body": [
814820
"switch (${1:\\$x}) {",
815-
"\t${2:condition} { $0 }",
821+
"\t${2:condition} { ${0:$TM_SELECTED_TEXT} }",
816822
"\tDefault {}",
817823
"}"
818824
],
@@ -822,7 +828,7 @@
822828
"prefix": "try",
823829
"body": [
824830
"try {",
825-
"\t$0",
831+
"\t${0:$TM_SELECTED_TEXT}",
826832
"}",
827833
"catch {",
828834
"\t",
@@ -834,7 +840,7 @@
834840
"prefix": "trycf",
835841
"body": [
836842
"try {",
837-
"\t$0",
843+
"\t${0:$TM_SELECTED_TEXT}",
838844
"}",
839845
"catch {",
840846
"\t",
@@ -849,7 +855,7 @@
849855
"prefix": "tryf",
850856
"body": [
851857
"try {",
852-
"\t$0",
858+
"\t${0:$TM_SELECTED_TEXT}",
853859
"}",
854860
"finally {",
855861
"\t",
@@ -864,7 +870,7 @@
864870
"\tparam (",
865871
"\t)",
866872
"",
867-
"\t$0",
873+
"\t${0:$TM_SELECTED_TEXT}",
868874
"}"
869875
],
870876
"description": "workflow snippet"
@@ -873,7 +879,7 @@
873879
"prefix": "workflow foreach-parallel",
874880
"body": [
875881
"foreach -parallel ($${variable:item} in $${collection:collection}) {",
876-
"\t$0",
882+
"\t${0:$TM_SELECTED_TEXT}",
877883
"}"
878884
],
879885
"description": "foreach-parallel snippet (for use inside a workflow)"
@@ -882,7 +888,7 @@
882888
"prefix": "workflow inlinescript",
883889
"body": [
884890
"inlineScript {",
885-
"\t$0",
891+
"\t${0:$TM_SELECTED_TEXT}",
886892
"}"
887893
],
888894
"description": "inlinescript snippet (for use inside a workflow)"
@@ -891,7 +897,7 @@
891897
"prefix": "workflow parallel",
892898
"body": [
893899
"parallel {",
894-
"\t$0",
900+
"\t${0:$TM_SELECTED_TEXT}",
895901
"}"
896902
],
897903
"description": "parallel snippet (for use inside a workflow)"
@@ -900,7 +906,7 @@
900906
"prefix": "workflow sequence",
901907
"body": [
902908
"sequence {",
903-
"\t$0",
909+
"\t${0:$TM_SELECTED_TEXT}",
904910
"}"
905911
],
906912
"description": "sequence snippet (for use inside a workflow)"
@@ -948,7 +954,7 @@
948954
"prefix": "#region",
949955
"body": [
950956
"#region ${1}",
951-
"$0",
957+
"${0:$TM_SELECTED_TEXT}",
952958
"#endregion"
953959
],
954960
"description": "Region Block for organizing and folding of your code"
@@ -957,15 +963,15 @@
957963
"prefix": "IfShouldProcess",
958964
"body": [
959965
"if (\\$PSCmdlet.ShouldProcess(\"${1:Target}\", \"${2:Operation}\")) {",
960-
"\t$0",
966+
"\t${0:$TM_SELECTED_TEXT}",
961967
"}"
962968
],
963969
"description": "Creates ShouldProcess block"
964970
},
965971
"CalculatedProperty": {
966972
"prefix": "Calculated-Property",
967973
"body": [
968-
"@{name='${1:PropertyName}';expression={${2:\\$_.PropertyValue}}}$0"
974+
"@{name='${1:PropertyName}';expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0"
969975
],
970976
"description": "Creates a Calculated Property typically used with Select-Object."
971977
},
@@ -975,7 +981,7 @@
975981
"Describe \"${1:DescribeName}\" {",
976982
"\tContext \"${2:ContextName}\" {",
977983
"\t\tIt \"${3:ItName}\" {",
978-
"\t\t\t${4:Assertion}",
984+
"\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}",
979985
"\t\t}$0",
980986
"\t}",
981987
"}"
@@ -986,7 +992,7 @@
986992
"prefix": "Describe-Pester",
987993
"body": [
988994
"Describe \"${1:DescribeName}\" {",
989-
"\t$0",
995+
"\t${0:TM_SELECTED_TEXT}",
990996
"}"
991997
],
992998
"description": "Pester Describe block"
@@ -996,7 +1002,7 @@
9961002
"body": [
9971003
"Context \"${1:ContextName}\" {",
9981004
"\tIt \"${2:ItName}\" {",
999-
"\t\t${3:Assertion}",
1005+
"\t\t${3:${TM_SELECTED_TEXT:Assertion}}",
10001006
"\t}$0",
10011007
"}"
10021008
],
@@ -1006,7 +1012,7 @@
10061012
"prefix": "Context-Pester",
10071013
"body": [
10081014
"Context \"${1:ContextName}\" {",
1009-
"\t$0",
1015+
"\t${0:$TM_SELECTED_TEXT}",
10101016
"}"
10111017
],
10121018
"description": "Pester - Context block"
@@ -1015,7 +1021,7 @@
10151021
"prefix": "It-Pester",
10161022
"body": [
10171023
"It \"${1:ItName}\" {",
1018-
"\t${2:Assertion}",
1024+
"\t${2:${TM_SELECTED_TEXT:Assertion}}",
10191025
"}$0"
10201026
],
10211027
"description": "Pester - It block"

0 commit comments

Comments
 (0)