From 9140e421eceeef9d92cf671cc6aaa0782ea343cd Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Thu, 18 Apr 2019 11:42:49 -0700 Subject: [PATCH] Add wildcard back to end of tab completion command lookup (#9383) Re-add wildcard when searching AST + Missed test case. ## PR Context In #8109, we removed the line that added a wildcard to the end of the command that was used to match commands in the script AST. This readds that line closer to where it is used. --- .../engine/CommandCompletion/CompletionCompleters.cs | 3 +++ test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 | 1 + 2 files changed, 4 insertions(+) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index d117e09428..5c6d11c96c 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -103,6 +103,9 @@ namespace System.Management.Automation if (lastAst != null) { + // We need to add the wildcard to the end so the regex is built correctly. + commandName += "*"; + // Search the asts for function definitions that we might be calling var findFunctionsVisitor = new FindFunctionsVisitor(); while (lastAst.Parent != null) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index f48a66acf9..06f29a40b1 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -485,6 +485,7 @@ Describe "TabCompletion" -Tags CI { @{ inputStr = '$A=[datetime]::now;$A.'; expected = 'Date'; setup = $null } @{ inputStr = 'try { 1/0 } catch {};$error[0].'; expected = 'CategoryInfo'; setup = $null } @{ inputStr = '$x= gps pwsh;$x.*pm'; expected = 'NPM'; setup = $null } + @{ inputStr = 'function Get-ScrumData {}; Get-Scrum'; expected = 'Get-ScrumData'; setup = $null } @{ inputStr = 'function write-output {param($abcd) $abcd};Write-Output -a'; expected = '-abcd'; setup = $null } @{ inputStr = 'function write-output {param($abcd) $abcd};Microsoft.PowerShell.Utility\Write-Output -'; expected = '-InputObject'; setup = $null } @{ inputStr = '[math]::Co'; expected = 'Cos('; setup = $null }