Vscode-powershell: Feature request: Convert PowerShell command invocation to Splatting

Created on 18 Jun 2017  路  7Comments  路  Source: PowerShell/vscode-powershell

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

Area-Code Formatting Issue-Enhancement

Most helpful comment

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)
}

All 7 comments

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)
}

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

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

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

@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?

@PowerSchill Go or it :)

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

Was this page helpful?
0 / 5 - 0 ratings