From 778adfe93d647c70c7bb8d277d423f7897fd5fb6 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Fri, 28 Apr 2017 12:27:20 +0200 Subject: [PATCH 1/4] Add Name as tooltip when tab completing process ID --- .../engine/CommandCompletion/CompletionCompleters.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 41258697b11..65d8ee8f152 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -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)); } } From 6019e78a7d60b0e8002e4f6b2808dd5d1f1dd763 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Fri, 28 Apr 2017 20:45:10 +0200 Subject: [PATCH 2/4] trailing whitespace --- .../TabCompletion/TabCompletion.Tests.ps1 | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index a462b0a3099..7966f75b394 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -1,83 +1,83 @@ 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 { @@ -85,13 +85,13 @@ Describe "TabCompletion" -Tags CI { $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 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' - } + } } From 8c02c06dbe90192a4e943c8edc718307571deda1 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Fri, 28 Apr 2017 20:37:12 +0200 Subject: [PATCH 3/4] Adding test for Get-Process -Id completion --- test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 7966f75b394..30d076dee7f 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -90,6 +90,13 @@ Describe "TabCompletion" -Tags CI { $res.CompletionMatches.Foreach{$_.CompletionText -in 'A', 'B', 'C' | Should Be $true} } + It 'Should complete "Get-Process -Id " with Id and name in tooltip' { + $cmd = 'Get-Process -Id ' + $res = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $res.CompletionMatches[0].CompletionText -match '^\d+$' | Should be true + $res.CompletionMatches[0].ToolTip -match '^\w' | Should be true + } + It 'Should complete keyword' -skip { $res = TabExpansion2 -inputScript 'using nam' -cursorColumn 'using nam'.Length $res.CompletionMatches[0].CompletionText | Should be 'namespace' From 3f64b47888cd9bf4a3edf0bcb43ec6873e9eb891 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Sat, 6 May 2017 01:15:44 +0200 Subject: [PATCH 4/4] Correcting regex in test --- test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 30d076dee7f..dd164aee76a 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -91,10 +91,12 @@ Describe "TabCompletion" -Tags CI { } It 'Should complete "Get-Process -Id " with Id and name in tooltip' { + Set-StrictMode -Version latest $cmd = 'Get-Process -Id ' - $res = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + [System.Management.Automation.CommandCompletion]$res = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length $res.CompletionMatches[0].CompletionText -match '^\d+$' | Should be true - $res.CompletionMatches[0].ToolTip -match '^\w' | 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 {