Example #1
0
        /// <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="INotificationHandler"/> that implements the handler.
        /// </param>
        /// <returns>
        ///     An <see cref="IDisposable"/> representing the registration.
        /// </returns>
        public static IDisposable HandleNotification(this LanguageClient languageClient, string method, INotificationHandler 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)
                       ));
        }
Example #2
0
        /// <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)
                       ));
        }