You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I set a breakpoint inside the scriptblock, I find that $commandName is of type String, and $wordToComplete is of type CommandAst. The $commandName variable holds the last 'partial word' on the command line, the word to complete.
This matches with what I found after digging in the code, at this line, the exact same pattern is used: CompletionCompleter.cs:1307
It seems to me the parameters in the example scriptblock should be named: $wordToComplete, $commandAst, $cursorPosition
The example does work, because $commandAst.ToString() returns the full command line up to that point (eg. "dotnet --h"), and dotnet uses the --position x information to filter out where to start completing.
I realized later that there is more. The description for the -ScriptBlock parameter combined with the -Native parameter needs to be corrected too.
Current text:
$commandName (Position 0) - This parameter is set to the name of the command for which the script block is providing tab completion.
$wordToComplete (Position 1) - This parameter is set to value the user has provided before they pressed Tab. Your script block should use this value to determine tab completion values.
$cursorPosition (Position 2) - This parameter is set to the position of the cursor when the user pressed Tab.
Suggested improved version, adapted from the parameter description for non-Native:
$wordToComplete (Position 0) - This parameter is set to value the user has provided before they pressed Tab. Your script block should use this value to determine tab completion values.
$commandAst (Position 1) - This parameter is set to the Abstract Syntax Tree (AST) for the current input line. For more information, see Ast Class.
$cursorPosition (Position 2) - This parameter is set to the position of the cursor when the user pressed Tab.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: 0050f0cf-2744-391c-5b15-b4eeb51f8675
Version Independent ID: 3d52e60a-f772-66e7-adf6-9ad79acdae0f
The text was updated successfully, but these errors were encountered:
Jawz84
changed the title
Example for -Native has wrong parameter names
Example for Register-ArgumentCompleter -Native has wrong parameter names
Feb 3, 2020
The naming of the scriptblock parameters in the example for the native argument completer are misleading/incorrect. This is the example:
When I set a breakpoint inside the scriptblock, I find that
$commandName
is of type String, and$wordToComplete
is of type CommandAst. The$commandName
variable holds the last 'partial word' on the command line, the word to complete.This matches with what I found after digging in the code, at this line, the exact same pattern is used: CompletionCompleter.cs:1307
It seems to me the parameters in the example scriptblock should be named:
$wordToComplete, $commandAst, $cursorPosition
The example does work, because $commandAst.ToString() returns the full command line up to that point (eg. "dotnet --h"), and dotnet uses the
--position x
information to filter out where to start completing.Proposed improved example:
Edit:
I realized later that there is more. The description for the -ScriptBlock parameter combined with the
-Native
parameter needs to be corrected too.Current text:
Suggested improved version, adapted from the parameter description for non
-Native
:Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: