mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add property assignment completion for enums (#19178)
* Add property assignment completion for enums * Move method
This commit is contained in:
@@ -1421,6 +1421,24 @@ namespace System.Management.Automation
|
||||
return typeConstraint != null || setConstraint != null;
|
||||
}
|
||||
|
||||
private static List<CompletionResult> CompletePropertyAssignment(MemberExpressionAst memberExpression, CompletionContext context)
|
||||
{
|
||||
if (SafeExprEvaluator.TrySafeEval(memberExpression, context.ExecutionContext, out var evalValue))
|
||||
{
|
||||
if (evalValue is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Type type = evalValue.GetType();
|
||||
if (type.IsEnum)
|
||||
{
|
||||
return GetResultForEnum(type, context);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool TryGetCompletionsForVariableAssignment(
|
||||
CompletionContext completionContext,
|
||||
AssignmentStatementAst assignmentAst,
|
||||
@@ -1452,6 +1470,12 @@ namespace System.Management.Automation
|
||||
return false;
|
||||
}
|
||||
|
||||
if (assignmentAst.Left is MemberExpressionAst member)
|
||||
{
|
||||
completions = CompletePropertyAssignment(member, completionContext);
|
||||
return completions is not null;
|
||||
}
|
||||
|
||||
completions = null;
|
||||
|
||||
// Try to get the variable from the assignment, plus any type constraint on it
|
||||
|
||||
@@ -378,6 +378,11 @@ using `
|
||||
$res.CompletionMatches[0].CompletionText | Should -BeExactly '${PSVersionTable}'
|
||||
}
|
||||
|
||||
It 'Should work for property assignment of enum type:' {
|
||||
$res = TabExpansion2 -inputScript '$psstyle.Progress.View="Clas'
|
||||
$res.CompletionMatches[0].CompletionText | Should -Be '"Classic"'
|
||||
}
|
||||
|
||||
It 'Should work for variable assignment of enum type: <inputStr>' -TestCases @(
|
||||
@{ inputStr = '$ErrorActionPreference = '; filter = ''; doubleQuotes = $false }
|
||||
@{ inputStr = '$ErrorActionPreference='; filter = ''; doubleQuotes = $false }
|
||||
|
||||
Reference in New Issue
Block a user