Skip to content

Fix tab completion for parameters so that it shows common parameters as available #10850

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

Merged
merged 5 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ internal MergedCompiledCommandParameter GetMatchingParameter(
}
}

if (filteredParameters.Count == 1)
if (tryExactMatching && filteredParameters.Count == 1)
{
matchingParameters = filteredParameters;
}
Expand Down
16 changes: 15 additions & 1 deletion test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,20 @@ dir -Recurse `
$res.CompletionMatches | Should -HaveCount 33
$res.CompletionMatches[0].CompletionText | Should -BeExactly "Commands"
}

It "Test completion with common parameters" {
$inputStr = 'invoke-webrequest -out'
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
$res.CompletionMatches | Should -HaveCount 3
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-OutBuffer,-OutFile,-OutVariable"
}

It "Test completion with exact match" {
$inputStr = 'get-content -wa'
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
$res.CompletionMatches | Should -HaveCount 4
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-wa,-Wait,-WarningAction,-WarningVariable"
}
}

Context "Module completion for 'using module'" {
Expand Down Expand Up @@ -1322,7 +1336,7 @@ Describe "WSMan Config Provider tab complete tests" -Tags Feature,RequireAdminOn
}

It "Tab completion gets dynamic parameters for '<path>' using '<parameter>'" -TestCases @(
@{path = ""; parameter = "-co"; expected = "ConnectionURI"},
@{path = ""; parameter = "-conn"; expected = "ConnectionURI"},
@{path = ""; parameter = "-op"; expected = "OptionSet"},
@{path = ""; parameter = "-au"; expected = "Authentication"},
@{path = ""; parameter = "-ce"; expected = "CertificateThumbprint"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
# Licensed under the MIT License.
Describe "Get-Member" -Tags "CI" {
It "Should be able to be called on string objects, ints, arrays, etc" {
$a = 1 #test numbers
$b = 1.3
$c = $false #test bools
$d = @(1,3) # test arrays
$e = "anoeduntodeu" #test strings
$f = 'asntoheusth' #test strings
$a = 1 #test numbers
$b = 1.3
$c = $false #test bools
$d = @(1, 3) # test arrays
$e = "anoeduntodeu" #test strings
$f = 'asntoheusth' #test strings

Get-Member -InputObject $a | Should -Not -BeNullOrEmpty
Get-Member -InputObject $b | Should -Not -BeNullOrEmpty
Get-Member -InputObject $c | Should -Not -BeNullOrEmpty
Get-Member -InputObject $d | Should -Not -BeNullOrEmpty
Get-Member -InputObject $e | Should -Not -BeNullOrEmpty
Get-Member -InputObject $f | Should -Not -BeNullOrEmpty
Get-Member -InputObject $a | Should -Not -BeNullOrEmpty
Get-Member -InputObject $b | Should -Not -BeNullOrEmpty
Get-Member -InputObject $c | Should -Not -BeNullOrEmpty
Get-Member -InputObject $d | Should -Not -BeNullOrEmpty
Get-Member -InputObject $e | Should -Not -BeNullOrEmpty
Get-Member -InputObject $f | Should -Not -BeNullOrEmpty
}

It "Should be able to extract a field from string objects, ints, arrays, etc" {
$a = 1 #test numbers
$b = 1.3
$c = $false #test bools
$d = @(1,3) # test arrays
$e = "anoeduntodeu" #test strings
$f = 'asntoheusth' #test strings
$a = 1 #test numbers
$b = 1.3
$c = $false #test bools
$d = @(1, 3) # test arrays
$e = "anoeduntodeu" #test strings
$f = 'asntoheusth' #test strings

$a | Should -BeOfType 'Int32'
$b | Should -BeOfType 'Double'
$c | Should -BeOfType 'Boolean'
,$d | Should -BeOfType 'Object[]'
$e | Should -BeOfType 'String'
$f | Should -BeOfType 'String'
$a | Should -BeOfType 'Int32'
$b | Should -BeOfType 'Double'
$c | Should -BeOfType 'Boolean'
, $d | Should -BeOfType 'Object[]'
$e | Should -BeOfType 'String'
$f | Should -BeOfType 'String'
}

It "Should be able to be called on a newly created PSObject" {
$o = New-Object psobject
# this creates a dependency on the Add-Member cmdlet.
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
$o = New-Object psobject
# this creates a dependency on the Add-Member cmdlet.
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"

Get-Member -InputObject $o | Should -Not -BeNullOrEmpty
Get-Member -InputObject $o | Should -Not -BeNullOrEmpty
}

It "Should be able to be called on IntPtr" {
Expand All @@ -47,13 +47,17 @@ Describe "Get-Member" -Tags "CI" {
$results[0].Name | Should -BeExactly 'Size'
$results[1].Name | Should -BeExactly 'Zero'
}

It "Should work with incomplete parameter '-i'" {
$a = 1
{ Get-Member -i $a } | Should -Not -Throw
}
}

Describe "Get-Member DRT Unit Tests" -Tags "CI" {
Context "Verify Get-Member with Class" {
if(-not ([System.Management.Automation.PSTypeName]'Employee').Type)
{
Add-Type -TypeDefinition @"
if (-not ([System.Management.Automation.PSTypeName]'Employee').Type) {
Add-Type -TypeDefinition @"
public class Employee
{
private string firstName;
Expand Down Expand Up @@ -104,10 +108,10 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" {
}
}
"@
}
}

$fileToDeleteName = Join-Path $TestDrive -ChildPath "getMemberTest.ps1xml"
$XMLFile= @"
$XMLFile = @"
<Types>
<Type>
<Name>Employee</Name>
Expand Down Expand Up @@ -175,19 +179,15 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" {
$results.Length | Should -Be $methodList.Length
$methodFound = @()

for ($i = 0;$i -lt $methodList.Length;$i++)
{
for ($j = 0;$j -lt $results.Length;$j++)
{
if ($results[$j].Name.Equals($methodList[$i]))
{
for ($i = 0; $i -lt $methodList.Length; $i++) {
for ($j = 0; $j -lt $results.Length; $j++) {
if ($results[$j].Name.Equals($methodList[$i])) {
$methodFound += $true
}
}
}

for ($i = 0;$i -lt $methodList.Length;$i++)
{
for ($i = 0; $i -lt $methodList.Length; $i++) {
$methodFound[$i] | Should -BeTrue
}
}
Expand All @@ -206,12 +206,9 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" {
$obj = New-Object -TypeName System.Int32
$results = $obj | Get-Member -Static
$members = "MaxValue", "MinValue", "Parse", "TryParse"
foreach ($member in $members)
{
foreach ($result in $results)
{
if($result.Name.Equals($member))
{
foreach ($member in $members) {
foreach ($result in $results) {
if ($result.Name.Equals($member)) {
return $true
}
}
Expand All @@ -222,12 +219,9 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" {
It "Get the static properties and methods of int instance" {
$results = 1 | Get-Member -Static
$members = "MaxValue", "MinValue", "Parse", "TryParse"
foreach ($member in $members)
{
foreach ($result in $results)
{
if($result.Name.Equals($member))
{
foreach ($member in $members) {
foreach ($result in $results) {
if ($result.Name.Equals($member)) {
return $true
}
}
Expand All @@ -238,12 +232,9 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" {
It "Get the static properties and methods of int instance Wrapped" {
$results = [pscustomobject]1 | Get-Member -Static
$members = "MaxValue", "MinValue", "Parse", "TryParse"
foreach ($member in $members)
{
foreach ($result in $results)
{
if($result.Name.Equals($member))
{
foreach ($member in $members) {
foreach ($result in $results) {
if ($result.Name.Equals($member)) {
return $true
}
}
Expand All @@ -260,31 +251,25 @@ Describe "Get-Member DRT Unit Tests" -Tags "CI" {
$results | Where-Object Name -eq CreateNode | Should -Not -BeNullOrEmpty
}

It 'Get hidden members'{
It 'Get hidden members' {
$results = 'abc' | Get-Member -force
$hiddenMembers = "psbase", "psextended", "psadapted", "pstypenames", "psobject"
foreach ($member in $hiddenMembers)
{
foreach ($result in $results)
{
if($result.Name.Equals($member))
{
foreach ($member in $hiddenMembers) {
foreach ($result in $results) {
if ($result.Name.Equals($member)) {
return $true
}
}
return $false
}
}

It 'Get Set Property Accessors On PsBase'{
It 'Get Set Property Accessors On PsBase' {
$results = ('abc').psbase | Get-Member -force get_*
$expectedMembers = "get_Chars", "get_Length"
foreach ($member in $expectedMembers)
{
foreach ($result in $results)
{
if($result.Name.Equals($member))
{
foreach ($member in $expectedMembers) {
foreach ($result in $results) {
if ($result.Name.Equals($member)) {
return $true
}
}
Expand Down