File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
src/System.Management.Automation/engine/CommandCompletion
test/powershell/Host/TabCompletion Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -5200,6 +5200,12 @@ internal static List<CompletionResult> CompleteVariable(CompletionContext contex
52005200
52015201 var lastAst = context . RelatedAsts ? [ ^ 1 ] ;
52025202 var variableAst = lastAst as VariableExpressionAst ;
5203+ if ( lastAst is PropertyMemberAst ||
5204+ ( lastAst is not null && lastAst . Parent is ParameterAst parameter && parameter . DefaultValue != lastAst ) )
5205+ {
5206+ // User is adding a new parameter or a class member, variable tab completion is not useful.
5207+ return results ;
5208+ }
52035209 var prefix = variableAst != null && variableAst . Splatted ? "@" : "$" ;
52045210 bool tokenAtCursorUsedBraces = context . TokenAtCursor is not null && context . TokenAtCursor . Text . StartsWith ( "${" ) ;
52055211
Original file line number Diff line number Diff line change @@ -79,6 +79,21 @@ Describe "TabCompletion" -Tags CI {
7979 $res.CompletionMatches [0 ].CompletionText | Should - BeExactly ' $CurrentItem'
8080 }
8181
82+ It ' Should not complete parameter name' {
83+ $res = TabExpansion2 - inputScript ' param($P'
84+ $res.CompletionMatches.Count | Should - Be 0
85+ }
86+
87+ It ' Should complete variable in default value of a parameter' {
88+ $res = TabExpansion2 - inputScript ' param($PS = $P'
89+ $res.CompletionMatches.Count | Should - BeGreaterThan 0
90+ }
91+
92+ It ' Should not complete property name in class definition' {
93+ $res = TabExpansion2 - inputScript ' class X {$P'
94+ $res.CompletionMatches.Count | Should - Be 0
95+ }
96+
8297 foreach ($Operator in [System.Management.Automation.CompletionCompleters ]::CompleteOperator(" " ))
8398 {
8499 It " Should complete $ ( $Operator.CompletionText ) " {
You can’t perform that action at this time.
0 commit comments