- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 45
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
PsfArgumentCompleter behaviour not consistant with original ArgumentCompleter #638
Comments
~Update i tried this,
And that appears to work. So PsfArgumentCompleter already does implement the $WordToComplete Filter mechanism and somehow doesn't like it if i bring my own. |
~Another Update Would it be possible to implement the $WordToComplete.trim("'") i showcased above? f.e. if it expanded some value, but i actually want a totally different value, so i can delete some chars and can tab again. |
Heya @azra1l , I could change the default behavior, yes. While I do have a "no breaking change" policy, as this only affects interactive execution in a non-intrusive way, I could add that to the next version. In the meantime, you can work around this by disabling the assist system. This won't work with the attribute, but by assigning the completer it will work. At that point you are however back to pretty much the old ways and loose most of the benefits PSF actually brings to the completion table. Wouldn't recommend it and instead stick to the PSF way (but I'm somewhat biased): Register-PSFTeppScriptblock -Name 'Test.PSFTepp' -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
"XYZ","123","ABC" | Where-Object { $_ -like "*$($WordToComplete.trim("'"))*" } | ForEach-Object { "'$($_)'" }
} -Mode Full
Register-PSFTeppArgumentCompleter -Command Get-Test -Parameter TestParam2 -Name 'Test.PSFTepp'
function Get-Test {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True, Position = 0)]
[ArgumentCompleter(
{
Param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters)
@("XYZ","123","ABC") | Where-Object { $_ -like "*$($WordToComplete.trim("'"))*" } | ForEach-Object { "'$($_)'" }
}
)]
[String] $TestParam1,
[Parameter(Mandatory = $True, Position = 1)]
[String] $TestParam2
)
} This will do the job, but ... yeah. not so great. Will add the update to the pile for the next release :)
There are some fun features in PowerShell TabCompletion in general and the PSFramework version in particular, so let's make this a bit awesomer: Register-PSFTeppScriptblock -Name 'Test.PSFTepp' -ScriptBlock {
@{ Text = 'ABC'; ListItemText = 'DEF'; ToolTip = 'Take some awesome letters!' }
@{ Text = '123'; ListItemText = '***'; ToolTip = 'Take some awesome numbers!' }
@{ Text = 'XYZ'; ListItemText = 'XYZ'; ToolTip = 'The ListItemText is kind of pointless, right?' }
}
function Get-Test {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True, Position = 0)]
[ArgumentCompleter(
{
Param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters)
@("XYZ","123","ABC") | Where-Object { $_ -like "*$($WordToComplete.trim("'"))*" } | ForEach-Object { "'$($_)'" }
}
)]
[String] $TestParam1,
[Parameter(Mandatory = $True, Position = 1)]
[PsfArgumentCompleter('Test.PSFTepp')]
[String] $TestParam2
)
} Now tab completion will work as before, but Get-Test -TestParam2 <CTRL+Space> |
Alright, added a separate issue to track this, so I've got a clean tracking item: |
Holy cow, that was quick. Yes, the tooltip stuff will definetly come in handy, Thanks for adding the feature request <3 |
I so far used the original ArgumentCompleter to manage my tab completion, and am aiming to replace those with PsfArgumentCompleter, to make things more readable and easier to manage.
Unfortunately, i am facing wierd behaviour and i am hoping to get some insight here, as the documentation doesn't really explain much. Especially the PsfArgumentCompleter Parameter is not documented at all, i just adopted what i found in some builtin psf functions, so there might be something wrong with that. But i get the same behaviour if i use the Register-PSFTeppArgumentCompleter command, which is documented and supposed to achieve the same result if i am not mistaken?
Anyways, I've sketched up this test example, which does reproduce the issue on my end with PSFramework versions 1.9.310 and 1.11.343.
First, register a psf tepp scriptblock
Second, make a script to compare it to an original ArgumentCompleter with identical setup.
For me,
TestParam1 expands like expected, in the order provided. If i tab through, i get
'XYZ'
,'123'
and'ABC'
. If i typeab
and hit tab, it will expand to'ABC'
.TestParam2 expands in alphabetic order, and it doesn't pick up typed values, unless i write * at the beginning. If i type
*ab
, it will expand to'ABC'
. Wierdly enough, not if i typeab*
, which would actually make more sense.My expectation here was, since the tepp scriptblock does support all the special variables from the original argumentcompleter, it would also behave the same given an identical scriptblock.
So my question here is, is this behaviour "working as intended?"
Or am i doing anything wrong?
The text was updated successfully, but these errors were encountered: