public LspHandlerDescriptorDisposable Add(params IJsonRpcHandler[] handlers)
        {
            var descriptors = new HashSet <LspHandlerDescriptor>();
            var cd          = new CompositeDisposable();

            foreach (var handler in handlers)
            {
                if (descriptors.Any(z => z.Handler == handler))
                {
                    continue;
                }

                foreach (var(method, implementedInterface) in handler.GetType().GetTypeInfo()
                         .ImplementedInterfaces
                         .Select(x => (method: HandlerTypeDescriptorHelper.GetMethodName(x), implementedInterface: x))
                         .Distinct(new EqualityComparer())
                         .Where(x => !string.IsNullOrWhiteSpace(x.method))
                         )
                {
                    var descriptor = GetDescriptor(method, implementedInterface, handler, null);
                    descriptors.Add(descriptor);
                    _handlers.Add(descriptor);
                    if (descriptor.Handler is ITextDocumentIdentifier textDocumentIdentifier)
                    {
                        cd.Add(_textDocumentIdentifiers.Add(textDocumentIdentifier));
                    }
                }
            }

            return(new LspHandlerDescriptorDisposable(descriptors, cd));
        }
Exemplo n.º 2
0
        public static ILspHandlerTypeDescriptor GetHandlerTypeDescriptor(Type type)
        {
            var @default = KnownHandlers.Values.FirstOrDefault(x => x.InterfaceType == type);

            if (@default != null)
            {
                return(@default);
            }

            var methodName = HandlerTypeDescriptorHelper.GetMethodName(type);

            if (string.IsNullOrWhiteSpace(methodName))
            {
                return(null);
            }
            return(GetHandlerTypeDescriptor(methodName));
        }
        public static ILspHandlerTypeDescriptor GetHandlerTypeDescriptor(Type type)
        {
            var @default = KnownHandlers
                           .SelectMany(g => g)
                           .FirstOrDefault(x => x.InterfaceType == type || x.HandlerType == type || x.ParamsType == type)
                           ?? KnownHandlers
                           .SelectMany(g => g)
                           .FirstOrDefault(x => x.InterfaceType.IsAssignableFrom(type) || x.HandlerType.IsAssignableFrom(type));

            if (@default != null)
            {
                return(@default);
            }

            var methodName = HandlerTypeDescriptorHelper.GetMethodName(type);

            return(string.IsNullOrWhiteSpace(methodName) ? null : KnownHandlers[methodName].FirstOrDefault());
        }
        public LspHandlerDescriptorDisposable Add(params Type[] handlerTypes)
        {
            var descriptors = new HashSet <LspHandlerDescriptor>();
            var cd          = new CompositeDisposable();

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

            return(new LspHandlerDescriptorDisposable(descriptors, cd));
        }
Exemplo n.º 5
0
 public static ILspHandlerTypeDescriptor GetHandlerTypeDescriptor <T>()
 {
     return(KnownHandlers.Values.FirstOrDefault(x => x.InterfaceType == typeof(T)) ??
            GetHandlerTypeDescriptor(HandlerTypeDescriptorHelper.GetMethodName(typeof(T))));
 }