From 4535e76a9466b2df0d6c8538dfa1da00c2297de0 Mon Sep 17 00:00:00 2001 From: MartinGC94 Date: Sat, 16 Jan 2021 09:09:08 +0100 Subject: [PATCH 1/7] Fix binding splat variables to positional parameters. --- .../engine/CommandCompletion/PseudoParameterBinder.cs | 9 ++++++--- .../Host/TabCompletion/TabCompletion.Tests.ps1 | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index 0d195280239..ad7598c2d78 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1862,13 +1862,16 @@ private static AstParameterArgumentPair GetNextPositionalArgument( while (unboundArgumentsIndex < unboundArgumentsCollection.Count) { AstParameterArgumentPair argument = unboundArgumentsCollection[unboundArgumentsIndex++]; - if (!argument.ParameterSpecified) + bool splatted = (argument is AstPair a) && (a.Argument is VariableExpressionAst v) && v.Splatted; + if (!argument.ParameterSpecified && splatted == false) { result = argument; break; } - - nonPositionalArguments.Add(argument); + if (splatted == false) + { + nonPositionalArguments.Add(argument); + } } return result; diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 77667306aed..718016ecc85 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -953,6 +953,13 @@ dir -Recurse ` $res.CompletionMatches | Should -HaveCount 4 [string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-wa,-Wait,-WarningAction,-WarningVariable" } + + It "Test completion with splatted variable" { + $inputStr = 'Get-Content @Splat -P' + $res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length + $res.CompletionMatches | Should -HaveCount 4 + [string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-Path,-PipelineVariable,-PSPath,-pv" + } } Context "Module completion for 'using module'" { From 1e02fb292d1147ee2d1098cb49b7a7212c21d38d Mon Sep 17 00:00:00 2001 From: MartinGC94 Date: Sat, 16 Jan 2021 10:03:31 +0100 Subject: [PATCH 2/7] Fix formatting issue (missing blank line) --- .../engine/CommandCompletion/PseudoParameterBinder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index ad7598c2d78..d6a5ba7a7ac 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1868,6 +1868,7 @@ private static AstParameterArgumentPair GetNextPositionalArgument( result = argument; break; } + if (splatted == false) { nonPositionalArguments.Add(argument); From eb8cde72ae64f84dbe44484c9e4f3efaf2c132c0 Mon Sep 17 00:00:00 2001 From: MartinGC94 <42123497+MartinGC94@users.noreply.github.com> Date: Mon, 14 Jun 2021 23:04:14 +0200 Subject: [PATCH 3/7] Apply suggestions from code review Co-authored-by: Robert Holt --- .../engine/CommandCompletion/PseudoParameterBinder.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index d6a5ba7a7ac..7c056fe8f13 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1862,14 +1862,16 @@ private static AstParameterArgumentPair GetNextPositionalArgument( while (unboundArgumentsIndex < unboundArgumentsCollection.Count) { AstParameterArgumentPair argument = unboundArgumentsCollection[unboundArgumentsIndex++]; - bool splatted = (argument is AstPair a) && (a.Argument is VariableExpressionAst v) && v.Splatted; - if (!argument.ParameterSpecified && splatted == false) + bool splatted = argument is AstPair astPair + && astPair.Argument is VariableExpressionAst argumentVariable + && argumentVariable.Splatted; + if (!splatted && !argument.ParameterSpecified) { result = argument; break; } - if (splatted == false) + if (!splatted) { nonPositionalArguments.Add(argument); } From b51b72ba97cd979e00c234f8188da23327c7cb34 Mon Sep 17 00:00:00 2001 From: MartinGC94 Date: Tue, 15 Jun 2021 21:09:38 +0200 Subject: [PATCH 4/7] Apply suggestions from code review --- .../CommandCompletion/PseudoParameterBinder.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index 7c056fe8f13..7c8cf0f3286 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1865,16 +1865,17 @@ private static AstParameterArgumentPair GetNextPositionalArgument( bool splatted = argument is AstPair astPair && astPair.Argument is VariableExpressionAst argumentVariable && argumentVariable.Splatted; - if (!splatted && !argument.ParameterSpecified) + if (splatted) + { + continue; + } + if (!argument.ParameterSpecified) { result = argument; break; } - - if (!splatted) - { - nonPositionalArguments.Add(argument); - } + + nonPositionalArguments.Add(argument); } return result; From d705fb0d63ddfec270973eee0540672dc0e05704 Mon Sep 17 00:00:00 2001 From: MartinGC94 Date: Tue, 15 Jun 2021 21:11:12 +0200 Subject: [PATCH 5/7] Remove whitespace --- .../engine/CommandCompletion/PseudoParameterBinder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index 7c8cf0f3286..5a57be1c845 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1874,7 +1874,7 @@ private static AstParameterArgumentPair GetNextPositionalArgument( result = argument; break; } - + nonPositionalArguments.Add(argument); } From e934e798ba8db75e728e7cf12873c6cd10d18bca Mon Sep 17 00:00:00 2001 From: MartinGC94 Date: Tue, 15 Jun 2021 21:17:09 +0200 Subject: [PATCH 6/7] Add blank line --- .../engine/CommandCompletion/PseudoParameterBinder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index 5a57be1c845..6b4049054aa 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1869,6 +1869,7 @@ private static AstParameterArgumentPair GetNextPositionalArgument( { continue; } + if (!argument.ParameterSpecified) { result = argument; From c05a2be95291490472f1283100097fd2f1c0ea8a Mon Sep 17 00:00:00 2001 From: MartinGC94 <42123497+MartinGC94@users.noreply.github.com> Date: Tue, 15 Jun 2021 23:17:05 +0200 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Robert Holt --- .../engine/CommandCompletion/PseudoParameterBinder.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index 6b4049054aa..c98be4ccac8 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1862,10 +1862,9 @@ private static AstParameterArgumentPair GetNextPositionalArgument( while (unboundArgumentsIndex < unboundArgumentsCollection.Count) { AstParameterArgumentPair argument = unboundArgumentsCollection[unboundArgumentsIndex++]; - bool splatted = argument is AstPair astPair + if (argument is AstPair astPair && astPair.Argument is VariableExpressionAst argumentVariable - && argumentVariable.Splatted; - if (splatted) + && argumentVariable.Splatted) { continue; }