Skip to content
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 @@ -3201,12 +3201,14 @@ private static void NativeCompletionProcessCommands(string wordToComplete, strin
var pattern = WildcardPattern.Get(wordToComplete, WildcardOptions.IgnoreCase);
foreach (dynamic process in psObjects)
{
var completionText = process.Id.ToString();
if (pattern.IsMatch(completionText))
var processId = process.Id.ToString();
if (pattern.IsMatch(processId))
{
var listItemText = completionText;
completionText = quote + completionText + quote;
result.Add(new CompletionResult(completionText, listItemText, CompletionResultType.ParameterValue, listItemText));
var processName = process.Name;

var idAndName = $"{processId} - {processName}";
processId = quote + processId + quote;
result.Add(new CompletionResult(processId, idAndName, CompletionResultType.ParameterValue, idAndName));
}
}

Expand Down
77 changes: 43 additions & 34 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,97 +1,106 @@
Describe "TabCompletion" -Tags CI {
It 'Should complete Command' {
$res = TabExpansion2 -inputScript 'Get-Com' -cursorColumn 'Get-Com'.Length
$res = TabExpansion2 -inputScript 'Get-Com' -cursorColumn 'Get-Com'.Length
$res.CompletionMatches[0].CompletionText | Should be Get-Command
}

It 'Should complete native exe' -Skip:(!$IsWindows) {
$res = TabExpansion2 -inputScript 'notep' -cursorColumn 'notep'.Length
$res = TabExpansion2 -inputScript 'notep' -cursorColumn 'notep'.Length
$res.CompletionMatches[0].CompletionText | Should be notepad.exe
}

It 'Should complete dotnet method' {
$res = TabExpansion2 -inputScript '(1).ToSt' -cursorColumn '(1).ToSt'.Length
$res = TabExpansion2 -inputScript '(1).ToSt' -cursorColumn '(1).ToSt'.Length
$res.CompletionMatches[0].CompletionText | Should be 'ToString('
}
}

It 'Should complete Magic foreach' {
$res = TabExpansion2 -inputScript '(1..10).Fo' -cursorColumn '(1..10).Fo'.Length
$res = TabExpansion2 -inputScript '(1..10).Fo' -cursorColumn '(1..10).Fo'.Length
$res.CompletionMatches[0].CompletionText | Should be 'Foreach('
}
}

It 'Should complete types' {
$res = TabExpansion2 -inputScript '[pscu' -cursorColumn '[pscu'.Length
$res = TabExpansion2 -inputScript '[pscu' -cursorColumn '[pscu'.Length
$res.CompletionMatches[0].CompletionText | Should be 'pscustomobject'
}
}

It 'Should complete namespaces' {
$res = TabExpansion2 -inputScript 'using namespace Sys' -cursorColumn 'using namespace Sys'.Length
$res = TabExpansion2 -inputScript 'using namespace Sys' -cursorColumn 'using namespace Sys'.Length
$res.CompletionMatches[0].CompletionText | Should be 'System'
}
}


