Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions TabExpansionPlusPlus.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ function Get-CommandTreeCompletion
# if we find the element that matches $wordToComplete.
for ($i = 1; $i -lt $commandElements.Count; $i++)
{
if (!($commandElements[$i] -is [System.Management.Automation.Language.StringConstantExpressionAst]))
if (!($commandElements[$i] -is [System.Management.Automation.Language.StringConstantExpressionAst]) -and
!($commandElements[$i] -is [System.Management.Automation.Language.CommandParameterAst]))
{
# Ignore arguments that are expressions. In some rare cases this
# could cause strange completions because the context is incorrect, e.g.:
Expand All @@ -267,7 +268,7 @@ function Get-CommandTreeCompletion
continue
}

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

{
$CommandTree = $CommandTree |
Where-Object { $_.Command -like "$wordToComplete*" -or $_.CompletionGenerator -ne $null }
Expand All @@ -276,7 +277,7 @@ function Get-CommandTreeCompletion

foreach ($subCommand in $CommandTree)
{
if ($subCommand.Command -eq $commandElements[$i].Value)
if ($subCommand.Command -eq $commandElements[$i].Extent.Text)
{
if (!$subCommand.Argument)
{
Expand Down