diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs index 27bd522cd4..6b32856c01 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs @@ -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); } diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index ec698b8762..250809bf44 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -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 {