mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add quote handling in Verb, StrictModeVersion, Scope & PropertyType Argument Completers with single helper method (#24839)
This commit is contained in:
+7
-25
@@ -226,31 +226,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
string wordToComplete,
|
||||
CommandAst commandAst,
|
||||
IDictionary fakeBoundParameters)
|
||||
{
|
||||
if (!IsRegistryProvider(fakeBoundParameters))
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
string quote = CompletionCompleters.HandleDoubleAndSingleQuote(ref wordToComplete);
|
||||
var propertyTypePattern = WildcardPattern.Get(wordToComplete + "*", WildcardOptions.IgnoreCase);
|
||||
|
||||
foreach (string propertyType in s_RegistryPropertyTypes)
|
||||
{
|
||||
if (propertyTypePattern.IsMatch(propertyType))
|
||||
{
|
||||
string completionText = quote == string.Empty
|
||||
? propertyType
|
||||
: quote + propertyType + quote;
|
||||
|
||||
yield return new CompletionResult(
|
||||
completionText,
|
||||
propertyType,
|
||||
CompletionResultType.ParameterValue,
|
||||
GetRegistryPropertyTypeToolTip(propertyType));
|
||||
}
|
||||
}
|
||||
}
|
||||
=> IsRegistryProvider(fakeBoundParameters)
|
||||
? CompletionCompleters.GetMatchingResults(
|
||||
wordToComplete,
|
||||
possibleCompletionValues: s_RegistryPropertyTypes,
|
||||
toolTipMapping: GetRegistryPropertyTypeToolTip,
|
||||
resultType: CompletionResultType.ParameterValue)
|
||||
: [];
|
||||
|
||||
/// <summary>
|
||||
/// Checks if parameter paths are from Registry provider.
|
||||
|
||||
@@ -2664,7 +2664,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// -Verb is not supported on non-Windows platforms as well as Windows headless SKUs
|
||||
if (!Platform.IsWindowsDesktop)
|
||||
{
|
||||
yield break;
|
||||
return [];
|
||||
}
|
||||
|
||||
// Completion: Start-Process -FilePath <path> -Verb <wordToComplete>
|
||||
@@ -2676,12 +2676,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Complete file verbs if extension exists
|
||||
if (Path.HasExtension(filePath))
|
||||
{
|
||||
foreach (string verb in CompleteFileVerbs(filePath, wordToComplete))
|
||||
{
|
||||
yield return new CompletionResult(verb);
|
||||
}
|
||||
|
||||
yield break;
|
||||
return CompleteFileVerbs(wordToComplete, filePath);
|
||||
}
|
||||
|
||||
// Otherwise check if command is an Application to resolve executable full path with extension
|
||||
@@ -2699,34 +2694,23 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Start-Process & Get-Command select first found application based on PATHEXT environment variable
|
||||
if (commands.Count >= 1)
|
||||
{
|
||||
foreach (string verb in CompleteFileVerbs(commands[0].Source, wordToComplete))
|
||||
{
|
||||
yield return new CompletionResult(verb);
|
||||
}
|
||||
return CompleteFileVerbs(wordToComplete, filePath: commands[0].Source);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Completes file verbs.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The file path to get verbs.</param>
|
||||
/// <param name="wordToComplete">The word to complete.</param>
|
||||
/// <param name="filePath">The file path to get verbs.</param>
|
||||
/// <returns>List of file verbs to complete.</returns>
|
||||
private static IEnumerable<string> CompleteFileVerbs(string filePath, string wordToComplete)
|
||||
{
|
||||
var verbPattern = WildcardPattern.Get(wordToComplete + "*", WildcardOptions.IgnoreCase);
|
||||
|
||||
string[] verbs = new ProcessStartInfo(filePath).Verbs;
|
||||
|
||||
foreach (string verb in verbs)
|
||||
{
|
||||
if (verbPattern.IsMatch(verb))
|
||||
{
|
||||
yield return verb;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static IEnumerable<CompletionResult> CompleteFileVerbs(string wordToComplete, string filePath)
|
||||
=> CompletionCompleters.GetMatchingResults(
|
||||
wordToComplete,
|
||||
possibleCompletionValues: new ProcessStartInfo(filePath).Verbs);
|
||||
}
|
||||
|
||||
#if !UNIX
|
||||
|
||||
Reference in New Issue
Block a user