Fixed issue with native command trees for parameters starting with '-'#79
Fixed issue with native command trees for parameters starting with '-'#79razaraz wants to merge 1 commit intolzybkr:masterfrom
Conversation
When powershell parses a native command Ast, it adds any parameters that start with a '-' as CommandParameterAst rather than StringConstantExpressionAst.
| } | ||
|
|
||
| if ($commandElements[$i].Value -eq $wordToComplete) | ||
| if ($commandElements[$i].Extent.Text -eq $wordToComplete) |
There was a problem hiding this comment.
Sorry for the long delayed review.
Using the extent text is sometimes wrong, e.g. sometimes an argument uses quotes, sometimes it doesn't. Either way, the value is the same, but Extent.Text will include the quotes if they were specified.
Similarly (but definitely a corner case) a parameter can use different characters for -, e.g. em-dash or en-dash. Extent.Text will include whatever dash character appeared in the script/command line, and it is unlikely the argument completer handles alternative dashes. This is a corner case for native commands because few will recognize alternative dashes, but I expect more to do that over time.
There was a problem hiding this comment.
I see. I was trying to avoid adding if statements for arguments parsed as StringConstantExpression, and CommandParameter. Extent.Text seemed to work for both cases. I'm not familiar with alternative dashes, are those different Unicode characters that can be used for dashes?
In any case, would adding separate if statements for StringConstantExpression, and CommandParameter, or even a switch statement to include the if above work? I don't even remember my exact usage scenario, or how I originally debugged it. It would probably take me a bit to make the edits, sorry :/
When powershell parses a native command Ast, it adds any parameters
that start with a '-' as CommandParameterAst rather than
StringConstantExpressionAst.