Summary of the new feature
On my stream with Scott Hanselman, he wasn't sure on how to write a param block because we have snippets for individual parameters, not param blocks.
I'd be nice to have a snippet of a param block, with a parameter inside.
Proposed technical implementation details (optional)
Take the current parameter snippet, and wrap it in a param block and call it the param-block snippet.
Should probably have something like this...
[CmdletBinding(DefaultParameterSetName = 'Default', SupportsShouldProcess = $false)]
param(
[Parameter(
Position = 0,
Mandatory = $false,
ValueFromPipeline = $false,
ValueFromPipelineByPropertyName = $false,
ParameterSetName = 'Default'
)]
[object]
$Parameter
)
Maybe with some inline comments that properties not needed / set to $false can be omitted if not used.
I think there's a difference between a "teaching" style snippet and a "productivity" snippet. The above, as a productivity snippet, wouldn't work for me because I'd end up deleting more stuff than I would have typed in the first place. For me, this would be a productivity snippet:
[CmdletBinding()]
param(
[Parameter()]
[${1:type-name}]
$${2:parameter-name}
)
$0
Hm, that's a very good point! Yeah definitely err on the side of productivity.
FWIW I do think there is value in having "teaching" style snippets. They just need to be easily distinguished somehow between normal productivity snippets. That's why we have snippets that are prefixed with Example- and Parameter-* but I'm not sure that's really the best approach.
It might be nice to give the user the CHOICE of a comma, or maybe we should just leave the cursor at the right end of the variable name?
Something like this: Note where the $0 moved to.
"Parameter_Block" : {
"prefix": "param-block",
"body": ["[CmdletBinding()]",
"param (",
" [parameter()]",
" [${1:TypeName}]",
" $${2:ParameterName}$0",
")"],
"description": "A Parameter block to get you started."
}
I鈥檇 approve that PR 馃槃
Well, let's see how I did...
Hi team, might I suggest, that by presenting me with potential options of what I can populate, I can learn how to use the snippet and what it represents. Otherwise I get confused as to why i can't tab/shift tab between the fillable parts? Would certainly like a url to a man page to "teach the snippet" in the description somewhere. I just ended up deleting and typing more than I would have typed if I memorized the param block? On the other hand, we don't create param blocks often. Still I would really love a fillable snippet (great for teaching new comers to Powershell)
@malcolmardalon are you referring to snippets in general or this specific snippet?
This snippet exists now, so I'll close this. However, feel free to continue the discussion.
Hi team, might I suggest, that by presenting me with potential options of what I can populate, I can learn how to use the snippet and what it represents. Otherwise I get confused as to why i can't tab/shift tab between the fillable parts? Would certainly like a url to a man page to "teach the snippet" in the description somewhere. I just ended up deleting and typing more than I would have typed if I memorized the param block?
I'm not sure how much of this the PowerShell extension is responsible for, vs VSCode itself, but if we can work out which is which we can see what can be done where
Most helpful comment
I think there's a difference between a "teaching" style snippet and a "productivity" snippet. The above, as a productivity snippet, wouldn't work for me because I'd end up deleting more stuff than I would have typed in the first place. For me, this would be a productivity snippet: