|
25 | 25 | "prefix": "calculated-property",
|
26 | 26 | "description": "Typically used with Select-Object or Sort-Object. More: Get-Help about_Calculated_Properties",
|
27 | 27 | "body": [
|
28 |
| - "@{Name='${1:PropertyName}';Expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" |
| 28 | + "@{Name='${1:PropertyName}';Expression={${2:${TM_SELECTED_TEXT:<# Desired result. You can reference this object via \\$_ and \\$PSItem#>}}}}$0 #>" |
29 | 29 | ]
|
30 | 30 | },
|
31 | 31 | "Class": {
|
32 | 32 | "prefix": "class",
|
33 | 33 | "description": "A blueprint used to create instances of objects at run time. More: Get-Help about_Classes",
|
34 | 34 | "body": [
|
35 | 35 | "class ${1:ClassName} {",
|
36 |
| - "\t${0:${TM_SELECTED_TEXT:#Define the class. Try constructors, properties, or methods}}", |
| 36 | + "\t${0:${TM_SELECTED_TEXT:< #Define the class. Try constructors, properties, or methods #>}}", |
37 | 37 | "}"
|
38 | 38 | ]
|
39 | 39 | },
|
|
44 | 44 | ],
|
45 | 45 | "description": "Set default values and validate object logic at the moment of creating the instance of the class. Constructors have the same name as the class. Constructors might have arguments, to initialize the data members of the new object. More: Get-Help about_Classes",
|
46 | 46 | "body": [
|
47 |
| - "${1:ClassName}(${2:OptionalParameters}) {", |
48 |
| - "\t${0:${TM_SELECTED_TEXT:#Initialize the class. Use \\$this to reference the properties of the instance you are creating}}", |
| 47 | + "${1:ClassName}(${2:<#OptionalParameters#>}) {", |
| 48 | + "\t${0:${TM_SELECTED_TEXT:<# Initialize the class. Use \\$this to reference the properties of the instance you are creating #>}}", |
49 | 49 | "}"
|
50 | 50 | ]
|
51 | 51 | },
|
|
56 | 56 | "description": "A multi-line comment.",
|
57 | 57 | "body": [
|
58 | 58 | "$BLOCK_COMMENT_START",
|
59 |
| - " # ${{0:$TM_SELECTED_TEXT:Enter a comment or description}}", |
| 59 | + " # ${0:{$TM_SELECTED_TEXT:Enter a comment or description}}", |
60 | 60 | "$BLOCK_COMMENT_END"
|
61 | 61 | ]
|
62 | 62 | },
|
|
67 | 67 | "do {",
|
68 | 68 | "\t${0:$TM_SELECTED_TEXT}",
|
69 | 69 | "} until (",
|
70 |
| - "\t${1:#Condition that stops the loop if it returns true}", |
| 70 | + "\t${1:<# Condition that stops the loop if it returns true #>}", |
71 | 71 | ")"
|
72 | 72 | ]
|
73 | 73 | },
|
|
78 | 78 | "do {",
|
79 | 79 | "\t${0:$TM_SELECTED_TEXT}",
|
80 | 80 | "} while (",
|
81 |
| - "\t${1:#Condition that stops the loop if it returns false})", |
| 81 | + "\t${1:<# Condition that stops the loop if it returns false #>})", |
82 | 82 | ")"
|
83 | 83 | ]
|
84 | 84 | },
|
|
147 | 147 | "description": "else defines what is done when all if and elseif conditions are false. More: Get-Help about_If",
|
148 | 148 | "body": [
|
149 | 149 | "else {",
|
150 |
| - "\t${0:$TM_SELECTED_TEXT}", |
| 150 | + "\t${0:${TM_SELECTED_TEXT:<# Action when all if and elseif conditions are false #>}}", |
151 | 151 | "}"
|
152 | 152 | ]
|
153 | 153 | },
|
154 | 154 | "elseif": {
|
155 | 155 | "prefix": "elseif",
|
156 | 156 | "description": "elseif provides an alternative path when an if condition is false. More: Get-Help about_If",
|
157 | 157 | "body": [
|
158 |
| - "elseif (${1:condition}) {", |
159 |
| - "\t${0:$TM_SELECTED_TEXT}", |
| 158 | + "elseif (${1:<#condition#>}) {", |
| 159 | + "\t${0:${TM_SELECTED_TEXT:<# Action when this condition is true #>}}", |
160 | 160 | "}"
|
161 | 161 | ]
|
162 | 162 | },
|
163 | 163 | "Enum": {
|
164 | 164 | "prefix": "enum",
|
165 | 165 | "description": "An enumeration is a distinct type that consists of a set of named labels called the enumerator list. More: Get-Help about_Enum",
|
166 | 166 | "body": [
|
167 |
| - "enum ${1:EnumName} {", |
168 |
| - "\t${0:$TM_SELECTED_TEXT}", |
| 167 | + "enum ${1:<#EnumName#>} {", |
| 168 | + "\t${0:${TM_SELECTED_TEXT:<# Specify a list of distinct values #>}}", |
169 | 169 | "}"
|
170 | 170 | ]
|
171 | 171 | },
|
|
495 | 495 | },
|
496 | 496 | "for": {
|
497 | 497 | "prefix": "for",
|
498 |
| - "description": "for loop snippet", |
| 498 | + "description": "Creates a loop that runs commands in a command block while a specified condition evaluates to $true. A typical use of the For loop is to iterate an array of values and to operate on a subset of these values. More: Get-Help about_For", |
499 | 499 | "body": [
|
500 | 500 | "for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {",
|
501 |
| - "\t${0:$TM_SELECTED_TEXT}", |
| 501 | + "\t${0:${TM_SELECTED_TEXT:<# Action that will repeat until the condition is met #>}}", |
502 | 502 | "}"
|
503 | 503 | ]
|
504 | 504 | },
|
|
507 | 507 | "description": "reversed for loop snippet",
|
508 | 508 | "body": [
|
509 | 509 | "for ($${1:i} = $${2:array}.Count - 1; $${1:i} -ge 0 ; $${1:i}--) {",
|
510 |
| - "\t${0:$TM_SELECTED_TEXT}", |
| 510 | + "\t${0:${$TM_SELECTED_TEXT}}", |
511 | 511 | "}"
|
512 | 512 | ]
|
513 | 513 | },
|
514 | 514 | "foreach": {
|
515 | 515 | "prefix": "foreach",
|
516 |
| - "description": "foreach loop snippet", |
| 516 | + "description": "Iterate through a collection, assigning a variable to the current item on each loop rather than using the automatic variable $PSItem. More: Get-Help about_Foreach", |
517 | 517 | "body": [
|
518 |
| - "foreach ($${1:item} in $${2:collection}) {", |
519 |
| - "\t${0:$TM_SELECTED_TEXT}", |
| 518 | + "foreach ($${1:currentItemName} in $${2:collection}) {", |
| 519 | + "\t${0:${TM_SELECTED_TEXT:<# $${1} is the current item #>}}", |
| 520 | + "}" |
| 521 | + ] |
| 522 | + }, |
| 523 | + "foreach-item": { |
| 524 | + "prefix": "foreach-item", |
| 525 | + "description": "Quicker definition of foreach, just highlight the variable name of the collection you want to use and type 'item' then enter then tab. More: Get-Help about_Foreach", |
| 526 | + "body": [ |
| 527 | + "foreach (${1/(.*)/$1Item/} in ${1:${TM_SELECTED_TEXT:collection}}) {", |
| 528 | + "\t${0:${1/(.*)/$1Item/}}", |
520 | 529 | "}"
|
521 | 530 | ]
|
522 | 531 | },
|
|
525 | 534 | "description": "[PS 7+] Process multiple objects in parallel using runspaces. This has some limitations compared to a regular ForEach-Object. More: Get-Help ForEach-Object",
|
526 | 535 | "body": [
|
527 | 536 | "${1:\\$collection} | Foreach-Object -ThrottleLimit ${2:5} -Parallel {",
|
528 |
| - " ${0:${TM_SELECTED_TEXT:#Reference items via \\$PSItem and bring in outside variables with \\$USING:varname}}", |
| 537 | + " ${0:${TM_SELECTED_TEXT:#Action that will run in Parallel. Reference the current object via \\$PSItem and bring in outside variables with \\$USING:varname}}", |
529 | 538 | "}"
|
530 | 539 | ]
|
531 | 540 | },
|
|
592 | 601 | "}"
|
593 | 602 | ]
|
594 | 603 | },
|
595 |
| - "Function-Help": { |
596 |
| - "prefix": "help-function", |
597 |
| - "description": "Comment-based help for an advanced function snippet", |
598 |
| - "body": [ |
599 |
| - "<#", |
600 |
| - ".SYNOPSIS", |
601 |
| - "\t${1:A short one-line action-based description, e.g. 'Tests if a function is valid'}", |
602 |
| - ".DESCRIPTION", |
603 |
| - "\t${2:A longer description of the function, its purpose, common use cases, etc.}", |
604 |
| - ".NOTES", |
605 |
| - "\t${3:Information or caveats about the function e.g. 'This function is not supported in Linux'}", |
606 |
| - ".LINK", |
607 |
| - "\t${4:Specify a URI to a help page, this will show when Get-Help -Online is used.}", |
608 |
| - ".EXAMPLE", |
609 |
| - "\t${5:Test-MyTestFunction -Verbose}", |
610 |
| - "\t${6:Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines}", |
611 |
| - "#>" |
612 |
| - ] |
613 |
| - }, |
614 | 604 | "Function-Inline": {
|
615 | 605 | "prefix": "Function-Inline",
|
616 | 606 | "description": "Function definition snippet that does not contain a param block, but defines parameters inline. This syntax is commonly used in other languages",
|
|
621 | 611 | ]
|
622 | 612 | },
|
623 | 613 | "Hashtable": {
|
624 |
| - "prefix": [ |
625 |
| - "Hashtable", |
626 |
| - "@{" |
627 |
| - ], |
| 614 | + "prefix": "Hashtable", |
628 | 615 | "description": "A key/value store that are very effecient for finding and retrieving data. More: Get-Help about_Hash_Tables",
|
629 | 616 | "body": [
|
630 | 617 | "\\$${1:Var} = @{",
|
|
633 | 620 | ]
|
634 | 621 | },
|
635 | 622 | "Hidden Property": {
|
636 |
| - "prefix": "class-proph", |
| 623 | + "prefix": "class-proph-hidden", |
637 | 624 | "description": "Useful for creating properties and methods within a class that you do not necessarily want other users of the class to see, or readily be able to edit. More: about_Hidden",
|
638 | 625 | "body": [
|
639 | 626 | "hidden [${1:string}] $${0:PropertyName}"
|
|
662 | 649 | },
|
663 | 650 | "if": {
|
664 | 651 | "prefix": "if",
|
665 |
| - "description": "if statement snippet", |
| 652 | + "description": "Run code blocks if a specified conditional test evaluates to true. More: Get-Help about_If", |
666 | 653 | "body": [
|
667 | 654 | "if (${1:condition}) {",
|
668 |
| - "\t${0:$TM_SELECTED_TEXT}", |
| 655 | + "\t${0:${TM_SELECTED_TEXT:<# Action to perform if the condition is true #>}}", |
669 | 656 | "}"
|
670 | 657 | ]
|
671 | 658 | },
|
672 | 659 | "IfShouldProcess": {
|
673 | 660 | "prefix": "if-Should-Process",
|
674 |
| - "description": "Creates ShouldProcess block", |
| 661 | + "description": "Defines a condition that only executes if -WhatIf is not set, and returns a message otherwise. More: https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-shouldprocess", |
675 | 662 | "body": [
|
676 | 663 | "if (\\$PSCmdlet.ShouldProcess(\"${1:Target}\", \"${2:Operation}\")) {",
|
677 | 664 | "\t${0:$TM_SELECTED_TEXT}",
|
|
943 | 930 | },
|
944 | 931 | "Suppress PSScriptAnalyzer Rule": {
|
945 | 932 | "prefix": "suppress-message-rule",
|
946 |
| - "description": "Suppress a built-in PSScriptAnalyzer rule using the SuppressMessageAttribute", |
| 933 | + "description": "Suppress a PSScriptAnalyzer rule. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", |
947 | 934 | "body": [
|
948 |
| - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '')]" |
| 935 | + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", |
| 936 | + "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',<#CheckId#>\\$null,", |
| 937 | + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", |
| 938 | + ")]" |
949 | 939 | ]
|
950 | 940 | },
|
951 |
| - "Suppress PSScriptAnalyzer Rule in Scope": { |
952 |
| - "prefix": "suppress-message-rule-for-scope", |
953 |
| - "description": "Suppress a built-in PSScriptAnalyzer rule for functions or classes in a specific scope using the SuppressMessageAttribute", |
| 941 | + "Suppress PSScriptAnalyzer Rule in Function": { |
| 942 | + "prefix": "suppress-message-rule-function", |
| 943 | + "description": "Suppress a PSScriptAnalyzer rule for a function. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", |
954 | 944 | "body": [
|
955 |
| - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSProvideDefaultParameterValue}', '', Scope='Function', Target='${2:*}')]" |
| 945 | + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", |
| 946 | + "\t<#Category#>'${1:PSProvideDefaultParameterValue}', <#CheckId>\\$null, Scope='Function',", |
| 947 | + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", |
| 948 | + ")]" |
956 | 949 | ]
|
957 | 950 | },
|
958 | 951 | "Suppress PSScriptAnalyzer Rule on Parameter": {
|
959 |
| - "prefix": "suppress-message-rule-for-parameter", |
960 |
| - "description": "Suppress a built-in PSScriptAnalyzer rule on a parameter using the SuppressMessageAttribute", |
| 952 | + "prefix": "suppress-message-rule-parameter", |
| 953 | + "description": "Suppress a PSScriptAnalyzer rule on a parameter. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", |
961 | 954 | "body": [
|
962 |
| - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '${2:ParamName}')]" |
| 955 | + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',", |
| 956 | + "\t<#ParameterName#>'${0:${TM_SELECTED_TEXT:ParamName}}", |
| 957 | + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", |
| 958 | + ")]" |
| 959 | + ] |
| 960 | + }, |
| 961 | + "Suppress PSScriptAnalyzer Rule on a specific Scope": { |
| 962 | + "prefix": "suppress-message-rule-scope", |
| 963 | + "description": "Suppress a PSScriptAnaylzer rule based on a function/parameter/class/variable/object's name by setting the SuppressMessageAttribute's Target property to a regular expression or a glob pattern. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", |
| 964 | + "body": [ |
| 965 | + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", |
| 966 | + "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}', <#CheckId#>\\$null, Scope='Function',", |
| 967 | + "\tTarget='${1:${TM_SELECTED_TEXT:RegexOrGlobPatternToMatchName}}'", |
| 968 | + "\tJustification = '${0:Reason for suppressing}}'", |
| 969 | + ")]" |
963 | 970 | ]
|
964 | 971 | },
|
965 | 972 | "switch": {
|
966 | 973 | "prefix": "switch",
|
967 |
| - "description": "switch statement snippet", |
| 974 | + "description": "Equivalent to a series of if statements, but it is simpler. The switch statement lists each condition and an optional action. If a condition obtains, the action is performed. More: about_Switch", |
968 | 975 | "body": [
|
969 | 976 | "switch (${1:\\$x}) {",
|
970 | 977 | "\t${2:condition} { ${0:$TM_SELECTED_TEXT} }",
|
|
976 | 983 | "prefix": "ternary",
|
977 | 984 | "description": "[PS 7+] Simplified version of if-else popular in other languages that works in Powershell. More: about_If",
|
978 | 985 | "body": [
|
979 |
| - "(${TM_SELECTED_TEXT:${1:condition}}) ? $(${2:actionIfTrue}) : $(${3:actionIfFalse})", |
980 |
| - "$0" |
| 986 | + "(${1:${TM_SELECTED_TEXT:condition}}) ? $(${2:<#Action if True#>}) : $(${0:<#Action If False#>})" |
981 | 987 | ]
|
982 | 988 | },
|
983 | 989 | "try-catch": {
|
|
988 | 994 | "\t${0:$TM_SELECTED_TEXT}",
|
989 | 995 | "}",
|
990 | 996 | "catch {",
|
991 |
| - "\t{1:Do this if a terminating exception happens}", |
| 997 | + "\t{1:<#Do this if a terminating exception happens#>}", |
992 | 998 | "}"
|
993 | 999 | ]
|
994 | 1000 | },
|
|
1000 | 1006 | "\t${0:$TM_SELECTED_TEXT}",
|
1001 | 1007 | "}",
|
1002 | 1008 | "catch {",
|
1003 |
| - "\t{1:Do this if a terminating exception happens}", |
| 1009 | + "\t${1:<#Do this if a terminating exception happens#>}", |
1004 | 1010 | "}",
|
1005 | 1011 | "finally {",
|
1006 |
| - "\t{2:Do this after the try block regardless of whether an exception occurred or not}", |
| 1012 | + "\t${2:<#Do this after the try block regardless of whether an exception occurred or not#>}", |
1007 | 1013 | "}"
|
1008 | 1014 | ]
|
1009 | 1015 | },
|
|
1015 | 1021 | "\t${0:$TM_SELECTED_TEXT}",
|
1016 | 1022 | "}",
|
1017 | 1023 | "finally {",
|
1018 |
| - "\t{2:Do this after the try block regardless of whether an exception occurred or not}", |
| 1024 | + "\t${2:<#Do this after the try block regardless of whether an exception occurred or not#>}", |
1019 | 1025 | "}"
|
1020 | 1026 | ]
|
1021 | 1027 | },
|
|
0 commit comments