-
-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to Register-ArgumentCompleter for tab expansion #609
Conversation
} | ||
} | ||
@('git', 'tgit', 'gitk') | ForEach-Object { | ||
Register-ArgumentCompleter -CommandName $_ -Native -ScriptBlock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually work on Windows PowerShell? My experience with the built-in Register-ArgumentCompleter
in Windows PowerShell 5.1 is that it won't auto-complete native parameters that start with -
or --
. This would be a serious problem for Git.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, you're correct, it does not work. :( I'll post context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it sounds like we want to use Register-ArgumentCompleter
on PS 6+, and fall back on the previous behavior for PS 5.1?
I didn't realize the built-in Register-ArgumentCompleter on Windows PowerShell has a bug where it doesn't tab-complete arguments that begin with a hyphen. MicrosoftDocs/PowerShell-Docs#1979 So I guess this is only useful if you want posh-git to get the benefits of built-in Register-ArgumentCompleter on new-enough versions of Powershell and fallback to the old logic on e.g. Windows PowerShell. The benefits of built-in Register-ArgumentCompleter are that you can tab complete e.g. after the "b" in this example:
|
I've been looking at this. I think the following could work:
If you'd like to make this change, then I will accept and merge it. Also, in looking at the completer impl, I wasn't sure why we needed the padding/substring calls. If you don't have time for this, I can submit a PR to do the above but I'll make sure you get credit for this in the changelog. @dahlbyk I think it would be good to do one more beta drop with this change. |
Close in favor of #711 @cspotcode I'll make sure you get the credit for this in the changelog. Thanks for investigating this and doing the work!! |
I saw talk of switching to the more modern
Register-ArgumentCompleter
for tab completion. This is the most minimal implementation of such a switch. Completion logic is the same. We register ourselves as a-Native
completer forgit
,gitk
, andtgit
. When invoked, we convert the command AST into a string, trim it to match what the old completion logic is expecting, and pass it along.