Skip to content

Feature request: Convert PowerShell command invocation to Splatting #898

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
pcgeek86 opened this issue Jun 18, 2017 · 7 comments
Closed
Labels
Area-Code Formatting Issue-Enhancement A feature request (enhancement).

Comments

@pcgeek86
Copy link
Contributor

Back before VSCode PowerShell was emerging, I was often using the PowerShell ISE to author PowerShell code. While writing PowerShell code, I typically call a PowerShell command, and then convert that to a Splatting invocation, which took a bit of manual effort. The more parameters a command invocation has the more effort it takes to manually convert the command invocation to Splatting syntax. This manual effort gets boring over time, and reduces the amount of time that I can focus on business logic.

To speed up that manual process, I wrote a PowerShell module called SplatHelper. It offers two commands:

  • One that converts a command invocation to Splatting in ISE
  • One that's intended to work from the command line

vscode splatting

I'd like to be able to achieve the same goal using VSCode.

Cheers,
Trevor Sullivan
https://trevorsullivan.net

@pcgeek86 pcgeek86 added Area-Code Formatting Issue-Enhancement A feature request (enhancement). labels Jun 18, 2017
@SeeminglyScience
Copy link
Collaborator

SeeminglyScience commented Jun 18, 2017

You can do the same type of thing with editor commands and some of the EditorServices commands. For example this will splat whatever CommandAst is closest to your cursor.

Register-EditorCommand -Name ConvertToSplatting -DisplayName 'Splat closest command' -ScriptBlock {
    $ast = Find-Ast -AtCursor | Find-Ast -First -Ancestor { $_.GetType().Name -eq 'CommandAst' }
    $ast | Set-ScriptExtent -Text (ConvertTo-Splatting $ast.Extent.Text)
}

@kapilmb
Copy link

kapilmb commented Jun 18, 2017

I think this issue is identical to that of #517.

@pcgeek86
Copy link
Contributor Author

Thanks for pointing that out @kapilmb. Looks like SAPIEN implemented it into their editor based on my original release of SplatHelper. I'll close this one since the two issues are closely related.

image

@jkavanagh58
Copy link

I will work with it but the Register-EditorCommand does not seem to work for me.

@PowerSchill
Copy link
Contributor

@pcgeek86 I am going to see if I can add this to the PowerShellEditorServices code. Do you mind if I use your splatting module's code?

@pcgeek86
Copy link
Contributor Author

@PowerSchill Go or it :)

@it-praktyk
Copy link

It looks like Sapien implemented it in PowerShell Studio 2017: Service Release v5.4.141.

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

No branches or pull requests

6 participants