Exemplo n.º 1
0
        public LspHandlerDescriptorDisposable Add(params IJsonRpcHandler[] handlers)
        {
            var descriptors = new HashSet <HandlerDescriptor>();

            foreach (var handler in handlers)
            {
                foreach (var(method, implementedInterface) in handler.GetType().GetTypeInfo()
                         .ImplementedInterfaces
                         .Select(x => (method: LspHelper.GetMethodName(x), implementedInterface: x))
                         .Where(x => !string.IsNullOrWhiteSpace(x.method)))
                {
                    descriptors.Add(GetDescriptor(method, implementedInterface, handler));
                }
            }

            foreach (var descriptor in descriptors)
            {
                _handlers.Add(descriptor);
                if (descriptor.Handler is ITextDocumentIdentifier)
                {
                    _textDocumentIdentifiers.Add(descriptor);
                }
            }

            return(new LspHandlerDescriptorDisposable(descriptors));
        }
Exemplo n.º 2
0
        public override (IEnumerable <Renor> results, bool hasResponse) GetRequests(JToken container)
        {
            if (_initialized)
            {
                return(base.GetRequests(container));
            }

            var newResults = new List <Renor>();

            // Based on https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#initialize-request
            var(results, hasResponse) = base.GetRequests(container);
            foreach (var item in results)
            {
                if (item.IsRequest && item.Request.Method == LspHelper.GetMethodName <IInitializeHandler>())
                {
                    newResults.Add(item);
                }
                else if (item.IsRequest)
                {
                    newResults.Add(new ServerNotInitialized());
                }
                else if (item.IsResponse)
                {
                    newResults.Add(item);
                }
            }

            return(newResults, hasResponse);
        }
Exemplo n.º 3
0
        public LspHandlerDescriptorDisposable Add(IServiceProvider serviceProvider, params Type[] handlerTypes)
        {
            var descriptors = new HashSet <HandlerDescriptor>();

            foreach (var handlerType in handlerTypes)
            {
                foreach (var(method, implementedInterface) in handlerType.GetTypeInfo()
                         .ImplementedInterfaces
                         .Select(x => (method: LspHelper.GetMethodName(x), implementedInterface: x))
                         .Where(x => !string.IsNullOrWhiteSpace(x.method)))
                {
                    descriptors.Add(GetDescriptor(method, implementedInterface, serviceProvider));
                }
            }

            foreach (var descriptor in descriptors)
            {
                _handlers.Add(descriptor);
                if (typeof(ITextDocumentIdentifier).IsAssignableFrom(descriptor.ImplementationType))
                {
                    _textDocumentIdentifiers.Add(descriptor);
                }
            }

            return(new LspHandlerDescriptorDisposable(descriptors));
        }
Exemplo n.º 4
0
        public LspHandlerDescriptorDisposable Add(params Type[] handlerTypes)
        {
            var descriptors = new HashSet <HandlerDescriptor>();
            var cd          = new CompositeDisposable();

            foreach (var handlerType in handlerTypes)
            {
                foreach (var(method, implementedInterface) in handlerType.GetTypeInfo()
                         .ImplementedInterfaces
                         .Select(x => (method: LspHelper.GetMethodName(x), implementedInterface: x))
                         .Where(x => !string.IsNullOrWhiteSpace(x.method)))
                {
                    var descriptor = GetDescriptor(method, implementedInterface, _serviceProvider);
                    descriptors.Add(descriptor);
                    _handlers.Add(descriptor);
                    if (descriptor.Handler is ITextDocumentIdentifier textDocumentIdentifier)
                    {
                        cd.Add(_textDocumentIdentifiers.Add(textDocumentIdentifier));
                    }
                }
            }

            return(new LspHandlerDescriptorDisposable(descriptors, cd));
        }