Skip to content

Allow CompleteInput to return results from ArgumentCompleter when AST or Script has matching function definition - #10574

Merged
Aditya Patwardhan (adityapatwardhan) merged 10 commits into
PowerShell:masterfrom
M1kep:include-custom-completers-with-ast
Dec 2, 2019
Merged

Aditya Patwardhan (adityapatwardhan) merged 10 commits into
PowerShell:masterfrom
M1kep:include-custom-completers-with-ast

Conversation

@M1kep

@M1kep Michael (M1kep) commented Sep 19, 2019 •

Copy link
Copy Markdown
Contributor

PR Summary

Fix #10567

This PR adds a check in NativeCommandArgumentCompletion to retrieve the commandName from the CommandAST if the commandName passed is null.

PR Context

When [System.Management.Automation.CommandCompletion]::CompleteInput is provided a ScriptBlock or AST that contains a definition of the function to be completed while there is a registered ArgumentCompleter for the function, the ArgumentCompleter is ignored.

This issue is visible when an editor leverages the CompleteInput to provide Intellisense(PowerShell/vscode-powershell#2162 ).

The impact to editors is that completion will be returned in such a way that better matches the terminal experience.

PR Checklist

@msftclas

Microsoft Contribution License Agreements (msftclas) commented Sep 19, 2019 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@M1kep

Michael (M1kep) commented Sep 19, 2019 •

Copy link
Copy Markdown
Contributor Author

I'm unsure what would cause the test to fail after simply changing a spacing issue.

Test prior to spacing issue: https://powershell.visualstudio.com/PowerShell/_build/results?buildId=32680

Test after spacing issue: https://powershell.visualstudio.com/PowerShell/_build/results?buildId=32688

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 19, 2019
@iSazonov Ilya (iSazonov) added this to the 7.0.0-preview.5 milestone Sep 19, 2019

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor comment.

@adityapatwardhan

Copy link
Copy Markdown
Member

TylerLeonhardt for impact on vscode-powershell

Dongbo Wang (@daxian-dbw) - please review this change.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right. After invoking, Test-Completion would already been defined, and it's not the scenario you are aiming at -- AST or Script has matching function definition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Oct 9, 2019
@adityapatwardhan

Copy link
Copy Markdown
Member

Dongbo Wang (@daxian-dbw) can you re-review?

Michael (M1kep) and others added 2 commits October 31, 2019 00:35

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming the comment is addressed.

…letionCompleters.cs

Co-Authored-By: Dongbo Wang <dongbow@microsoft.com>
@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit 570ba43 into PowerShell:master Dec 2, 2019
@adityapatwardhan

Copy link
Copy Markdown
Member

Michael (@M1kep) Thank you for your contribution!

@ghost

Copy link
Copy Markdown

🎉v7.1.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CompleteInput ignoring registered ArgumentCompleters when passed Script or AST

8 participants