Remove the old fuzzy suggestion and fix the local script file name suggestion (#25177)

This commit is contained in:
Dongbo Wang
2025-03-17 10:19:15 -07:00
committed by GitHub
parent 9f45f9a855
commit 48b25da147
5 changed files with 16 additions and 32 deletions
@@ -243,7 +243,7 @@ namespace System.Management.Automation.Subsystem.Feedback
public Guid Id => _guid;
public string Name => "general";
public string Name => "General Feedback";
public string Description => "The built-in general feedback source for command errors.";
@@ -8,7 +8,6 @@ using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Management.Automation.Host;
using System.Management.Automation.Internal;
using System.Management.Automation.Language;
using System.Management.Automation.Runspaces;
using System.Management.Automation.Subsystem.Feedback;
using System.Runtime.InteropServices;
@@ -67,13 +66,6 @@ namespace System.Management.Automation
$formatString -f $lastError.TargetObject,"".\$($lastError.TargetObject)""
";
private static readonly string s_getFuzzyMatchedCommands = @"
[System.Diagnostics.DebuggerHidden()]
param([string] $formatString)
$formatString -f [string]::Join(', ', (Get-Command $lastError.TargetObject -UseFuzzyMatching -FuzzyMinimumDistance 1 | Select-Object -First 5 -Unique -ExpandProperty Name))
";
private static readonly List<Hashtable> s_suggestions = InitializeSuggestions();
private static bool HostSupportUnicode()
@@ -97,28 +89,17 @@ namespace System.Management.Automation
private static List<Hashtable> InitializeSuggestions()
{
var suggestions = new List<Hashtable>(
new Hashtable[]
{
NewSuggestion(
id: 3,
category: "General",
matchType: SuggestionMatchType.Dynamic,
rule: ScriptBlock.CreateDelayParsedScriptBlock(s_checkForCommandInCurrentDirectoryScript, isProductCode: true),
suggestion: ScriptBlock.CreateDelayParsedScriptBlock(s_createCommandExistsInCurrentDirectoryScript, isProductCode: true),
suggestionArgs: new object[] { CodeGeneration.EscapeSingleQuotedStringContent(SuggestionStrings.Suggestion_CommandExistsInCurrentDirectory) },
enabled: true)
});
suggestions.Add(
var suggestions = new List<Hashtable>()
{
NewSuggestion(
id: 4,
id: 3,
category: "General",
matchType: SuggestionMatchType.ErrorId,
rule: "CommandNotFoundException",
suggestion: ScriptBlock.CreateDelayParsedScriptBlock(s_getFuzzyMatchedCommands, isProductCode: true),
suggestionArgs: new object[] { CodeGeneration.EscapeSingleQuotedStringContent(SuggestionStrings.Suggestion_CommandNotFound) },
enabled: true));
matchType: SuggestionMatchType.Dynamic,
rule: ScriptBlock.CreateDelayParsedScriptBlock(s_checkForCommandInCurrentDirectoryScript, isProductCode: true),
suggestion: ScriptBlock.CreateDelayParsedScriptBlock(s_createCommandExistsInCurrentDirectoryScript, isProductCode: true),
suggestionArgs: new object[] { SuggestionStrings.Suggestion_CommandExistsInCurrentDirectory_Legacy },
enabled: true)
};
return suggestions;
}
@@ -123,6 +123,9 @@ PowerShell does not load commands from the current location by default (see 'Get
If you trust this command, run the following command instead:</value>
</data>
<data name="Suggestion_CommandExistsInCurrentDirectory_Legacy" xml:space="preserve">
<value>The command "{0}" was not found, but does exist in the current location. PowerShell does not load commands from the current location by default. If you trust this command, instead type: "{1}". See "get-help about_Command_Precedence" for more details.</value>
</data>
<data name="Suggestion_CommandNotFound" xml:space="preserve">
<value>The most similar commands are:</value>
</data>
@@ -636,7 +636,7 @@ namespace Microsoft.PowerShell.Telemetry
s_knownSubsystemNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"Completion",
"general",
"General Feedback",
"Windows Package Manager - WinGet",
"Az Predictor"
};
+2 -2
View File
@@ -97,7 +97,7 @@ namespace PSTests.Sequential
// Test the result from the 'general' feedback provider.
Assert.Single(feedbacks);
Assert.Equal("general", feedbacks[0].Name);
Assert.Equal("General Feedback", feedbacks[0].Name);
Assert.Equal(expectedCmd, feedbacks[0].Item.RecommendedActions[0]);
// Expect the result from both 'general' and the 'slow' feedback providers.
@@ -107,7 +107,7 @@ namespace PSTests.Sequential
Assert.Equal(2, feedbacks.Count);
FeedbackResult entry1 = feedbacks[0];
Assert.Equal("general", entry1.Name);
Assert.Equal("General Feedback", entry1.Name);
Assert.Equal(expectedCmd, entry1.Item.RecommendedActions[0]);
FeedbackResult entry2 = feedbacks[1];