Powershell: Add parameter name and value completion for hashtables used for splatting

Created on 14 Sep 2018  路  5Comments  路  Source: PowerShell/PowerShell

When getting completion results while in a hashtable that is used for splatting, completion should treat keys as parameter names and values as arguments.

This would be easiest supported easiest when

  1. The HashtableAst is on the RHS of an AssignmentStatementAst
  2. A VariableExpressionAst is on the LHS
  3. The same variable is splatted in a CommandAst

Ideally completion features would be the same as when in the CommandAst, such as

  1. Keys are completed as parameter names
  2. Values would take ArgumentCompleter, ValidateSet, Enum typed parameters, etc into account
  3. Parameters already bound in the CommandAst would be excluded

/cc @TheIncorrigible1

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Discussion WG-Interactive-IntelliSense

Most helpful comment

@SeeminglyScience: Because it took me a while to figure out the intent myself, via the linked VSCode issue, let me try to clarify if my understanding of what you're asking for is correct:

Given a hashtable literal assigned to a variable ($splat) that is _later_ used for splatting (Get-ChildItem @splat), you want tab completion _inside the hashtable literal_ to complete the parameter names (and, if applicable, set-constrained arguments) of the cmdlet in whose context said splatting later happens.

Correct?

All 5 comments

@SeeminglyScience Not sure I understand. When splatting you just specify the variable name:

get-somthing @hashtableWithParameters

so there's nothing to complete. Could you please provide an example?

@BrucePay

Using this example

$splat = @{
    Pa
}

Get-ChildItem @splat

If tab was pressed with the cursor after Pa then Path would be a completion result.

@SeeminglyScience: Because it took me a while to figure out the intent myself, via the linked VSCode issue, let me try to clarify if my understanding of what you're asking for is correct:

Given a hashtable literal assigned to a variable ($splat) that is _later_ used for splatting (Get-ChildItem @splat), you want tab completion _inside the hashtable literal_ to complete the parameter names (and, if applicable, set-constrained arguments) of the cmdlet in whose context said splatting later happens.

Correct?

@mklement0 Exactly! Thanks for clarifying :)

This and a few other ideal features (like for Add-Type, Import-Module and Get-Command) would probably benefit from some kind of constant-folding analysis. Which starts to blur the lines on what PowerShell ought to be doing, because it's not really responsible for that kind of optimisation. But just thought I'd mention it, since I keep seeing similar scenarios for it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manofspirit picture manofspirit  路  3Comments

aragula12 picture aragula12  路  3Comments

ajensenwaud picture ajensenwaud  路  3Comments

concentrateddon picture concentrateddon  路  3Comments

JohnLBevan picture JohnLBevan  路  3Comments