mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add completion for variables assigned by command redirection (#25104)
This commit is contained in:
@@ -5797,6 +5797,46 @@ namespace System.Management.Automation
|
||||
}
|
||||
}
|
||||
|
||||
foreach (RedirectionAst redirection in commandAst.Redirections)
|
||||
{
|
||||
if (redirection is FileRedirectionAst fileRedirection
|
||||
&& fileRedirection.Location is StringConstantExpressionAst redirectTarget
|
||||
&& redirectTarget.Value.StartsWith("variable:", StringComparison.OrdinalIgnoreCase)
|
||||
&& redirectTarget.Value.Length > "variable:".Length)
|
||||
{
|
||||
string varName = redirectTarget.Value.Substring("variable:".Length);
|
||||
PSTypeName varType;
|
||||
switch (fileRedirection.FromStream)
|
||||
{
|
||||
case RedirectionStream.Error:
|
||||
varType = new PSTypeName(typeof(ErrorRecord));
|
||||
break;
|
||||
|
||||
case RedirectionStream.Warning:
|
||||
varType = new PSTypeName(typeof(WarningRecord));
|
||||
break;
|
||||
|
||||
case RedirectionStream.Verbose:
|
||||
varType = new PSTypeName(typeof(VerboseRecord));
|
||||
break;
|
||||
|
||||
case RedirectionStream.Debug:
|
||||
varType = new PSTypeName(typeof(DebugRecord));
|
||||
break;
|
||||
|
||||
case RedirectionStream.Information:
|
||||
varType = new PSTypeName(typeof(InformationRecord));
|
||||
break;
|
||||
|
||||
default:
|
||||
varType = null;
|
||||
break;
|
||||
}
|
||||
|
||||
SaveVariableInfo(varName, varType, isConstraint: false);
|
||||
}
|
||||
}
|
||||
|
||||
return AstVisitAction.Continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -436,6 +436,21 @@ switch ($x)
|
||||
$res.CompletionMatches.Count | Should -Be 0
|
||||
}
|
||||
|
||||
It 'Should complete variable assigned in command redirection to variable' {
|
||||
$res = TabExpansion2 -inputScript 'New-Guid 1>variable:Redir1 2>variable:Redir2 3>variable:Redir3 4>variable:Redir4 5>variable:Redir5 6>variable:Redir6; $Redir'
|
||||
$res.CompletionMatches[0].CompletionText | Should -Be '$Redir1'
|
||||
$res.CompletionMatches[1].CompletionText | Should -Be '$Redir2'
|
||||
$res.CompletionMatches[1].ToolTip | Should -Be '[ErrorRecord]$Redir2'
|
||||
$res.CompletionMatches[2].CompletionText | Should -Be '$Redir3'
|
||||
$res.CompletionMatches[2].ToolTip | Should -Be '[WarningRecord]$Redir3'
|
||||
$res.CompletionMatches[3].CompletionText | Should -Be '$Redir4'
|
||||
$res.CompletionMatches[3].ToolTip | Should -Be '[VerboseRecord]$Redir4'
|
||||
$res.CompletionMatches[4].CompletionText | Should -Be '$Redir5'
|
||||
$res.CompletionMatches[4].ToolTip | Should -Be '[DebugRecord]$Redir5'
|
||||
$res.CompletionMatches[5].CompletionText | Should -Be '$Redir6'
|
||||
$res.CompletionMatches[5].ToolTip | Should -Be '[InformationRecord]$Redir6'
|
||||
}
|
||||
|
||||
context TypeConstructionWithHashtable {
|
||||
BeforeAll {
|
||||
class RandomTestType {
|
||||
|
||||
Reference in New Issue
Block a user