-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Allow CompleteInput to return results from ArgumentCompleter when AST or Script has matching function definition #10574
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
Changes from all commits
7b5dffe
34fb67e
baae993
22f3e31
ae8439f
c93c879
daaca3e
1b98abf
ffebee6
10de9e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -687,6 +687,32 @@ Describe "TabCompletion" -Tags CI { | |
| $res.CompletionMatches[1].CompletionText | Should -BeExactly 'dog' | ||
| } | ||
|
|
||
| It "Tab completion for ArgumentCompleter when AST is passed to CompleteInput" { | ||
| $scriptBl = { | ||
| function Test-Completion { | ||
| param ( | ||
| [String]$TestVal | ||
| ) | ||
| } | ||
| [scriptblock]$completer = { | ||
| param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) | ||
|
|
||
| @('Val1', 'Val2') | ||
| } | ||
| Register-ArgumentCompleter -CommandName Test-Completion -ParameterName TestVal -ScriptBlock $completer | ||
| } | ||
| $pwsh = [PowerShell]::Create() | ||
| $pwsh.AddScript($scriptBl) | ||
| $pwsh.Invoke() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem right. After invoking,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding of this is as follows: The script block is executed to define the Test-Completion function and argument completer in the runspace.(As the runspace should provide the registered argument completers when in an editor). From there, we are using the $script variable for completion input(Similar to how VSCode utilizes CompleteInput) as the issue arises when the function is defined in the $script block being passed to CompleteInput |
||
|
|
||
| $completeInput_Input = $scriptBl.ToString() | ||
| $completeInput_Input += "`nTest-Completion -TestVal " | ||
| $res = [System.Management.Automation.CommandCompletion]::CompleteInput($completeInput_Input, $completeInput_Input.Length, $null, $pwsh) | ||
| $res.CompletionMatches | Should -HaveCount 2 | ||
| $res.CompletionMatches[0].CompletionText | Should -BeExactly 'Val1' | ||
| $res.CompletionMatches[1].CompletionText | Should -BeExactly 'Val2' | ||
| } | ||
|
|
||
| It "Tab completion for enum type parameter of a custom function" { | ||
| function baz ([consolecolor]$name, [ValidateSet('cat','dog')]$p){} | ||
| $inputStr = "baz -name " | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.