It 'Should complete format-table hashtable' {
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Table @{ ' -cursorColumn 'Get-ChildItem | Format-Table @{ '.Length
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Table @{ ' -cursorColumn 'Get-ChildItem | Format-Table @{ '.Length
$res.CompletionMatches.Count | Should Be 5
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Label', 'Width', 'Alignment', 'Expression', 'FormatString' | Should Be $true}
}
}

It 'Should complete format-* hashtable on GroupBy' -TestCases (

It 'Should complete format-* hashtable on GroupBy' -TestCases (
@{cmd = 'Format-Table'},
@{cmd = 'Format-List'},
@{cmd = 'Format-Wide'},
@{cmd = 'Format-Custom'}
) {
param($cmd)
$res = TabExpansion2 -inputScript "Get-ChildItem | $cmd -GroupBy @{ " -cursorColumn "Get-ChildItem | $cmd -GroupBy @{ ".Length
$res = TabExpansion2 -inputScript "Get-ChildItem | $cmd -GroupBy @{ " -cursorColumn "Get-ChildItem | $cmd -GroupBy @{ ".Length
$res.CompletionMatches.Count | Should Be 3
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Label', 'Expression', 'FormatString' | Should Be $true}
}
}

It 'Should complete format-list hashtable' {
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-List @{ ' -cursorColumn 'Get-ChildItem | Format-List @{ '.Length
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-List @{ ' -cursorColumn 'Get-ChildItem | Format-List @{ '.Length
$res.CompletionMatches.Count | Should Be 3
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Label', 'Expression', 'FormatString' | Should Be $true}
}
}

It 'Should complete format-wide hashtable' {
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Wide @{ ' -cursorColumn 'Get-ChildItem | Format-Wide @{ '.Length
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Wide @{ ' -cursorColumn 'Get-ChildItem | Format-Wide @{ '.Length
$res.CompletionMatches.Count | Should Be 2
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Expression', 'FormatString' | Should Be $true}
}
}

It 'Should complete format-custom hashtable' {
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Custom @{ ' -cursorColumn 'Get-ChildItem | Format-Custom @{ '.Length
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Custom @{ ' -cursorColumn 'Get-ChildItem | Format-Custom @{ '.Length
$res.CompletionMatches.Count | Should Be 2
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Expression', 'Depth' | Should Be $true}
}
}

It 'Should complete Select-Object hashtable' {
$res = TabExpansion2 -inputScript 'Get-ChildItem | Select-Object @{ ' -cursorColumn 'Get-ChildItem | Select-Object @{ '.Length
$res = TabExpansion2 -inputScript 'Get-ChildItem | Select-Object @{ ' -cursorColumn 'Get-ChildItem | Select-Object @{ '.Length
$res.CompletionMatches.Count | Should Be 2
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Name', 'Expression' | Should Be $true}
}
}

It 'Should complete Sort-Object hashtable' {
$res = TabExpansion2 -inputScript 'Get-ChildItem | Sort-Object @{ ' -cursorColumn 'Get-ChildItem | Sort-Object @{ '.Length
$res = TabExpansion2 -inputScript 'Get-ChildItem | Sort-Object @{ ' -cursorColumn 'Get-ChildItem | Sort-Object @{ '.Length
$res.CompletionMatches.Count | Should Be 3
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Expression', 'Ascending', 'Descending' | Should Be $true}
}
}

It 'Should complete New-Object hashtable' {
class X {
$A
$B
$C
}
$res = TabExpansion2 -inputScript 'New-Object -TypeName X -Property @{ ' -cursorColumn 'New-Object -TypeName X -Property @{ '.Length
$res = TabExpansion2 -inputScript 'New-Object -TypeName X -Property @{ ' -cursorColumn 'New-Object -TypeName X -Property @{ '.Length
$res.CompletionMatches.Count | Should Be 3
$res.CompletionMatches.Foreach{$_.CompletionText -in 'A', 'B', 'C' | Should Be $true}
}
}

It 'Should complete "Get-Process -Id " with Id and name in tooltip' {
Set-StrictMode -Version latest
$cmd = 'Get-Process -Id '
[System.Management.Automation.CommandCompletion]$res = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
$res.CompletionMatches[0].CompletionText -match '^\d+$' | Should be true
$res.CompletionMatches[0].ListItemText -match '^\d+ -' | Should be true
$res.CompletionMatches[0].ToolTip -match '^\d+ -' | Should be true
}

It 'Should complete keyword' -skip {
$res = TabExpansion2 -inputScript 'using nam' -cursorColumn 'using nam'.Length
$res = TabExpansion2 -inputScript 'using nam' -cursorColumn 'using nam'.Length
$res.CompletionMatches[0].CompletionText | Should be 'namespace'
}
}
}