mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Improve dynamic parameter tab completion (#17661)
This commit is contained in:
+22
-11
@@ -1235,21 +1235,32 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
else
|
||||
{
|
||||
var dash = _commandElements[commandIndex] as StringConstantExpressionAst;
|
||||
if (dash != null && dash.Value.Trim().Equals("-", StringComparison.OrdinalIgnoreCase))
|
||||
object valueToAdd;
|
||||
ExpressionAst expressionToAdd;
|
||||
if (_commandElements[commandIndex] is ConstantExpressionAst constant)
|
||||
{
|
||||
if (constant.Extent.Text.Equals("-", StringComparison.Ordinal))
|
||||
{
|
||||
// A value of "-" is most likely the user trying to tab here,
|
||||
// and we don't want it be treated as an argument
|
||||
continue;
|
||||
}
|
||||
|
||||
valueToAdd = constant.Value;
|
||||
expressionToAdd = constant;
|
||||
}
|
||||
else if (_commandElements[commandIndex] is ExpressionAst expression)
|
||||
{
|
||||
valueToAdd = expression.Extent.Text;
|
||||
expressionToAdd = expression;
|
||||
}
|
||||
else
|
||||
{
|
||||
// "-" is represented by StringConstantExpressionAst. Most likely the user type a tab here,
|
||||
// and we don't want it be treated as an argument
|
||||
continue;
|
||||
}
|
||||
|
||||
var expressionArgument = _commandElements[commandIndex] as ExpressionAst;
|
||||
if (expressionArgument != null)
|
||||
{
|
||||
argumentsToGetDynamicParameters?.Add(expressionArgument.Extent.Text);
|
||||
|
||||
_arguments.Add(new AstPair(null, expressionArgument));
|
||||
}
|
||||
argumentsToGetDynamicParameters?.Add(valueToAdd);
|
||||
_arguments.Add(new AstPair(null, expressionToAdd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,6 +510,19 @@ ConstructorTestClass(int i, bool b)
|
||||
$res.CompletionMatches[0].CompletionText | Should -BeExactly Cat
|
||||
}
|
||||
|
||||
it 'Should complete provider dynamic parameters with quoted path' {
|
||||
$Script = if ($IsWindows)
|
||||
{
|
||||
'Get-ChildItem -Path "C:\" -Director'
|
||||
}
|
||||
else
|
||||
{
|
||||
'Get-ChildItem -Path "/" -Director'
|
||||
}
|
||||
$res = TabExpansion2 -inputScript $Script
|
||||
$res.CompletionMatches[0].CompletionText | Should -BeExactly '-Directory'
|
||||
}
|
||||
|
||||
Context "Format cmdlet's View paramter completion" {
|
||||
BeforeAll {
|
||||
$viewDefinition = @'
|
||||
|
||||
Reference in New Issue
Block a user