diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 2fa8fbc68da..cf88b76bca7 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -3172,6 +3172,12 @@ private static void NativeCompletionProcessCommands(CompletionContext context, s completionText = quote + completionText + quote; } + // on macOS, system processes names will be empty if PowerShell isn't run as `sudo` + if (string.IsNullOrEmpty(listItemText)) + { + continue; + } + result.Add(new CompletionResult(completionText, listItemText, CompletionResultType.ParameterValue, listItemText)); } diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 1be3ae286f8..505b11d87eb 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -115,6 +115,14 @@ Describe "TabCompletion" -Tags CI { $res.CompletionMatches[0].ToolTip -match '^\d+ -' | Should -BeTrue } + It 'Should complete "Get-Process" with process names' { + $cmd = "Get-Process " + $res = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + # Can't compare to number of processes since macOS has a large number of processes + # that have empty Name which should be skipped + $res.CompletionMatches.Count | Should -BeGreaterThan 0 + } + It 'Should complete keyword' -skip { $res = TabExpansion2 -inputScript 'using nam' -cursorColumn 'using nam'.Length $res.CompletionMatches[0].CompletionText | Should -Be 'namespace'