Files

233 lines
8.8 KiB
C#

#if LEGACY
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Management.Automation.Language;
namespace System.Management.Automation.Subsystem.Prediction
{
/// <summary>
/// Kinds of prediction clients.
/// </summary>
public enum PredictionClientKind
{
/// <summary>
/// A terminal client, representing the command-line experience.
/// </summary>
Terminal,
/// <summary>
/// An editor client, representing the editor experience.
/// </summary>
Editor,
}
/// <summary>
/// The class represents a client that interacts with predictors.
/// </summary>
public sealed class PredictionClient
{
/// <summary>
/// Gets the client name.
/// </summary>
[HiddenAttribute]
public string Name { get; }
/// <summary>
/// Gets the client kind.
/// </summary>
[HiddenAttribute]
public PredictionClientKind Kind { get; }
/// <summary>
/// Initializes a new instance of the <see cref="PredictionClient"/> class.
/// </summary>
/// <param name="name">Name of the interactive client.</param>
/// <param name="kind">Kind of the interactive client.</param>
[HiddenAttribute]
public PredictionClient(string name, PredictionClientKind kind)
{
Name = name;
Kind = kind;
}
}
/// <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 mini-session id that represents a specific invocation that returns this result.
/// When it's not specified, it's considered by a client that the predictor doesn't expect feedback.
/// </summary>
[HiddenAttribute]
public uint? Session { get; }
/// <summary>
/// Gets the suggestions.
/// </summary>
[HiddenAttribute]
public IReadOnlyList<PredictiveSuggestion> Suggestions { get; }
internal PredictionResult(Guid id, string name, uint? session, List<PredictiveSuggestion> suggestions)
{
Id = id;
Name = name;
Session = session;
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="client">Represents the client that initiates the call.</param>
/// <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>> PredictInputAsync(PredictionClient client, Ast ast, Token[] astTokens)
{
return null;
}
/// <summary>
/// Collect the predictive suggestions from registered predictors using the specified timeout.
/// </summary>
/// <param name="client">Represents the client that initiates the call.</param>
/// <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>> PredictInputAsync(PredictionClient client, 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="client">Represents the client that initiates the call.</param>
/// <param name="history">History command lines provided as references for prediction.</param>
[HiddenAttribute]
public static void OnCommandLineAccepted(PredictionClient client, IReadOnlyList<string> history)
{
}
/// <summary>
/// Allow registered predictors to know the execution result (success/failure) of the last accepted command line.
/// </summary>
/// <param name="client">Represents the client that initiates the call.</param>
/// <param name="commandLine">The last accepted command line.</param>
/// <param name="success">Whether the execution of the last command line was successful.</param>
[HiddenAttribute]
public static void OnCommandLineExecuted(PredictionClient client, string commandLine, bool success)
{
}
/// <summary>
/// Send feedback to a predictor when one or more suggestions from it were displayed to the user.
/// </summary>
/// <param name="client">Represents the client that initiates the call.</param>
/// <param name="predictorId">The identifier of the predictor whose prediction result was accepted.</param>
/// <param name="session">The mini-session where the displayed suggestions came from.</param>
/// <param name="countOrIndex">
/// When the value is <code>> 0</code>, it's the number of displayed suggestions from the list returned in <see cref="session"/>, starting from the index 0.
/// When the value is <code><= 0</code>, it means a single suggestion from the list got displayed, and the index is the absolute value.
/// </param>
[HiddenAttribute]
public static void OnSuggestionDisplayed(PredictionClient client, Guid predictorId, uint session, int countOrIndex)
{
}
/// <summary>
/// Send feedback to predictors about their last suggestions.
/// </summary>
/// <param name="client">Represents the client that initiates the call.</param>
/// <param name="predictorId">The identifier of the predictor whose prediction result was accepted.</param>
/// <param name="session">The mini-session where the accepted suggestion came from.</param>
/// <param name="suggestionText">The accepted suggestion text.</param>
[HiddenAttribute]
public static void OnSuggestionAccepted(PredictionClient client, Guid predictorId, uint session, string suggestionText)
{
}
}
}
#else
using System.Management.Automation.Subsystem.Prediction;
using System.Runtime.CompilerServices;
[assembly: TypeForwardedTo(typeof(PredictionClientKind))]
[assembly: TypeForwardedTo(typeof(PredictionClient))]
[assembly: TypeForwardedTo(typeof(PredictiveSuggestion))]
[assembly: TypeForwardedTo(typeof(PredictionResult))]
[assembly: TypeForwardedTo(typeof(CommandPrediction))]
#endif