public LspHandlerTypeDescriptor(Type handlerType) : base(handlerType) { PartialItemsType = ParamsType.GetInterfaces().FirstOrDefault(z => z.IsGenericType && typeof(IPartialItems <>).IsAssignableFrom(z.GetGenericTypeDefinition())) ?.GetGenericArguments()[0]; HasPartialItems = PartialItemsType != null; PartialItemType = ParamsType.GetInterfaces().FirstOrDefault(z => z.IsGenericType && typeof(IPartialItem <>).IsAssignableFrom(z.GetGenericTypeDefinition())) ?.GetGenericArguments()[0]; HasPartialItem = PartialItemType != null; RegistrationType = HandlerTypeDescriptorHelper.UnwrapGenericType(typeof(IRegistration <>), handlerType); HasRegistration = RegistrationType != null && RegistrationType != typeof(object); if (!HasRegistration) { RegistrationType = null; } CapabilityType = HandlerTypeDescriptorHelper.UnwrapGenericType(typeof(ICapability <>), handlerType); HasCapability = CapabilityType != null; if (!HasCapability) { CapabilityType = null; } if (HasCapability) { IsDynamicCapability = typeof(IDynamicCapability).GetTypeInfo().IsAssignableFrom(CapabilityType); } }
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)); }
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 && HandlerTypeDescriptorHelper.IsMethodName(item.Request.Method, typeof(IShowMessageRequestHandler))) { newResults.Add(item); } else if (item.IsResponse) { newResults.Add(item); } else if (item.IsNotification && HandlerTypeDescriptorHelper.IsMethodName(item.Notification.Method, typeof(IShowMessageHandler), typeof(ILogMessageHandler), typeof(ITelemetryEventHandler)) ) { newResults.Add(item); } } return(newResults, hasResponse); }
public TypeHandlerData() { foreach (var type in typeof(CompletionsArguments).Assembly.ExportedTypes.Where( z => z.IsInterface && typeof(IJsonRpcHandler).IsAssignableFrom(z) && !z.IsGenericType)) { Add(HandlerTypeDescriptorHelper.GetHandlerTypeDescriptor(type)); } }
public void HandlersShouldMatchParamsMethodAttribute(Type type) { var paramsType = HandlerTypeDescriptorHelper.GetHandlerInterface(type).GetGenericArguments()[0]; var lhs = MethodAttribute.From(type) !; var rhs = MethodAttribute.From(paramsType) !; lhs.Method.Should().Be(rhs.Method, $"{type.FullName} method does not match {paramsType.FullName}"); lhs.Direction.Should().Be(rhs.Direction, $"{type.FullName} direction does not match {paramsType.FullName}"); }
public void HandlersShouldMatchParamsMethodAttribute(Type type) { if (typeof(IJsonRpcNotificationHandler).IsAssignableFrom(type)) { return; } var paramsType = HandlerTypeDescriptorHelper.GetHandlerInterface(type).GetGenericArguments()[0]; var lhs = type.GetCustomAttribute <MethodAttribute>(true); var rhs = paramsType.GetCustomAttribute <MethodAttribute>(true); lhs.Method.Should().Be(rhs.Method, $"{type.FullName} method does not match {paramsType.FullName}"); lhs.Direction.Should().Be(rhs.Direction, $"{type.FullName} direction does not match {paramsType.FullName}"); }
public TypeHandlerExtensionData() { foreach (var type in typeof(CompletionsArguments).Assembly.ExportedTypes .Where(z => z.IsInterface && typeof(IJsonRpcHandler).IsAssignableFrom(z) && !z.IsGenericType)) { var descriptor = HandlerTypeDescriptorHelper.GetHandlerTypeDescriptor(type); Add( descriptor, GetOnMethodName(descriptor), GetSendMethodName(descriptor), GetExtensionClass(descriptor), GetExtensionClassName(descriptor).Substring(GetExtensionClassName(descriptor).LastIndexOf('.') + 1) ); } }
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 TypeHandlerData() { foreach (var type in typeof(CompletionsArguments).Assembly.ExportedTypes.Where( z => z.IsInterface && typeof(IJsonRpcHandler).IsAssignableFrom(z) )) { if (type.IsGenericTypeDefinition && !MethodAttribute.AllFrom(type).Any()) { continue; } if (type == typeof(IProgressStartHandler) || type == typeof(IProgressUpdateHandler) || type == typeof(IProgressEndHandler)) { continue; } Add(HandlerTypeDescriptorHelper.GetHandlerTypeDescriptor(type)); } }
public TypeHandlerExtensionData() { foreach (var type in typeof(CompletionsArguments).Assembly.ExportedTypes .Where(z => z.IsInterface && typeof(IJsonRpcHandler).IsAssignableFrom(z))) { if (type.IsGenericTypeDefinition && !MethodAttribute.AllFrom(type).Any()) { continue; } if (type == typeof(IProgressStartHandler) || type == typeof(IProgressUpdateHandler) || type == typeof(IProgressEndHandler)) { continue; } var descriptor = HandlerTypeDescriptorHelper.GetHandlerTypeDescriptor(type); Add( descriptor, GetOnMethodName(descriptor), GetSendMethodName(descriptor), GetExtensionClass(descriptor), GetExtensionClassName(descriptor).Substring(GetExtensionClassName(descriptor).LastIndexOf('.') + 1) ); } }
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)); }
public RequestProcessType Identify(IHandlerDescriptor descriptor) { if (descriptor.RequestProcessType.HasValue) { return(descriptor.RequestProcessType.Value); } if (_cache.TryGetValue(descriptor.HandlerType, out var type)) { return(type); } type = _defaultRequestProcessType; var typeDescriptor = HandlerTypeDescriptorHelper.GetHandlerTypeDescriptor(descriptor.HandlerType); if (typeDescriptor?.RequestProcessType.HasValue == true) { type = typeDescriptor.RequestProcessType.Value; } else { var processAttribute = descriptor.ImplementationType .GetCustomAttributes(true) .Concat(descriptor.HandlerType.GetCustomAttributes(true)) .OfType <ProcessAttribute>() .FirstOrDefault(); if (processAttribute != null) { type = processAttribute.Type; } } _cache.TryAdd(descriptor.HandlerType, type); return(type); }
public static ILspHandlerTypeDescriptor GetHandlerTypeDescriptor <T>() { return(KnownHandlers.Values.FirstOrDefault(x => x.InterfaceType == typeof(T)) ?? GetHandlerTypeDescriptor(HandlerTypeDescriptorHelper.GetMethodName(typeof(T)))); }