Give more completion context info to argument completers
See original GitHub issueSummary of the new feature/enhancement
Argument completers get the following parameters: $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
This is great but I would like to also get: $cursorPosition, ref $replacementLength, ref $replacementIndex
This will enable completion for substrings, like the string you provide to the Filter parameter for Get-CimInstance.
Example: Get-CimInstance Win32_Process -Filter "Name = 'pwsh.exe'"
If my cursor is in the “Name” area my argument completer would show Win32_Process properties and if my cursor is in the “=” area it would show operators.
If you want to do this today you either have to assume the cursor is always at the end of the line or just show all possible options with no regard for the cursor position.
Proposed technical implementation details (optional)
Add the cursorPosition parameter to the list of parameters given to argument completers and if passing objects by reference is possible do that for replacementLength and replacementIndex.
If it’s not possible to set the replacement length/index from the argument completer then argument completers will just have to keep that in mind and use the whole string as a completion result.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:18 (5 by maintainers)
With the way that the scriptblock is called (
ScriptBlock.Invoke
),CmdletBinding
is ignored. Shouldn’t be an issue.I think we would need to add a new interface
IArgumentCompeleter2
with the required methods.The engine would first check for the new interface and fall back to the old.