Thanks to visit codestin.com
Credit goes to github.com

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 @@ -5573,7 +5573,13 @@ public override AstVisitAction VisitAssignmentStatement(AssignmentStatementAst a
: AstVisitAction.StopVisit;
}

if (assignmentStatementAst.Left is AttributedExpressionAst attributedExpression)
ProcessAssignmentLeftSide(assignmentStatementAst.Left, assignmentStatementAst.Right);
return AstVisitAction.Continue;
}

private void ProcessAssignmentLeftSide(ExpressionAst left, StatementAst right)
{
if (left is AttributedExpressionAst attributedExpression)
{
var firstConvertExpression = attributedExpression as ConvertExpressionAst;
ExpressionAst child = attributedExpression.Child;
Expand All @@ -5593,7 +5599,7 @@ public override AstVisitAction VisitAssignmentStatement(AssignmentStatementAst a
{
if (variableExpression == CompletionVariableAst || s_specialVariablesCache.Value.Contains(variableExpression.VariablePath.UserPath))
{
return AstVisitAction.Continue;
return;
}

if (firstConvertExpression is not null)
Expand All @@ -5602,22 +5608,22 @@ public override AstVisitAction VisitAssignmentStatement(AssignmentStatementAst a
}
else
{
PSTypeName lastAssignedType = assignmentStatementAst.Right is CommandExpressionAst commandExpression
PSTypeName lastAssignedType = right is CommandExpressionAst commandExpression
? GetInferredVarTypeFromAst(commandExpression.Expression)
: null;
SaveVariableInfo(variableExpression.VariablePath.UnqualifiedPath, lastAssignedType, isConstraint: false);
}
}
}
else if (assignmentStatementAst.Left is VariableExpressionAst variableExpression)
else if (left is VariableExpressionAst variableExpression)
{
if (variableExpression == CompletionVariableAst || s_specialVariablesCache.Value.Contains(variableExpression.VariablePath.UserPath))
{
return AstVisitAction.Continue;
return;
}

PSTypeName lastAssignedType;
if (assignmentStatementAst.Right is CommandExpressionAst commandExpression)
if (right is CommandExpressionAst commandExpression)
{
lastAssignedType = GetInferredVarTypeFromAst(commandExpression.Expression);
}
Expand All @@ -5628,8 +5634,21 @@ public override AstVisitAction VisitAssignmentStatement(AssignmentStatementAst a

SaveVariableInfo(variableExpression.VariablePath.UnqualifiedPath, lastAssignedType, isConstraint: false);
}

return AstVisitAction.Continue;
else if (left is ArrayLiteralAst array)
{
foreach (ExpressionAst expression in array.Elements)
{
ProcessAssignmentLeftSide(expression, right);
}
}
else if (left is ParenExpressionAst parenExpression)
{
ExpressionAst pureExpression = parenExpression.Pipeline.GetPureExpression();
if (pureExpression is not null)
{
ProcessAssignmentLeftSide(pureExpression, right);
}
}
}

public override AstVisitAction VisitCommand(CommandAst commandAst)
Expand Down
11 changes: 11 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,17 @@ param([ValidatePattern(
$res.CompletionMatches[0].CompletionText | Should -BeExactly '$TestVar1'
}

It 'Should complete variable assigned in ParenExpression' {
$res = TabExpansion2 -inputScript '($ParenVar) = 1; $ParenVa'
$res.CompletionMatches[0].CompletionText | Should -BeExactly '$ParenVar'
}

It 'Should complete variable assigned in ArrayLiteral' {
$res = TabExpansion2 -inputScript '$DemoVar1, $DemoVar2 = 1..10; $DemoVar'
$res.CompletionMatches[0].CompletionText | Should -BeExactly '$DemoVar1'
$res.CompletionMatches[1].CompletionText | Should -BeExactly '$DemoVar2'
}

Context 'Start-Process -Verb parameter completion' {
BeforeAll {
function GetProcessInfoVerbs([string]$path, [switch]$singleQuote, [switch]$doubleQuote) {
Expand Down
Loading