Files
PowerShell-PSReadLine/Polyfill/CommandPrediction.cs
T

146 lines
5.0 KiB
C#

#if LEGACY
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Management.Automation.Language;
namespace System.Management.Automation.Subsystem
{
/// <summary>
/// The class represents the prediction result from a predictor.
/// </summary>
public sealed class PredictionResult
{
/// <summary>
/// Gets the Id of the predictor.
/// </summary>
[HiddenAttribute]
public Guid Id { get; }
/// <summary>
/// Gets the name of the predictor.
/// </summary>
[HiddenAttribute]
public string Name { get; }
/// <summary>
/// Gets the suggestions.
/// </summary>
[HiddenAttribute]
public IReadOnlyList<PredictiveSuggestion> Suggestions { get; }
internal PredictionResult(Guid id, string name, List<PredictiveSuggestion> suggestions)
{
Id = id;
Name = name;
Suggestions = suggestions;
}
}
/// <summary>
/// The class represents a predictive suggestion generated by a predictor.
/// </summary>
public sealed class PredictiveSuggestion
{
/// <summary>
/// Gets the suggestion.
/// </summary>
[HiddenAttribute]
public string SuggestionText { get; }
/// <summary>
/// Gets the tooltip of the suggestion.
/// </summary>
[HiddenAttribute]
public string ToolTip { get; }
/// <summary>
/// Initializes a new instance of the <see cref="PredictiveSuggestion"/> class.
/// </summary>
/// <param name="suggestion">The predictive suggestion text.</param>
[HiddenAttribute]
public PredictiveSuggestion(string suggestion)
: this(suggestion, toolTip: null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="PredictiveSuggestion"/> class.
/// </summary>
/// <param name="suggestion">The predictive suggestion text.</param>
/// <param name="toolTip">The tooltip of the suggestion.</param>
[HiddenAttribute]
public PredictiveSuggestion(string suggestion, string toolTip)
{
if (string.IsNullOrEmpty(suggestion))
{
throw new ArgumentNullException(nameof(suggestion));
}
SuggestionText = suggestion;
ToolTip = toolTip;
}
}
/// <summary>
/// Provides a set of possible predictions for given input.
/// </summary>
public static class CommandPrediction
{
/// <summary>
/// Collect the predictive suggestions from registered predictors using the default timeout.
/// </summary>
/// <param name="ast">The <see cref="Ast"/> object from parsing the current command line input.</param>
/// <param name="astTokens">The <see cref="Token"/> objects from parsing the current command line input.</param>
/// <returns>A list of <see cref="PredictionResult"/> objects.</returns>
[HiddenAttribute]
public static Task<List<PredictionResult>> PredictInput(Ast ast, Token[] astTokens)
{
return null;
}
/// <summary>
/// Collect the predictive suggestions from registered predictors using the specified timeout.
/// </summary>
/// <param name="ast">The <see cref="Ast"/> object from parsing the current command line input.</param>
/// <param name="astTokens">The <see cref="Token"/> objects from parsing the current command line input.</param>
/// <param name="millisecondsTimeout">The milliseconds to timeout.</param>
/// <returns>A list of <see cref="PredictionResult"/> objects.</returns>
[HiddenAttribute]
public static Task<List<PredictionResult>> PredictInput(Ast ast, Token[] astTokens, int millisecondsTimeout)
{
return null;
}
/// <summary>
/// Allow registered predictors to do early processing when a command line is accepted.
/// </summary>
/// <param name="history">History command lines provided as references for prediction.</param>
[HiddenAttribute]
public static void OnCommandLineAccepted(IReadOnlyList<string> history)
{
}
/// <summary>
/// Send feedback to predictors about their last suggestions.
/// </summary>
/// <param name="predictorId">The identifier of the predictor whose prediction result was accepted.</param>
/// <param name="suggestionText">The accepted suggestion text.</param>
[HiddenAttribute]
public static void OnSuggestionAccepted(Guid predictorId, string suggestionText)
{
}
}
}
#else
using System.Management.Automation.Subsystem;
using System.Runtime.CompilerServices;
[assembly: TypeForwardedTo(typeof(PredictiveSuggestion))]
[assembly: TypeForwardedTo(typeof(PredictionResult))]
[assembly: TypeForwardedTo(typeof(CommandPrediction))]
#endif