Skip to content

Conversation

@M1kep
Copy link
Contributor

@M1kep M1kep commented Sep 19, 2019

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
Copy link

msftclas commented Sep 19, 2019

CLA assistant check
All CLA requirements met.

@M1kep
Copy link
Contributor Author

M1kep commented Sep 19, 2019

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 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 iSazonov added this to the 7.0.0-preview.5 milestone Sep 19, 2019
Copy link
Collaborator

@iSazonov iSazonov left a comment

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
Member

@TylerLeonhardt for impact on vscode-powershell

@daxian-dbw - please review this change.

}
$pwsh = [PowerShell]::Create()
$pwsh.AddScript($scriptBl)
$pwsh.Invoke()
Copy link
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
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
@M1kep M1kep requested a review from TylerLeonhardt October 9, 2019 22:08
@M1kep M1kep requested a review from daxian-dbw October 18, 2019 23:06
@adityapatwardhan
Copy link
Member

@daxian-dbw can you re-review?

M1kep and others added 2 commits October 31, 2019 00:35
Copy link
Member

@daxian-dbw daxian-dbw left a comment

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 adityapatwardhan merged commit 570ba43 into PowerShell:master Dec 2, 2019
@adityapatwardhan
Copy link
Member

@M1kep Thank you for your contribution!

@ghost
Copy link

ghost commented Mar 26, 2020

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

Handy links:

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