// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.Extensions.Services
{
///
/// Service allowing the sending of notifications and requests to the PowerShell LSP language client from the server.
///
public interface ILanguageServerService
{
///
/// Send a parameterless notification.
///
/// The method to send.
void SendNotification(string method);
///
/// Send a notification with parameters.
///
/// The type of the parameter object.
/// The method to send.
/// The parameters to send.
void SendNotification(string method, T parameters);
///
/// Send a parameterless request with no response output.
///
/// The method to send.
/// A task that resolves when the request is acknowledged.
Task SendRequestAsync(string method);
///
/// Send a request with no response output.
///
/// The type of the request parameter object.
/// The method to send.
/// The request parameter object/body.
/// A task that resolves when the request is acknowledged.
Task SendRequestAsync(string method, T parameters);
///
/// Send a parameterless request and get its response.
///
/// The type of the response expected.
/// The method to send.
/// A task that resolves to the response sent by the server.
Task SendRequestAsync(string method);
///
/// Send a request and get its response.
///
/// The type of the parameter object.
/// The type of the response expected.
/// The method to send.
/// The parameters to send.
/// A task that resolves to the response sent by the server.
Task SendRequestAsync(string method, T parameters);
}
internal class LanguageServerService : ILanguageServerService
{
private readonly ILanguageServerFacade _languageServer;
internal LanguageServerService(ILanguageServerFacade languageServer) => _languageServer = languageServer;
public void SendNotification(string method) => _languageServer.SendNotification(method);
public void SendNotification(string method, T parameters) => _languageServer.SendNotification(method, parameters);
public void SendNotification(string method, object parameters) => _languageServer.SendNotification(method, parameters);
public Task SendRequestAsync(string method) => _languageServer.SendRequest(method).ReturningVoid(CancellationToken.None);
public Task SendRequestAsync(string method, T parameters) => _languageServer.SendRequest(method, parameters).ReturningVoid(CancellationToken.None);
public Task SendRequestAsync(string method) => _languageServer.SendRequest(method).Returning(CancellationToken.None);
public Task SendRequestAsync(string method, T parameters) => _languageServer.SendRequest(method, parameters).Returning(CancellationToken.None);
public Task