public JsonAmqpRpcServer(string hostName, string queueName, IJsonRpcHandler handler) { _log = LogManager.GetCurrentClassLogger(); _log.Info("AMQP RPC server starting: host = {0}; queue = {1}", hostName, queueName); _messaging = AmqpRpc.CreateMessaging(AmqpRpc.CreateConnector(hostName), queueName); _handler = handler; }
public IDisposable Add(IJsonRpcHandler handler, JsonRpcHandlerOptions options) { var result = _parent.Add(handler, options); _compositeDisposable.Add(result); return(result); }
public LspHandlerDescriptorDisposable Add(string method, IJsonRpcHandler handler) { var descriptor = GetDescriptor(method, handler.GetType(), handler); _handlers.Add(descriptor); return(new LspHandlerDescriptorDisposable(descriptor)); }
public HandlerInstance( string method, IJsonRpcHandler handler, Type handlerInterface, Type @params, Type response, RequestProcessType?requestProcessType, Action disposeAction ) { _disposeAction = disposeAction; Handler = handler; ImplementationType = handler.GetType(); Method = method; HandlerType = handlerInterface; Params = @params; Response = response; HasReturnType = HandlerType.GetInterfaces().Any( @interface => @interface.IsGenericType && typeof(IRequestHandler <,>).IsAssignableFrom(@interface.GetGenericTypeDefinition()) ); IsDelegatingHandler = @params?.IsGenericType == true && ( typeof(DelegatingRequest <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) || typeof(DelegatingNotification <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) ); IsNotification = handlerInterface.GetInterfaces().Any( z => z.IsGenericType && typeof(IJsonRpcNotificationHandler <>).IsAssignableFrom(z.GetGenericTypeDefinition()) ); IsRequest = !IsNotification; RequestProcessType = requestProcessType; }
private HandlerDescriptor GetDescriptor(string method, Type implementedType, IJsonRpcHandler handler) { var @interface = HandlerTypeHelpers.GetHandlerInterface(implementedType); var registration = UnwrapGenericType(typeof(IRegistration <>), implementedType); var capability = UnwrapGenericType(typeof(ICapability <>), implementedType); Type @params = null; if (@interface.GetTypeInfo().IsGenericType) { @params = @interface.GetTypeInfo().GetGenericArguments()[0]; } var key = "default"; if (handler is IRegistration <TextDocumentRegistrationOptions> ) { if (GetTextDocumentRegistrationOptionsMethod .MakeGenericMethod(registration) .Invoke(handler, new object[] { handler }) is TextDocumentRegistrationOptions options) { key = options.DocumentSelector; } } return(new HandlerDescriptor( method, key, handler, @interface, @params, registration, capability, () => _handlers.RemoveWhere(instance => instance.Handler == handler))); }
public HandlerInstance(string method, IJsonRpcHandler handler, Type handlerInterface, Type @params, Action disposeAction) { _disposeAction = disposeAction; Handler = handler; Method = method; HandlerType = handlerInterface; Params = @params; }
public LspHandlerDescriptor( int index, string method, string key, IJsonRpcHandler handler, Type handlerType, Type? @params, Type?registrationType, string registrationMethod, object?registrationOptions, Type?capabilityType, RequestProcessType?requestProcessType, Action disposeAction, ILspHandlerTypeDescriptor?typeDescriptor, Guid?id ) { _disposeAction = disposeAction; Id = id.HasValue ? id.Value : handler is ICanBeIdentifiedHandler h && h.Id != Guid.Empty ? h.Id : Guid.NewGuid(); Method = method; Key = key; ImplementationType = handler.GetType(); Handler = handler; HandlerType = handlerType; Params = @params; RegistrationType = registrationType; RegistrationMethod = registrationMethod; RegistrationOptions = registrationOptions; CapabilityType = capabilityType; Response = @params?.GetInterfaces() .Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest <>)) .Select(x => x.GetGenericArguments()[0]) .OrderBy(x => x == typeof(Unit)) .FirstOrDefault() ?? typeDescriptor?.ResponseType ?? typeof(Unit); // If multiple are implemented this behavior is unknown CanBeResolvedHandlerType = handler.GetType().GetTypeInfo() ?.ImplementedInterfaces ?.FirstOrDefault(x => typeof(ICanBeResolvedHandler).IsAssignableFrom(x)); HasReturnType = Response != null && Response != typeof(Unit); IsDelegatingHandler = @params?.IsGenericType == true && ( typeof(DelegatingRequest <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) || typeof(DelegatingNotification <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) ); IsNotification = handlerType.GetInterfaces() .Any(z => z.IsGenericType && typeof(IJsonRpcNotificationHandler <>).IsAssignableFrom(z.GetGenericTypeDefinition())); IsRequest = !IsNotification; RequestProcessType = requestProcessType; TypeDescriptor = typeDescriptor; Index = index; IsBuiltIn = handler.GetType().GetCustomAttributes <BuiltInAttribute>().Any(); }
private void Remove(IJsonRpcHandler handler) { var handlers = _handlers.FindAll(instance => instance.Handler == handler); foreach (var item in handlers) { _handlers.Remove(item); } }
private void Remove(IJsonRpcHandler handler) { var i = _handlers.Find(instance => instance.Handler == handler); if (i != null) { _handlers.Remove(i); } }
public LspHandlerDescriptor( string method, string key, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, object registrationOptions, Func <bool> allowsDynamicRegistration, Type capabilityType, RequestProcessType?requestProcessType, Action disposeAction, ILspHandlerTypeDescriptor typeDescriptor ) { _disposeAction = disposeAction; Id = Guid.NewGuid(); Method = method; Key = key; ImplementationType = handler.GetType(); Handler = handler; HandlerType = handlerType; Params = @params; RegistrationType = registrationType; RegistrationOptions = registrationOptions; _allowsDynamicRegistration = allowsDynamicRegistration; CapabilityType = capabilityType; Response = typeDescriptor?.ResponseType ?? @params?.GetInterfaces() .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest <>))? .GetGenericArguments()[0] ?? typeof(Unit); // If multiple are implemented this behavior is unknown CanBeResolvedHandlerType = handler.GetType().GetTypeInfo() .ImplementedInterfaces .FirstOrDefault(x => typeof(ICanBeResolvedHandler).IsAssignableFrom(x)); HasReturnType = Response != null && Response != typeof(Unit); IsDelegatingHandler = @params?.IsGenericType == true && ( typeof(DelegatingRequest <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) || typeof(DelegatingNotification <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) ); IsNotification = typeof(IJsonRpcNotificationHandler).IsAssignableFrom(handlerType) || handlerType .GetInterfaces().Any( z => z.IsGenericType && typeof(IJsonRpcNotificationHandler <>).IsAssignableFrom( z.GetGenericTypeDefinition() ) ); IsRequest = !IsNotification; RequestProcessType = requestProcessType; TypeDescriptor = typeDescriptor; }
/// <summary> /// Add a handler to the server's collection of JSON RPC handlers. /// </summary> /// <param name="handler"> /// The handler to add. /// </param> /// <returns> /// An <see cref="IDisposable"/> representing the handler; when disposed, the handler is removed from the handler collection. /// </returns> public virtual IDisposable AddHandler(IJsonRpcHandler handler) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } return(Disposable.Empty); }
public HandlerInstance(string method, IJsonRpcHandler handler, Type handlerInterface, Type @params, Type response, Action disposeAction) { _disposeAction = disposeAction; Handler = handler; ImplementationType = handler.GetType(); Method = method; HandlerType = handlerInterface; Params = @params; Response = response; }
private void Remove(IJsonRpcHandler handler) { var descriptors = _descriptors.ToBuilder(); foreach (var item in _descriptors.Where(instance => instance.Handler == handler)) { descriptors.Remove(item); } ImmutableInterlocked.InterlockedExchange(ref _descriptors, descriptors.ToImmutableArray()); }
public HandlerDescriptor(string method, string key, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, Type capabilityType, Action disposeAction) { _disposeAction = disposeAction; Handler = handler; Method = method; Key = key; HandlerType = handlerType; Params = @params; RegistrationType = registrationType; CapabilityType = capabilityType; }
public HandlerDescriptor( string method, string key, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, object registrationOptions, bool allowsDynamicRegistration, Type capabilityType, Action disposeAction) { _disposeAction = disposeAction; Id = Guid.NewGuid(); Method = method; Key = key; ImplementationType = handler.GetType(); Handler = handler; HandlerType = handlerType; Params = @params; Response = Response; RegistrationType = registrationType; RegistrationOptions = registrationOptions; AllowsDynamicRegistration = allowsDynamicRegistration; CapabilityType = capabilityType; var requestInterface = @params?.GetInterfaces() .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest <>)); if (requestInterface != null) { Response = requestInterface.GetGenericArguments()[0]; } // If multiple are implemented this behavior is unknown CanBeResolvedHandlerType = handler.GetType().GetTypeInfo() .ImplementedInterfaces .FirstOrDefault(x => x.GetTypeInfo().IsGenericType&& x.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICanBeResolvedHandler <>)); HasReturnType = HandlerType.GetInterfaces().Any(@interface => @interface.IsGenericType && typeof(IRequestHandler <,>).IsAssignableFrom(@interface.GetGenericTypeDefinition()) ); IsDelegatingHandler = @params?.IsGenericType == true && ( typeof(DelegatingRequest <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) || typeof(DelegatingNotification <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) ); if (handler is IOnStarted started) { StartedDelegate = started.OnStarted; } }
public void Should_DisallowUnsupportedCapabilities(IJsonRpcHandler handler, object instance) { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); var collection = new HandlerCollection { textDocumentSyncHandler, handler }; var provider = new ClientCapabilityProvider(collection); HasHandler(provider, instance).Should().BeFalse(); }
public void Should_AllowNullSupportedCapabilities(IJsonRpcHandler handler, object instance) { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); var collection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue) { textDocumentSyncHandler, handler }; var provider = new ClientCapabilityProvider(collection); HasHandler(provider, instance).Should().BeTrue(); }
public void Should_DisallowDynamicSupportedCapabilities(IJsonRpcHandler handler, object instance) { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var collection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers()) { textDocumentSyncHandler, handler }; var provider = new ClientCapabilityProvider(collection, true); HasHandler(provider, instance).Should().BeFalse(); }
public LspHandlerDescriptorDisposable Add(string method, IJsonRpcHandler handler) { var descriptor = GetDescriptor(method, handler.GetType(), handler); _handlers.Add(descriptor); var cd = new CompositeDisposable(); if (descriptor.Handler is ITextDocumentIdentifier textDocumentIdentifier) { cd.Add(_textDocumentIdentifiers.Add(textDocumentIdentifier)); } return(new LspHandlerDescriptorDisposable(new[] { descriptor }, cd)); }
public void SetCapability(ILspHandlerDescriptor descriptor, IJsonRpcHandler handler) { if (!descriptor.HasCapability) { return; } if (_supports.TryGetValue(descriptor.CapabilityType, out var capability)) { SetCapabilityInnerMethod .MakeGenericMethod(descriptor.CapabilityType) .Invoke(null, new[] { handler, capability }); } }
/// <summary> /// Add a handler for the specified method to the server's collection of JSON RPC handlers. /// </summary> /// <param name="method"> /// The method name. /// </param> /// <param name="handler"> /// The handler to add. /// </param> /// <returns> /// An <see cref="IDisposable"/> representing the handler; when disposed, the handler is removed from the handler collection. /// </returns> public IDisposable AddHandler(string method, IJsonRpcHandler handler) { if (String.IsNullOrWhiteSpace(method)) { throw new ArgumentException("Argument cannot be null, empty, or entirely composed of whitespace: 'method'.", nameof(method)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } return(Disposable.Empty); }
public HandlerDescriptor(string method, string key, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, Type capabilityType, Action disposeAction) { _disposeAction = disposeAction; Handler = handler; Method = method; Key = key; HandlerType = handlerType; Params = @params; RegistrationType = registrationType; CapabilityType = capabilityType; if (@params != null && typeof(ICanBeResolved).GetTypeInfo().IsAssignableFrom(@params)) { CanBeResolvedHandlerType = typeof(ICanBeResolvedHandler <>).MakeGenericType(@params); } }
public void Should_AllowNullSupportedCapabilities(IJsonRpcHandler handler, object instance) { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })) { textDocumentSyncHandler, handler }; var provider = new ClientCapabilityProvider(collection, true); HasHandler(provider, instance).Should().BeTrue(); }
public HandlerDescriptor(string method, string key, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, Type capabilityType, Action disposeAction) { _disposeAction = disposeAction; Handler = handler; Method = method; Key = key; HandlerType = handlerType; Params = @params; RegistrationType = registrationType; CapabilityType = capabilityType; // If multiple are implemented this behavior is unknown CanBeResolvedHandlerType = handler.GetType().GetTypeInfo() .ImplementedInterfaces .FirstOrDefault(x => x.GetTypeInfo().IsGenericType&& x.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICanBeResolvedHandler <>)); }
public IDisposable Add(string method, IJsonRpcHandler handler) { var type = handler.GetType(); var @interface = GetHandlerInterface(type); Type @params = null; if (@interface.GetTypeInfo().IsGenericType) { @params = @interface.GetTypeInfo().GetGenericArguments()[0]; } var h = new HandlerInstance(method, handler, @interface, @params, () => Remove(handler)); _handlers.Add(h); return(h); }
public LspHandlerDescriptor( string method, string key, IJsonRpcHandler handler, Type handlerType, Type? @params, Type?registrationType, object?registrationOptions, Func <bool> allowsDynamicRegistration, Type?capabilityType, RequestProcessType?requestProcessType, Action disposeAction, ILspHandlerTypeDescriptor?typeDescriptor ) : this( method, key, handler, handlerType, @params, registrationType, registrationOptions, allowsDynamicRegistration, capabilityType, requestProcessType, disposeAction, typeDescriptor, null ) { }
public IDisposable AddHandler(string method, IJsonRpcHandler handler) { var handlerDisposable = _collection.Add(method, handler); return(new ImmutableDisposable( handlerDisposable, new Disposable(() => { var foundItems = _collection .Where(x => handler == x.Handler) .Where(x => x.AllowsDynamicRegistration) .Select(x => x.Registration) .Where(x => x != null) .ToArray(); Task.Run(() => this.UnregisterCapability(new UnregistrationParams() { Unregisterations = foundItems })); }))); }
public LspHandlerDescriptor( int index, string method, string key, IJsonRpcHandler handler, Type handlerType, Type? @params, Type?registrationType, string registrationMethod, object?registrationOptions, Type?capabilityType, RequestProcessType?requestProcessType, Action disposeAction, ILspHandlerTypeDescriptor?typeDescriptor ) : this( index, method, key, handler, handlerType, @params, registrationType, registrationMethod, registrationOptions, capabilityType, requestProcessType, disposeAction, typeDescriptor, null ) { }
private HandlerDescriptor GetDescriptor(string method, Type implementedType, IJsonRpcHandler handler) { var @interface = HandlerTypeHelpers.GetHandlerInterface(implementedType); var registration = UnwrapGenericType(typeof(IRegistration <>), implementedType); var capability = UnwrapGenericType(typeof(ICapability <>), implementedType); Type @params = null; if (@interface.GetTypeInfo().IsGenericType) { @params = @interface.GetTypeInfo().GetGenericArguments()[0]; } var key = "default"; // This protects against the case where class implements many, possibly conflicting, interfaces. if ((registration != null && typeof(TextDocumentRegistrationOptions).GetTypeInfo().IsAssignableFrom(registration) || registration == null && implementedType.GetTypeInfo().ImplementedInterfaces.Any(x => x.GetTypeInfo().IsGenericType&& x.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICanBeResolvedHandler <>))) && handler is IRegistration <TextDocumentRegistrationOptions> handlerRegistration) { key = string.IsNullOrEmpty(handlerRegistration?.GetRegistrationOptions()?.DocumentSelector) ? key : handlerRegistration?.GetRegistrationOptions()?.DocumentSelector; } return(new HandlerDescriptor( method, key, handler, @interface, @params, registration, capability, () => { _handlers.RemoveWhere(instance => instance.Handler == handler); _documentSyncHandlers.RemoveWhere(instance => instance == handler); })); }
public HandlerDescriptor( string method, string key, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, Registration registration, Type capabilityType, Action disposeAction) { _disposeAction = disposeAction; Method = method; Key = key; ImplementationType = handler.GetType(); Handler = handler; HandlerType = handlerType; Params = @params; Response = Response; RegistrationType = registrationType; Registration = registration; CapabilityType = capabilityType; var requestInterface = @params?.GetInterfaces() .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest <>)); if (requestInterface != null) { Response = requestInterface.GetGenericArguments()[0]; } // If multiple are implemented this behavior is unknown CanBeResolvedHandlerType = handler.GetType().GetTypeInfo() .ImplementedInterfaces .FirstOrDefault(x => x.GetTypeInfo().IsGenericType&& x.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICanBeResolvedHandler <>)); }
public JsonAmqpRpcServer(string hostName, string queueName, IJsonRpcHandler handler) { _log = LogManager.GetCurrentClassLogger(); _log.Info("AMQP RPC server starting: host = {0}; queue = {1}", hostName, queueName); _messaging = AmqpRpc.CreateMessaging(AmqpRpc.CreateConnector(hostName), queueName); _handler = handler; }