Skip to content
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 @@ -1421,6 +1421,24 @@ private static bool TryGetTypeConstraintOnVariable(
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,
Expand Down Expand Up @@ -1452,6 +1470,12 @@ bool TryGetResultForSet(Type typeConstraint, ValidateSetAttribute setConstraint,
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
Expand Down
5 changes: 5 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down