Make features PSCommandNotFoundSuggestion, PSCommandWithArgs, and PSModuleAutoLoadSkipOfflineFiles stable (#24246)

This commit is contained in:
Steve Lee 2024-09-09 11:19:09 -07:00 committed by GitHub
parent c0aca665c4
commit ecb2ea6d44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 53 deletions

View File

@ -21,9 +21,7 @@ namespace System.Management.Automation
#region Const Members
internal const string EngineSource = "PSEngine";
internal const string PSModuleAutoLoadSkipOfflineFilesFeatureName = "PSModuleAutoLoadSkipOfflineFiles";
internal const string PSFeedbackProvider = "PSFeedbackProvider";
internal const string PSCommandWithArgs = "PSCommandWithArgs";
internal const string PSNativeWindowsTildeExpansion = nameof(PSNativeWindowsTildeExpansion);
internal const string PSRedirectToVariable = "PSRedirectToVariable";
@ -108,24 +106,15 @@ namespace System.Management.Automation
name: "PSFileSystemProviderV2",
description: "Replace the old FileSystemProvider with cleaner design and faster code"),
*/
new ExperimentalFeature(
name: "PSCommandNotFoundSuggestion",
description: "Recommend potential commands based on fuzzy search on a CommandNotFoundException"),
new ExperimentalFeature(
name: "PSSubsystemPluginModel",
description: "A plugin model for registering and un-registering PowerShell subsystems"),
new ExperimentalFeature(
name: "PSLoadAssemblyFromNativeCode",
description: "Expose an API to allow assembly loading from native code"),
new ExperimentalFeature(
name: PSModuleAutoLoadSkipOfflineFilesFeatureName,
description: "Module discovery will skip over files that are marked by cloud providers as not fully on disk."),
new ExperimentalFeature(
name: PSFeedbackProvider,
description: "Replace the hard-coded suggestion framework with the extensible feedback provider"),
new ExperimentalFeature(
name: PSCommandWithArgs,
description: "Enable `-CommandWithArgs` parameter for pwsh"),
new ExperimentalFeature(
name: PSNativeWindowsTildeExpansion,
description: "On windows, expand unquoted tilde (`~`) with the user's current home folder."),

View File

@ -39,18 +39,13 @@ namespace System.Management.Automation.Internal
static ModuleUtils()
{
if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSModuleAutoLoadSkipOfflineFilesFeatureName))
{
FileAttributesToSkip = FileAttributes.Hidden
// Skip OneDrive files/directories that are not fully on disk.
| FileAttributes.Offline
| (FileAttributes)FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS
| (FileAttributes)FILE_ATTRIBUTE_RECALL_ON_OPEN;
FileAttributesToSkip = FileAttributes.Hidden
// Skip OneDrive files/directories that are not fully on disk.
| FileAttributes.Offline
| (FileAttributes)FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS
| (FileAttributes)FILE_ATTRIBUTE_RECALL_ON_OPEN;
return;
}
FileAttributesToSkip = FileAttributes.Hidden;
return;
}
/// <summary>

View File

@ -276,26 +276,23 @@ namespace System.Management.Automation.Subsystem.Feedback
}
// Check fuzzy matching command names.
if (ExperimentalFeature.IsEnabled("PSCommandNotFoundSuggestion"))
{
var pwsh = PowerShell.Create(RunspaceMode.CurrentRunspace);
var results = pwsh.AddCommand("Get-Command")
.AddParameter("UseFuzzyMatching")
.AddParameter("FuzzyMinimumDistance", 1)
.AddParameter("Name", target)
.AddCommand("Select-Object")
.AddParameter("First", 5)
.AddParameter("Unique")
.AddParameter("ExpandProperty", "Name")
.Invoke<string>();
var pwsh = PowerShell.Create(RunspaceMode.CurrentRunspace);
var results = pwsh.AddCommand("Get-Command")
.AddParameter("UseFuzzyMatching")
.AddParameter("FuzzyMinimumDistance", 1)
.AddParameter("Name", target)
.AddCommand("Select-Object")
.AddParameter("First", 5)
.AddParameter("Unique")
.AddParameter("ExpandProperty", "Name")
.Invoke<string>();
if (results.Count > 0)
{
return new FeedbackItem(
SuggestionStrings.Suggestion_CommandNotFound,
new List<string>(results),
FeedbackDisplayLayout.Landscape);
}
if (results.Count > 0)
{
return new FeedbackItem(
SuggestionStrings.Suggestion_CommandNotFound,
new List<string>(results),
FeedbackDisplayLayout.Landscape);
}
return null;

View File

@ -110,18 +110,15 @@ namespace System.Management.Automation
enabled: true)
});
if (ExperimentalFeature.IsEnabled("PSCommandNotFoundSuggestion"))
{
suggestions.Add(
NewSuggestion(
id: 4,
category: "General",
matchType: SuggestionMatchType.ErrorId,
rule: "CommandNotFoundException",
suggestion: ScriptBlock.CreateDelayParsedScriptBlock(s_getFuzzyMatchedCommands, isProductCode: true),
suggestionArgs: new object[] { CodeGeneration.EscapeSingleQuotedStringContent(SuggestionStrings.Suggestion_CommandNotFound) },
enabled: true));
}
suggestions.Add(
NewSuggestion(
id: 4,
category: "General",
matchType: SuggestionMatchType.ErrorId,
rule: "CommandNotFoundException",
suggestion: ScriptBlock.CreateDelayParsedScriptBlock(s_getFuzzyMatchedCommands, isProductCode: true),
suggestionArgs: new object[] { CodeGeneration.EscapeSingleQuotedStringContent(SuggestionStrings.Suggestion_CommandNotFound) },
enabled: true));
return suggestions;
}