public LanguageClient Get(string name) { if (_clients.TryGetValue(name, out var client)) { return(client); } var options = name == Options.DefaultName ? _monitor.CurrentValue : _monitor.Get(name); var container = LanguageClient.CreateContainer(options, _outerServiceProvider); client = container.Resolve <LanguageClient>(); _clients.TryAdd(name, client); return(client); }
/// <summary> /// Register a handler for empty notifications. /// </summary> /// <param name="languageClient"> /// The <see cref="LanguageClient"/>. /// </param> /// <param name="method"> /// The name of the notification method to handle. /// </param> /// <param name="handler"> /// A JSON-RPC <see cref="IJsonRpcNotificationHandler"/> that implements the handler. /// </param> /// <returns> /// An <see cref="IDisposable"/> representing the registration. /// </returns> public static IDisposable HandleNotification(this LanguageClient languageClient, string method, IJsonRpcNotificationHandler handler) { if (languageClient == null) { throw new ArgumentNullException(nameof(languageClient)); } if (string.IsNullOrWhiteSpace(method)) { throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } return(languageClient.RegisterHandler( new JsonRpcEmptyNotificationHandler(method, handler) )); }
/// <summary> /// Register a handler for requests. /// </summary> /// <typeparam name="TRequest"> /// The request message type. /// </typeparam> /// <typeparam name="TResponse"> /// The response message type. /// </typeparam> /// <param name="languageClient"> /// The <see cref="LanguageClient"/>. /// </param> /// <param name="method"> /// The name of the request method to handle. /// </param> /// <param name="handler"> /// A <see cref="RequestHandler{TRequest}"/> delegate that implements the handler. /// </param> /// <returns> /// An <see cref="IDisposable"/> representing the registration. /// </returns> public static IDisposable HandleRequest <TRequest, TResponse>(this LanguageClient languageClient, string method, RequestHandler <TRequest, TResponse> handler) { if (languageClient == null) { throw new ArgumentNullException(nameof(languageClient)); } if (string.IsNullOrWhiteSpace(method)) { throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } return(languageClient.RegisterHandler( new DelegateRequestResponseHandler <TRequest, TResponse>(method, handler) )); }