Fix member completion for PowerShell Enum class (#19740)

This commit is contained in:
MartinGC94
2023-06-05 17:04:19 -07:00
committed by GitHub
parent cc05fdead2
commit 79d99b501b
2 changed files with 22 additions and 1 deletions
@@ -364,7 +364,22 @@ namespace System.Management.Automation
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)
@@ -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 ""