Fix type completion for attribute tokens (#17484)

This commit is contained in:
MartinGC94
2022-07-19 09:08:10 -07:00
committed by GitHub
parent bfb59f1acf
commit 618b348cdb
2 changed files with 8 additions and 2 deletions
@@ -424,7 +424,7 @@ namespace System.Management.Automation
case TokenKind.Generic:
case TokenKind.MinusMinus: // for native commands '--'
case TokenKind.Identifier:
if (tokenAtCursor.TokenFlags != TokenFlags.TypeName)
if (!tokenAtCursor.TokenFlags.HasFlag(TokenFlags.TypeName))
{
result = GetResultForIdentifier(completionContext, ref replacementIndex, ref replacementLength, isQuotedString);
}
@@ -1021,7 +1021,7 @@ namespace System.Management.Automation
}
}
if (typeNameToComplete is null && tokenAtCursor?.TokenFlags == TokenFlags.TypeName)
if (typeNameToComplete is null && tokenAtCursor?.TokenFlags.HasFlag(TokenFlags.TypeName) == true)
{
typeNameToComplete = new TypeName(tokenAtCursor.Extent, tokenAtCursor.Text);
}
@@ -1209,6 +1209,12 @@ ConstructorTestClass(int i, bool b)
$res.CompletionMatches[1].CompletionText | Should -BeExactly 'DarkCyan'
}
It "Tab completion for attribute type" {
$inputStr = '[validateset()]$var1'
$res = TabExpansion2 -inputScript $inputStr -cursorColumn 2
$res.CompletionMatches.CompletionText | Should -Contain 'ValidateSet'
}
It "Tab completion for ArgumentCompleter when AST is passed to CompleteInput" {
$scriptBl = {
function Test-Completion {