Skip to content

Fixed issue with native command trees for parameters starting with '-'#79

Open
razaraz wants to merge 1 commit intolzybkr:masterfrom
razaraz:NativeDashParams
Open

Fixed issue with native command trees for parameters starting with '-'#79
razaraz wants to merge 1 commit intolzybkr:masterfrom
razaraz:NativeDashParams

Conversation

@razaraz
Copy link
Copy Markdown

@razaraz razaraz commented Sep 9, 2016

When powershell parses a native command Ast, it adds any parameters
that start with a '-' as CommandParameterAst rather than
StringConstantExpressionAst.

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)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants