Fix tab completion within the script block specified for the `ValidateScriptAttribute`. (#14550)

This commit is contained in:
MartinGC94 2021-11-10 03:26:14 +01:00 committed by GitHub
parent 19b5647c0a
commit 965dc8f40f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -1813,9 +1813,14 @@ namespace System.Management.Automation
}
}
}
result = GetResultForAttributeArgument(completionContext, ref replacementIndex, ref replacementLength);
if (result != null) return result;
if (completionContext.TokenAtCursor.TokenFlags == TokenFlags.MemberName)
{
result = GetResultForAttributeArgument(completionContext, ref replacementIndex, ref replacementLength);
if (result is not null)
{
return result;
}
}
if ((tokenAtCursor.TokenFlags & TokenFlags.CommandName) != 0)
{

View File

@ -1097,6 +1097,14 @@ Describe "TabCompletion" -Tags CI {
$entry.CompletionText | Should -BeExactly "Mandatory"
}
It "Test Attribute scriptblock completion" {
$inputStr = '[ValidateScript({Get-Child})]$Test=ls'
$res = TabExpansion2 -inputScript $inputStr -cursorColumn ($inputStr.IndexOf('}'))
$res.CompletionMatches | Should -HaveCount 1
$entry = $res.CompletionMatches | Where-Object CompletionText -EQ "Get-ChildItem"
$entry.CompletionText | Should -BeExactly "Get-ChildItem"
}
It "Test completion with line continuation" {
$inputStr = @'
dir -Recurse `