Skip to content

Add param block snippet #2080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TylerLeonhardt opened this issue Jul 11, 2019 · 12 comments
Closed

Add param block snippet #2080

TylerLeonhardt opened this issue Jul 11, 2019 · 12 comments
Labels
Area-Snippets Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.

Comments

@TylerLeonhardt
Copy link
Member

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.

@TylerLeonhardt TylerLeonhardt added Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs. Area-Snippets labels Jul 11, 2019
@vexx32
Copy link

vexx32 commented Jul 11, 2019

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.

@rkeithhill
Copy link
Contributor

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

@vexx32
Copy link

vexx32 commented Jul 11, 2019

Hm, that's a very good point! Yeah definitely err on the side of productivity.

@rkeithhill
Copy link
Contributor

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.

@AspenForester
Copy link
Contributor

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?

@AspenForester
Copy link
Contributor

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."
    }

@TylerLeonhardt
Copy link
Member Author

I’d approve that PR 😄

@AspenForester
Copy link
Contributor

Well, let's see how I did...

@malcolmardalon
Copy link

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)

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jul 23, 2020
@AspenForester
Copy link
Contributor

@malcolmardalon are you referring to snippets in general or this specific snippet?

@TylerLeonhardt TylerLeonhardt removed the Needs: Maintainer Attention Maintainer attention needed! label Jul 24, 2020
@TylerLeonhardt
Copy link
Member Author

This snippet exists now, so I'll close this. However, feel free to continue the discussion.

@rjmholt
Copy link
Contributor

rjmholt commented Jul 24, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Snippets Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.
Projects
None yet
Development

No branches or pull requests

7 participants