-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Summary of the new feature / enhancement
I occasionally write functions where I use a switch based on the bound parameters like this:
function Verb-Noun
{
Param
(
[Parameter()]
[string]
$Param1,
[Parameter()]
[string]
$Param2
)
switch ($PSBoundParameters.Keys)
{
Param1 {}
Param2 {}
}
}
To ensure I don't make typos I tend to copy+paste the parameters but tab completing them would be much more convenient.
But before I try to add this feature, I want to be sure it would actually get accepted. Do other people use this pattern? Is this a pattern we want to encourage? If not, how do other people check if various parameters have been specified?
Proposed technical implementation details (optional)
The identifier/string completion code would be updated to check if it's completing a switch case, and if so, if the switch is on a variable with a property called Keys.
If the variable is $PSBoundParameters it would look for the nearest param block and get results from there.
If the variable is anything else we could try to look for a hashtable definition to that variable and get results from that, but I don't know if it's worth adding this because I don't think this is a particularly common pattern.
Also we could do some type inference on the variable, and if it's an Enum get the completion values from there.