internal static IContainer AddLanguageClientInternals(this IContainer container, LanguageClientOptions options, IServiceProvider outerServiceProvider)
        {
            container = container.AddLanguageProtocolInternals(options);

            container.RegisterInstance(options.ClientCapabilities);
            container.RegisterMany <LspClientReceiver>(
                reuse: Reuse.Singleton,
                nonPublicServiceTypes: true,
                ifAlreadyRegistered: IfAlreadyRegistered.Keep
                );
            if (options.OnUnhandledException != null)
            {
                container.RegisterInstance(options.OnUnhandledException);
            }
            else
            {
                container.RegisterDelegate(_ => new OnUnhandledExceptionHandler(e => _.GetRequiredService <LanguageClient>().Shutdown()), Reuse.Singleton);
            }

            container.RegisterMany <TextDocumentLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(TextDocumentLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <ClientLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(ClientLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <GeneralLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(GeneralLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <WindowLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(WindowLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <WorkspaceLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(WorkspaceLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <DefaultLanguageClientFacade>(
                serviceTypeCondition: type => type.IsClass || !type.Name.Contains("Proxy") && typeof(DefaultLanguageClientFacade).GetInterfaces()
                .Except(typeof(DefaultLanguageClientFacade).BaseType !.GetInterfaces()).Any(z => type == z),
                reuse: Reuse.Singleton
                );
            container.RegisterInstance <IOptionsFactory <LanguageClientOptions> >(new ValueOptionsFactory <LanguageClientOptions>(options));

            container.RegisterMany <LanguageClient>(
                serviceTypeCondition: type => type == typeof(ILanguageClient) || type == typeof(LanguageClient),
                reuse: Reuse.Singleton,
                setup: Setup.With(condition: req => req.IsResolutionRoot || req.Container.Resolve <IInsanceHasStarted>().Started)
                );

            container.RegisterInstance(
                options.ClientInfo ?? new ClientInfo {
                Name    = Assembly.GetEntryAssembly()?.GetName().Name,
                Version = Assembly.GetEntryAssembly()?.GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                          ?.InformationalVersion ??
                          Assembly.GetEntryAssembly()?.GetCustomAttribute <AssemblyVersionAttribute>()?.Version
            }
                );

            var providedConfiguration = options.Services.FirstOrDefault(z => z.ServiceType == typeof(IConfiguration) && z.ImplementationInstance is IConfiguration);

            container.RegisterDelegate <IConfiguration>(
                _ => {
                var builder            = new ConfigurationBuilder();
                var outerConfiguration = outerServiceProvider?.GetService <IConfiguration>();
                if (outerConfiguration != null)
                {
                    builder.CustomAddConfiguration(outerConfiguration, false);
                }

                if (providedConfiguration != null)
                {
                    builder.CustomAddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration);
                }

                //var didChangeConfigurationProvider = _.GetRequiredService<DidChangeConfigurationProvider>();
                return(builder
                       //.AddConfiguration(didChangeConfigurationProvider)
                       .Build());
            },
                Reuse.Singleton
                );

            container.RegisterMany <LanguageClientWorkDoneManager>(Reuse.Singleton);
            container.RegisterMany <LanguageClientWorkspaceFoldersManager>(
                serviceTypeCondition: type => options.WorkspaceFolders || type != typeof(IJsonRpcHandler), reuse: Reuse.Singleton
                );
            container.RegisterMany <LanguageClientRegistrationManager>(
                serviceTypeCondition: type => options.DynamicRegistration || type != typeof(IJsonRpcHandler), reuse: Reuse.Singleton
                );

            return(container);
        }
        internal static IContainer AddLanguageServerInternals(this IContainer container, LanguageServerOptions options, IServiceProvider?outerServiceProvider)
        {
            container = container.AddLanguageProtocolInternals(options);
            container.RegisterMany <LspServerReceiver>(
                reuse: Reuse.Singleton,
                nonPublicServiceTypes: true,
                ifAlreadyRegistered: IfAlreadyRegistered.Keep
                );
            container.RegisterMany <LspServerOutputFilter>(Reuse.Singleton, nonPublicServiceTypes: true);

            if (options.OnUnhandledException != null)
            {
                container.RegisterInstance(options.OnUnhandledException);
            }
            else
            {
                container.RegisterDelegate(_ => new OnUnhandledExceptionHandler(e => { _.GetRequiredService <LanguageServer>().ForcefulShutdown(); }), Reuse.Singleton);
            }

            container.RegisterMany <TextDocumentLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(TextDocumentLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <ClientLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(ClientLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <GeneralLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(GeneralLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <WindowLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(WindowLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <WorkspaceLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(WorkspaceLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <DefaultLanguageServerFacade>(
                serviceTypeCondition: type => type.IsClass || !type.Name.Contains("Proxy") && typeof(DefaultLanguageServerFacade).GetInterfaces()
                .Except(typeof(DefaultLanguageServerFacade).BaseType !.GetInterfaces()).Any(z => type == z),
                reuse: Reuse.Singleton
                );
            container.RegisterInstance <IOptionsFactory <LanguageServerOptions> >(new ValueOptionsFactory <LanguageServerOptions>(options));

            container.RegisterMany <LanguageServer>(
                serviceTypeCondition: type => type == typeof(ILanguageServer) || type == typeof(LanguageServer),
                reuse: Reuse.Singleton,
                setup: Setup.With(condition: req => req.IsResolutionRoot || req.Container.Resolve <IInsanceHasStarted>().Started)
                );

            container.RegisterMany <DidChangeConfigurationProvider>(
                made: Parameters.Of
                .Type <Action <IConfigurationBuilder> >(defaultValue: options.ConfigurationBuilderAction),
                reuse: Reuse.Singleton
                );
            container.RegisterInitializer <ILanguageServerConfiguration>(
                (provider, context) => {
                provider.AddConfigurationItems(context.ResolveMany <ConfigurationItem>());
            }
                );
            container.RegisterMany <ConfigurationConverter>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);


            var providedConfiguration = options.Services.FirstOrDefault(z => z.ServiceType == typeof(IConfiguration) && z.ImplementationInstance is IConfiguration);

            container.RegisterDelegate <IConfiguration>(
                _ => {
                var builder = new ConfigurationBuilder();
                var didChangeConfigurationProvider = _.GetRequiredService <ILanguageServerConfiguration>();
                var outerConfiguration             = outerServiceProvider?.GetService <IConfiguration>();
                if (outerConfiguration != null)
                {
                    builder.CustomAddConfiguration(outerConfiguration, false);
                }

                if (providedConfiguration != null)
                {
                    builder.CustomAddConfiguration((providedConfiguration.ImplementationInstance as IConfiguration) !);
                }

                return(builder.CustomAddConfiguration(didChangeConfigurationProvider).Build());
            },
                Reuse.Singleton
                );

            container.RegisterMany <LanguageServerLoggerFilterOptions>(serviceTypeCondition: type => type.IsInterface, reuse: Reuse.Singleton);
            container.RegisterInstance(
                options.ServerInfo ?? new ServerInfo {
                Name    = Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty,
                Version = Assembly.GetEntryAssembly()?.GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                          ?.InformationalVersion ??
                          Assembly.GetEntryAssembly()?.GetCustomAttribute <AssemblyVersionAttribute>()?.Version
            }
                );

            container.RegisterMany <TextDocumentMatcher>(Reuse.Singleton);
            container.RegisterMany <ExecuteCommandMatcher>(Reuse.Singleton);
            container.RegisterMany <ResolveCommandMatcher>(Reuse.Singleton);
            container.RegisterMany(new[] { typeof(ResolveCommandPipeline <,>) });
            container.RegisterMany(new[] { typeof(SemanticTokensDeltaPipeline <,>) });
            container.RegisterMany <LanguageServerWorkDoneManager>(Reuse.Singleton);
            container.RegisterMany <LanguageServerWorkspaceFolderManager>(reuse: Reuse.Singleton);

            return(container);
        }
        internal static IContainer AddLanguageClientInternals(this IContainer container, LanguageClientOptions options, IServiceProvider outerServiceProvider)
        {
            if (options.Receiver == null)
            {
                throw new ArgumentException("Receiver is missing!", nameof(options));
            }

            container = container.AddLanguageProtocolInternals(options);

            container.RegisterInstance(options.ClientCapabilities);
            container.RegisterInstanceMany(options.Receiver);
            if (options.OnUnhandledException != null)
            {
                container.RegisterInstance(options.OnUnhandledException);
            }
            else
            {
                container.RegisterDelegate(_ => new OnUnhandledExceptionHandler(e => _.GetRequiredService <LanguageClient>().Shutdown()), Reuse.Singleton);
            }

            container.RegisterMany <TextDocumentLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(TextDocumentLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <ClientLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(ClientLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <GeneralLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(GeneralLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <WindowLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(WindowLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterMany <WorkspaceLanguageClient>(serviceTypeCondition: type => type.Name.Contains(nameof(WorkspaceLanguageClient)), reuse: Reuse.Singleton);
            container.RegisterInstance <IOptionsFactory <LanguageClientOptions> >(new ValueOptionsFactory <LanguageClientOptions>(options));

            container.RegisterMany <LanguageClient>(serviceTypeCondition: type => type == typeof(ILanguageClient) || type == typeof(LanguageClient), reuse: Reuse.Singleton);

            container.RegisterInstance(
                options.ClientInfo ?? new ClientInfo {
                Name    = Assembly.GetEntryAssembly()?.GetName().Name,
                Version = Assembly.GetEntryAssembly()?.GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                          ?.InformationalVersion ??
                          Assembly.GetEntryAssembly()?.GetCustomAttribute <AssemblyVersionAttribute>()?.Version
            }
                );

            var providedConfiguration = options.Services.FirstOrDefault(z => z.ServiceType == typeof(IConfiguration) && z.ImplementationInstance is IConfiguration);

            container.RegisterDelegate <IConfiguration>(
                _ => {
                var builder            = new ConfigurationBuilder();
                var outerConfiguration = outerServiceProvider?.GetService <IConfiguration>();
                if (outerConfiguration != null)
                {
                    builder.AddConfiguration(outerConfiguration, false);
                }

                if (providedConfiguration != null)
                {
                    builder.AddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration);
                }

                //var didChangeConfigurationProvider = _.GetRequiredService<DidChangeConfigurationProvider>();
                return(builder
                       //.AddConfiguration(didChangeConfigurationProvider)
                       .Build());
            },
                Reuse.Singleton
                );

            container.RegisterMany <LanguageClientWorkDoneManager>(Reuse.Singleton);
            container.RegisterMany <LanguageClientWorkspaceFoldersManager>(
                serviceTypeCondition: type => options.WorkspaceFolders || type != typeof(IJsonRpcHandler), reuse: Reuse.Singleton
                );
            container.RegisterMany <LanguageClientRegistrationManager>(
                serviceTypeCondition: type => options.DynamicRegistration || type != typeof(IJsonRpcHandler), reuse: Reuse.Singleton
                );

            return(container);
        }
        internal static IContainer AddLanguageServerInternals(this IContainer container, LanguageServerOptions options, IServiceProvider outerServiceProvider)
        {
            if (options.Receiver == null)
            {
                throw new ArgumentException("Receiver is missing!", nameof(options));
            }

            container = container.AddLanguageProtocolInternals(options);

            container.RegisterInstanceMany(options.Receiver);
            if (options.OnUnhandledException != null)
            {
                container.RegisterInstance(options.OnUnhandledException);
            }
            else
            {
                container.RegisterDelegate(_ => new OnUnhandledExceptionHandler(e => { _.GetRequiredService <LanguageServer>().ForcefulShutdown(); }), Reuse.Singleton);
            }

            container.RegisterMany <TextDocumentLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(TextDocumentLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <ClientLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(ClientLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <GeneralLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(GeneralLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <WindowLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(WindowLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterMany <WorkspaceLanguageServer>(serviceTypeCondition: type => type.Name.Contains(nameof(WorkspaceLanguageServer)), reuse: Reuse.Singleton);
            container.RegisterInstance <IOptionsFactory <LanguageServerOptions> >(new ValueOptionsFactory <LanguageServerOptions>(options));

            container.RegisterMany <LanguageServer>(serviceTypeCondition: type => type == typeof(ILanguageServer) || type == typeof(LanguageServer), reuse: Reuse.Singleton);

            container.RegisterMany <DidChangeConfigurationProvider>(
                made: Parameters.Of
                .Type <Action <IConfigurationBuilder> >(defaultValue: options.ConfigurationBuilderAction),
                reuse: Reuse.Singleton
                );

            var providedConfiguration = options.Services.FirstOrDefault(z => z.ServiceType == typeof(IConfiguration) && z.ImplementationInstance is IConfiguration);

            container.RegisterDelegate <IConfiguration>(
                _ => {
                var builder = new ConfigurationBuilder();
                var didChangeConfigurationProvider = _.GetRequiredService <DidChangeConfigurationProvider>();
                var outerConfiguration             = outerServiceProvider?.GetService <IConfiguration>();
                if (outerConfiguration != null)
                {
                    builder.AddConfiguration(outerConfiguration, false);
                }

                if (providedConfiguration != null)
                {
                    builder.AddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration);
                }

                return(builder.AddConfiguration(didChangeConfigurationProvider).Build());
            },
                Reuse.Singleton
                );

            container.RegisterMany <LanguageServerLoggerFilterOptions>(serviceTypeCondition: type => type.IsInterface, reuse: Reuse.Singleton);
            container.RegisterInstance(
                options.ServerInfo ?? new ServerInfo {
                Name    = Assembly.GetEntryAssembly()?.GetName().Name,
                Version = Assembly.GetEntryAssembly()?.GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                          ?.InformationalVersion ??
                          Assembly.GetEntryAssembly()?.GetCustomAttribute <AssemblyVersionAttribute>()?.Version
            }
                );

            container.RegisterMany <TextDocumentMatcher>(Reuse.Singleton);
            container.RegisterMany <ExecuteCommandMatcher>(Reuse.Singleton);
            container.RegisterMany <ResolveCommandMatcher>(Reuse.Singleton);
            container.RegisterMany(new[] { typeof(ResolveCommandPipeline <,>) });
            container.RegisterMany <LanguageServerWorkDoneManager>(Reuse.Singleton);
            container.RegisterMany <LanguageServerWorkspaceFolderManager>(Reuse.Singleton);

            return(container);
        }