Skip to content

CompleteInput ignoring registered ArgumentCompleters when passed Script or AST #10567

Closed

Description

@M1kep

When [System.Management.Automation.CommandCompletion]::CompleteInput is provided a ScriptBlock or AST that has a definition of the command to be completed in it the ArgumentCompleters that are registered in the PowerShell instance are ignored.

This issue is mostly visible when an editor(Visual Studio Code) leverages the CompleteInput to provide Intellisense(As seen in PowerShell/vscode-powershell#2162 ).

@powershell/powershell I am currently working on a fix for this and will submit a PullRequest if deemed valid.

Steps to reproduce

$script = @'
function Test-Completion {
	param (
		[String]$TestVal
	)
}

[scriptblock]$completer = {
	param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
	@('Val1','Val2','Val3')
}

Register-ArgumentCompleter -CommandName Test-Completion -ParameterName TestVal -ScriptBlock $completer

Test-Completion -TestVal 
'@

$scriptBl = {
	function Test-Completion {
		param (
			[String]$TestVal
		)
	}

	[scriptblock]$completer = {
		param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)

		@('Val1', 'Val2', 'Val3')
	}

	Register-ArgumentCompleter -CommandName Test-Completion -ParameterName TestVal -ScriptBlock $completer
}

$pwsh = [PowerShell]::Create()
$pwsh.AddScript($scriptBl)
$pwsh.Invoke()


([System.Management.Automation.CommandCompletion]::CompleteInput($script, $script.Length, $null, $pwsh)).CompletionMatches

Expected behavior

CompletionText ListItemText ResultType ToolTip
-------------- ------------ ---------- -------
Val1           Val1               Text Val1
Val2           Val2               Text Val2
Val3           Val3               Text Val3

Actual behavior

List of files from my home directory

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.2
PSEdition                      Core
GitCommitId                    6.2.2
OS                             Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionResolution-FixedWG-Interactive-IntelliSense

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions