예제 #1
0
 private InputHandler NewHandler(
     PipeReader inputStream,
     IOutputHandler outputHandler,
     IReceiver receiver,
     IRequestProcessIdentifier requestProcessIdentifier,
     IRequestRouter <IHandlerDescriptor?> requestRouter,
     ILoggerFactory loggerFactory,
     IResponseRouter responseRouter,
     IScheduler?scheduler = null
     ) =>
 new InputHandler(
     inputStream,
     outputHandler,
     receiver,
     requestProcessIdentifier,
     requestRouter,
     responseRouter,
     loggerFactory,
     _unhandledException,
     null,
     TimeSpan.FromSeconds(30),
     true,
     null,
     scheduler ?? TaskPoolScheduler.Default
     );
예제 #2
0
        private static InputHandler NewHandler(
            Stream inputStream,
            IOutputHandler outputHandler,
            IReceiver receiver,
            IRequestProcessIdentifier requestProcessIdentifier,
            IRequestRouter <IHandlerDescriptor> requestRouter,
            IResponseRouter responseRouter,
            Action <CancellationTokenSource> action)
        {
            var cts = new CancellationTokenSource();

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                cts.CancelAfter(TimeSpan.FromSeconds(5));
            }
            action(cts);

            var handler = new InputHandler(
                inputStream,
                outputHandler,
                receiver,
                requestProcessIdentifier,
                requestRouter,
                responseRouter,
                Substitute.For <ILoggerFactory>(),
                new DapSerializer(),
                null);

            handler.Start();
            cts.Wait();
            Task.Delay(10).Wait();
            return(handler);
        }
예제 #3
0
 public InputHandler(
     Stream input,
     IOutputHandler outputHandler,
     IReceiver receiver,
     IRequestProcessIdentifier requestProcessIdentifier,
     IRequestRouter <IHandlerDescriptor> requestRouter,
     IResponseRouter responseRouter,
     ILoggerFactory loggerFactory,
     ISerializer serializer
     )
 {
     if (!input.CanRead)
     {
         throw new ArgumentException($"must provide a readable stream for {nameof(input)}", nameof(input));
     }
     _input                    = input;
     _outputHandler            = outputHandler;
     _receiver                 = receiver;
     _requestProcessIdentifier = requestProcessIdentifier;
     _requestRouter            = requestRouter;
     _responseRouter           = responseRouter;
     _serializer               = serializer;
     _logger                   = loggerFactory.CreateLogger <InputHandler>();
     _scheduler                = new ProcessScheduler(loggerFactory);
     _inputThread              = new Thread(ProcessInputStream)
     {
         IsBackground = true, Name = "ProcessInputStream"
     };
 }
 public Connection(
     PipeReader input,
     IOutputHandler outputHandler,
     IReceiver receiver,
     IRequestProcessIdentifier requestProcessIdentifier,
     IRequestRouter <IHandlerDescriptor> requestRouter,
     IResponseRouter responseRouter,
     ILoggerFactory loggerFactory,
     Action <Exception> onUnhandledException,
     Func <ServerError, string, Exception> getException,
     TimeSpan requestTimeout,
     bool supportContentModified,
     int?concurrency)
 {
     _inputHandler = new InputHandler(
         input,
         outputHandler,
         receiver,
         requestProcessIdentifier,
         requestRouter,
         responseRouter,
         loggerFactory,
         onUnhandledException,
         getException,
         requestTimeout,
         supportContentModified,
         concurrency
         );
 }
 public Connection(
     PipeReader input,
     IOutputHandler outputHandler,
     IReceiver receiver,
     IRequestProcessIdentifier requestProcessIdentifier,
     IRequestRouter <IHandlerDescriptor?> requestRouter,
     IResponseRouter responseRouter,
     ILoggerFactory loggerFactory,
     OnUnhandledExceptionHandler onUnhandledException,
     TimeSpan requestTimeout,
     bool supportContentModified,
     int concurrency,
     IScheduler scheduler,
     CreateResponseExceptionHandler?getException = null
     ) : this(
         input,
         outputHandler,
         receiver,
         requestRouter,
         responseRouter,
         new DefaultRequestInvoker(
             requestRouter,
             outputHandler,
             requestProcessIdentifier,
             new RequestInvokerOptions(
                 requestTimeout,
                 supportContentModified,
                 concurrency),
             loggerFactory,
             scheduler),
         loggerFactory,
         onUnhandledException,
         getException)
 {
 }
예제 #6
0
 internal LanguageServer(
     Stream input,
     Stream output,
     ILspReciever reciever,
     IRequestProcessIdentifier requestProcessIdentifier,
     ISerializer serializer,
     IServiceCollection services,
     IEnumerable <Assembly> assemblies,
     IEnumerable <IJsonRpcHandler> handlers,
     IEnumerable <Type> handlerTypes,
     IEnumerable <(string name, IJsonRpcHandler handler)> namedHandlers,
예제 #7
0
 public RazorOmniSharpRequestInvoker(
     RequestInvokerOptions options,
     IOutputHandler outputHandler,
     IRequestRouter <IHandlerDescriptor?> requestRouter,
     IRequestProcessIdentifier requestProcessIdentifier,
     ILoggerFactory loggerFactory)
 {
     _requestTimeout           = options.RequestTimeout;
     _outputHandler            = outputHandler;
     _requestRouter            = requestRouter;
     _requestProcessIdentifier = requestProcessIdentifier;
     _requestScheduler         = new JsonRpcRequestScheduler(loggerFactory);
     _logger = loggerFactory.CreateLogger <RazorOmniSharpRequestInvoker>();
 }
예제 #8
0
 public Connection(
     PipeReader input,
     IOutputHandler outputHandler,
     IReceiver receiver,
     IRequestProcessIdentifier requestProcessIdentifier,
     IRequestRouter <IHandlerDescriptor> requestRouter,
     IResponseRouter responseRouter,
     ILoggerFactory loggerFactory,
     OnUnhandledExceptionHandler onUnhandledException,
     TimeSpan requestTimeout,
     bool supportContentModified,
     int concurrency,
     CreateResponseExceptionHandler getException = null
     ) =>
 public DefaultRequestInvoker(
     IRequestRouter <IHandlerDescriptor?> requestRouter,
     IOutputHandler outputHandler,
     IRequestProcessIdentifier requestProcessIdentifier,
     RequestInvokerOptions options,
     ILoggerFactory loggerFactory,
     IScheduler scheduler)
 {
     _requestRouter            = requestRouter;
     _outputHandler            = outputHandler;
     _requestProcessIdentifier = requestProcessIdentifier;
     _options          = options;
     _processScheduler = new ProcessScheduler(loggerFactory, _options.SupportContentModified, _options.Concurrency, scheduler);
     _logger           = loggerFactory.CreateLogger <DefaultRequestInvoker>();
 }
        public Connection(
            Stream input,
            IOutputHandler outputHandler,
            IReciever reciever,
            IRequestProcessIdentifier requestProcessIdentifier,
            IRequestRouter requestRouter,
            IResponseRouter responseRouter,
            ILoggerFactory loggerFactory)
        {
            _requestRouter = requestRouter;

            _inputHandler = new InputHandler(
                input,
                outputHandler,
                reciever,
                requestProcessIdentifier,
                requestRouter,
                responseRouter,
                loggerFactory
                );
        }
        public Connection(
            Stream input,
            IOutputHandler outputHandler,
            IReceiver receiver,
            IRequestProcessIdentifier requestProcessIdentifier,
            IRequestRouter <IHandlerDescriptor> requestRouter,
            IResponseRouter responseRouter,
            ILoggerFactory loggerFactory,
            ISerializer serializer)
        {
            _requestRouter = requestRouter;

            _inputHandler = new InputHandler(
                input,
                outputHandler,
                receiver,
                requestProcessIdentifier,
                requestRouter,
                responseRouter,
                loggerFactory,
                serializer
                );
        }
예제 #12
0
        internal LanguageServer(
            Stream input,
            Stream output,
            LspReciever reciever,
            IRequestProcessIdentifier requestProcessIdentifier,
            ILoggerFactory loggerFactory,
            Serializer serializer,
            bool addDefaultLoggingProvider)
        {
            var outputHandler = new OutputHandler(output, serializer);

            if (addDefaultLoggingProvider)
            {
                loggerFactory.AddProvider(new LanguageServerLoggerProvider(this));
            }

            _reciever                 = reciever;
            _loggerFactory            = loggerFactory;
            _serializer               = serializer;
            _handlerMactherCollection = new HandlerMatcherCollection
            {
                new TextDocumentMatcher(_loggerFactory.CreateLogger <TextDocumentMatcher>(), _collection.TextDocumentSyncHandlers),
                new ExecuteCommandMatcher(_loggerFactory.CreateLogger <ExecuteCommandMatcher>()),
                new ResolveCommandMatcher(_loggerFactory.CreateLogger <ResolveCommandMatcher>()),
                new DocumentLinkCommandMatcher(_loggerFactory.CreateLogger <DocumentLinkCommandMatcher>())
            };

            _requestRouter  = new LspRequestRouter(_collection, loggerFactory, _handlerMactherCollection, _serializer);
            _responseRouter = new ResponseRouter(outputHandler, _serializer);
            _connection     = new Connection(input, outputHandler, reciever, requestProcessIdentifier, _requestRouter, _responseRouter, loggerFactory, serializer);

            _exitHandler = new ExitHandler(_shutdownHandler);

            _disposable.Add(
                AddHandlers(this, _shutdownHandler, _exitHandler, new CancelRequestHandler(_requestRouter))
                );
        }
예제 #13
0
 private InputHandler NewHandler(
     PipeReader inputStream,
     IOutputHandler outputHandler,
     IReceiver receiver,
     IRequestProcessIdentifier requestProcessIdentifier,
     IRequestRouter <IHandlerDescriptor> requestRouter,
     ILoggerFactory loggerFactory,
     IResponseRouter responseRouter)
 {
     return(new InputHandler(
                inputStream,
                outputHandler,
                receiver,
                requestProcessIdentifier,
                requestRouter,
                responseRouter,
                loggerFactory,
                _unhandledException,
                null,
                TimeSpan.FromSeconds(30),
                true,
                null
                ));
 }
예제 #14
0
 public T WithRequestProcessIdentifier(IRequestProcessIdentifier requestProcessIdentifier)
 {
     RequestProcessIdentifier = requestProcessIdentifier;
     return((T)(object)this);
 }
        internal LanguageServer(Stream input, IOutputHandler output, LspReciever reciever, IRequestProcessIdentifier requestProcessIdentifier, ILoggerFactory loggerFactory)
        {
            // TODO: This might not be the best
            loggerFactory.AddProvider(new LanguageServerLoggerProvider(this));

            _reciever                 = reciever;
            _loggerFactory            = loggerFactory;
            _handlerMactherCollection = new HandlerMatcherCollection
            {
                new TextDocumentMatcher(_loggerFactory.CreateLogger <TextDocumentMatcher>()),
                new ExecuteCommandMatcher(_loggerFactory.CreateLogger <ExecuteCommandMatcher>())
            };

            _requestRouter  = new LspRequestRouter(_collection, loggerFactory, _handlerMactherCollection);
            _responseRouter = new ResponseRouter(output);
            _connection     = new Connection(input, output, reciever, requestProcessIdentifier, _requestRouter, _responseRouter, loggerFactory);

            _exitHandler = new ExitHandler(_shutdownHandler);

            _disposable.Add(
                AddHandlers(this, _shutdownHandler, _exitHandler, new CancelRequestHandler(_requestRouter))
                );
        }
 public static DebugAdapterClientOptions WithRequestProcessIdentifier(this DebugAdapterClientOptions options, IRequestProcessIdentifier requestProcessIdentifier)
 {
     options.RequestProcessIdentifier = requestProcessIdentifier;
     return(options);
 }
예제 #17
0
        internal JsonRpcServer(
            Stream input,
            Stream output,
            IReciever reciever,
            IRequestProcessIdentifier requestProcessIdentifier,
            ILoggerFactory loggerFactory,
            ISerializer serializer,
            IServiceCollection services,
            IEnumerable <Assembly> assemblies)
        {
            var outputHandler = new OutputHandler(output, serializer);

            services.AddLogging();
            _reciever   = reciever;
            _serializer = serializer;
            _collection = new HandlerCollection();

            services.AddSingleton <IOutputHandler>(outputHandler);
            services.AddSingleton(_collection);
            services.AddSingleton(_serializer);
            services.AddSingleton <OmniSharp.Extensions.JsonRpc.ISerializer>(_serializer);
            services.AddSingleton(requestProcessIdentifier);
            services.AddSingleton(_reciever);
            services.AddSingleton(loggerFactory);

            services.AddJsonRpcMediatR(assemblies);
            services.AddSingleton <IJsonRpcServer>(this);
            services.AddSingleton <IRequestRouter, RequestRouter>();
            services.AddSingleton <IReciever, Reciever>();
            services.AddSingleton <IResponseRouter, ResponseRouter>();

            var foundHandlers = services
                                .Where(x => typeof(IJsonRpcHandler).IsAssignableFrom(x.ServiceType) && x.ServiceType != typeof(IJsonRpcHandler))
                                .ToArray();

            // Handlers are created at the start and maintained as a singleton
            foreach (var handler in foundHandlers)
            {
                services.Remove(handler);

                if (handler.ImplementationFactory != null)
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationFactory));
                }
                else if (handler.ImplementationInstance != null)
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationInstance));
                }
                else
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationType));
                }
            }

            _serviceProvider = services.BuildServiceProvider();

            var handlers = _serviceProvider.GetServices <IJsonRpcHandler>().ToArray();

            _collection.Add(handlers);

            _requestRouter  = _serviceProvider.GetRequiredService <IRequestRouter>();
            _responseRouter = _serviceProvider.GetRequiredService <IResponseRouter>();
            _connection     = ActivatorUtilities.CreateInstance <Connection>(_serviceProvider, input);
        }
