Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Enum member completion for PS Enums #19740

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,22 @@ internal void AddMembersByInferredTypesClrType(PSTypeName typename, bool isStati
filterToCall = filter;
}

results.AddRange(GetMembersByInferredType(new PSTypeName(typeof(object)), isStatic, filterToCall));
PSTypeName baseMembersType;
if (typename.TypeDefinitionAst.IsEnum)
{
if (!isStatic)
{
results.Add(new PSInferredProperty("value__", new PSTypeName(typeof(int))));
}

baseMembersType = new PSTypeName(typeof(Enum));
}
else
{
baseMembersType = new PSTypeName(typeof(object));
}

results.AddRange(GetMembersByInferredType(baseMembersType, isStatic, filterToCall));
}

internal void AddMembersByInferredTypeCimType(PSTypeName typename, List<object> results, Func<object, bool> filterToCall)
Expand Down
6 changes: 6 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,12 @@ class InheritedClassTest : System.Attribute
$res.CompletionMatches.CompletionText | Should -Contain '-ProgressAction'
}

it 'Should complete enum class members for Enums in script text' {
$res = TabExpansion2 -inputScript 'enum Test1 {Val1};([Test1]"").'
$res.CompletionMatches.CompletionText[0] | Should -Be 'value__'
$res.CompletionMatches.CompletionText | Should -Contain 'HasFlag('
}

Context "Script name completion" {
BeforeAll {
Setup -f 'install-powershell.ps1' -Content ""
Expand Down
Loading