Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ internal GeneralCommandErrorFeedback()

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.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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;
Expand Down Expand Up @@ -67,13 +66,6 @@ public static class HostUtilities
$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()
Expand All @@ -97,28 +89,17 @@ private static bool HostSupportUnicode()

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/utils/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ static ApplicationInsightsTelemetry()
s_knownSubsystemNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"Completion",
"general",
"General Feedback",
"Windows Package Manager - WinGet",
"Az Predictor"
};
Expand Down
4 changes: 2 additions & 2 deletions test/xUnit/csharp/test_Feedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static void GetFeedback()

// 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.
Expand All @@ -107,7 +107,7 @@ public static void GetFeedback()
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];
Expand Down
Loading