Fix tab completion regression (#17628)

This commit is contained in:
MartinGC94
2022-07-07 15:45:50 +05:00
committed by GitHub
parent 17b23e3ebc
commit 81f492744d
2 changed files with 13 additions and 2 deletions
@@ -1689,7 +1689,7 @@ namespace System.Management.Automation
{
RemoveLastNullCompletionResult(result);
string wordToComplete = context.WordToComplete;
string wordToComplete = context.WordToComplete ?? string.Empty;
string quote = HandleDoubleAndSingleQuote(ref wordToComplete);
var pattern = WildcardPattern.Get(wordToComplete + "*", WildcardOptions.IgnoreCase);
@@ -4126,7 +4126,7 @@ namespace System.Management.Automation
return GenerateArgumentLocation(prevArg, position);
}
if (token.Kind == TokenKind.Parameter
if ((token.Kind == TokenKind.Parameter && token.Extent.StartOffset == arg.Parameter.Extent.StartOffset)
|| (token.Extent.StartOffset > arg.Argument.Extent.StartOffset && token.Extent.EndOffset < arg.Argument.Extent.EndOffset))
{
// case 1: Get-Cmdlet -Param <tab> abc
@@ -499,6 +499,17 @@ ConstructorTestClass(int i, bool b)
$diffs | Should -BeNullOrEmpty
}
It 'Should complete argument for second parameter' {
$res = TabExpansion2 -inputScript 'Get-ChildItem -Path $HOME -ErrorAction '
$res.CompletionMatches[0].CompletionText | Should -BeExactly Break
}
It 'Should complete argument with validateset attribute after comma' {
$TestString = 'function Test-ValidateSet{Param([ValidateSet("Cat","Dog")]$Param1,$Param2)};Test-ValidateSet -Param1 Dog, -Param2'
$res = TabExpansion2 -inputScript $TestString -cursorColumn ($TestString.LastIndexOf(',') + 1)
$res.CompletionMatches[0].CompletionText | Should -BeExactly Cat
}
Context "Format cmdlet's View paramter completion" {
BeforeAll {
$viewDefinition = @'