예제 #18
0
        internal LanguageServer(
            Stream input,
            Stream output,
            ILspReciever reciever,
            IRequestProcessIdentifier requestProcessIdentifier,
            ILoggerFactory loggerFactory,
            ISerializer serializer,
            IServiceCollection services,
            IEnumerable <Assembly> assemblies,
            IEnumerable <InitializeDelegate> initializeDelegates,
            IEnumerable <InitializedDelegate> initializedDelegates)
        {
            var outputHandler = new OutputHandler(output, serializer);

            services.AddLogging();
            _reciever              = reciever;
            _serializer            = serializer;
            _supportedCapabilities = new SupportedCapabilities();
            _collection            = new HandlerCollection(_supportedCapabilities);
            _initializeDelegates   = initializeDelegates;
            _initializedDelegates  = initializedDelegates;

            services.AddSingleton <IOutputHandler>(outputHandler);
            services.AddSingleton(_collection);
            services.AddSingleton(_serializer);
            services.AddSingleton <OmniSharp.Extensions.JsonRpc.ISerializer>(_serializer);
            services.AddSingleton(requestProcessIdentifier);
            services.AddSingleton <OmniSharp.Extensions.JsonRpc.IReciever>(reciever);
            services.AddSingleton <ILspReciever>(reciever);
            services.AddSingleton(loggerFactory);

            services.AddJsonRpcMediatR(assemblies);
            services.AddTransient <IHandlerMatcher, TextDocumentMatcher>();
            services.AddSingleton <Protocol.Server.ILanguageServer>(this);
            services.AddSingleton <ILanguageServer>(this);
            services.AddTransient <IHandlerMatcher, ExecuteCommandMatcher>();
            services.AddTransient <IHandlerMatcher, ResolveCommandMatcher>();
            services.AddSingleton <ILspRequestRouter, LspRequestRouter>();
            services.AddSingleton <IRequestRouter>(_ => _.GetRequiredService <ILspRequestRouter>());
            services.AddSingleton <IResponseRouter, ResponseRouter>();
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ResolveCommandPipeline <,>));

            var foundHandlers = services
                                .Where(x => typeof(IJsonRpcHandler).IsAssignableFrom(x.ServiceType) && x.ServiceType != typeof(IJsonRpcHandler))
                                .ToArray();

            // Handlers are created at the start and maintained as a singleton
            foreach (var handler in foundHandlers)
            {
                services.Remove(handler);

                if (handler.ImplementationFactory != null)
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationFactory));
                }
                else if (handler.ImplementationInstance != null)
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationInstance));
                }
                else
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationType));
                }
            }

            _serviceProvider = services.BuildServiceProvider();

            _requestRouter  = _serviceProvider.GetRequiredService <ILspRequestRouter>();
            _responseRouter = _serviceProvider.GetRequiredService <IResponseRouter>();
            _connection     = ActivatorUtilities.CreateInstance <Connection>(_serviceProvider, input);

            _exitHandler = new ExitHandler(_shutdownHandler);

            _disposable.Add(
                AddHandlers(this, _shutdownHandler, _exitHandler, new CancelRequestHandler(_requestRouter))
                );

            var handlers = _serviceProvider.GetServices <IJsonRpcHandler>().ToArray();

            _collection.Add(handlers);

            Document  = new LanguageServerDocument(_responseRouter);
            Client    = new LanguageServerClient(_responseRouter);
            Window    = new LanguageServerWindow(_responseRouter);
            Workspace = new LanguageServerWorkspace(_responseRouter);
        }
예제 #19
0
 public static JsonRpcServerOptions WithRequestProcessIdentifier(this JsonRpcServerOptions options, IRequestProcessIdentifier requestProcessIdentifier)
 {
     options.RequestProcessIdentifier = requestProcessIdentifier;
     return(options);
 }
예제 #20
0
 public static LanguageServerOptions WithRequestProcessIdentifier(this LanguageServerOptions options, IRequestProcessIdentifier requestProcessIdentifier)
 {
     options.RequestProcessIdentifier = requestProcessIdentifier;
     return(options);
 }