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
HashtableAst is on the RHS of an AssignmentStatementAstVariableExpressionAst is on the LHSCommandAstIdeally completion features would be the same as when in the CommandAst, such as
ArgumentCompleter, ValidateSet, Enum typed parameters, etc into accountCommandAst would be excluded/cc @TheIncorrigible1
> $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
@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.
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?