public static ILanguageClient PreInit(Action <LanguageClientOptions> optionsAction)
        {
            var options = new LanguageClientOptions();

            optionsAction(options);
            return(PreInit(options));
        }
        public static async Task <ILanguageClient> From(LanguageClientOptions options, CancellationToken token)
        {
            var server = (LanguageClient)PreInit(options);
            await server.Initialize(token);

            return(server);
        }
        public static LanguageClient Create(Action <LanguageClientOptions> optionsAction, IServiceProvider outerServiceProvider)
        {
            var options = new LanguageClientOptions();

            optionsAction(options);
            return(Create(options, outerServiceProvider));
        }
 public static LanguageClientOptions WithWorkspaceFolder(this LanguageClientOptions options, DocumentUri documentUri, string name)
 {
     options.Services.AddSingleton(new WorkspaceFolder {
         Name = name, Uri = documentUri
     });
     return(options);
 }
        public static Task <LanguageClient> From(Action <LanguageClientOptions> optionsAction, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
        {
            var options = new LanguageClientOptions();

            optionsAction(options);
            return(From(options, outerServiceProvider, cancellationToken));
        }
        public static Task <ILanguageClient> From(Action <LanguageClientOptions> optionsAction, CancellationToken token)
        {
            var options = new LanguageClientOptions();

            optionsAction(options);
            return(From(options, token));
        }
        public static async Task <LanguageClient> From(LanguageClientOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
        {
            var server = Create(options, outerServiceProvider);
            await server.Initialize(cancellationToken).ConfigureAwait(false);

            return(server);
        }
 public static LanguageClientOptions WithInitializationOptions(
     this LanguageClientOptions options,
     object initializationOptions
     )
 {
     options.InitializationOptions = initializationOptions;
     return(options);
 }
 public static LanguageClientOptions WithReceiver(
     this LanguageClientOptions options,
     ILspClientReceiver serverReceiver
     )
 {
     options.Receiver = serverReceiver;
     return(options);
 }
 public static LanguageClientOptions ConfigureConfiguration(
     this LanguageClientOptions options,
     Action <IConfigurationBuilder> builderAction
     )
 {
     options.ConfigurationBuilderAction = builderAction;
     return(options);
 }
示例#11
0
 public static LanguageClientOptions WithReceiver(
     this LanguageClientOptions options,
     ILspClientReceiver serverReceiver
     )
 {
     options.Services.AddSingleton(serverReceiver);
     return(options);
 }
 public static LanguageClientOptions ConfigureLogging(
     this LanguageClientOptions options,
     Action <ILoggingBuilder> builderAction
     )
 {
     options.LoggingBuilderAction = builderAction;
     return(options);
 }
        public static LanguageClientOptions WithCapability(this LanguageClientOptions options, ICapability capability, params ICapability[] capabilities)
        {
            options.Services.AddSingleton(capability);
            foreach (var item in capabilities)
            {
                options.Services.AddSingleton(item);
            }

            return(options);
        }
 public static Task <LanguageClient> From(LanguageClientOptions options) => From(options, null, CancellationToken.None);
 public static LanguageClient Create(LanguageClientOptions options, IServiceProvider outerServiceProvider) =>
 CreateContainer(options, outerServiceProvider).Resolve <LanguageClient>();
 public static LanguageClientOptions WithWorkspaceFolder(this LanguageClientOptions options, WorkspaceFolder workspaceFolder)
 {
     options.Services.AddSingleton(workspaceFolder);
     return(options);
 }
 public static LanguageClient Create(LanguageClientOptions options) => Create(options, null);
 internal static IContainer CreateContainer(LanguageClientOptions options, IServiceProvider outerServiceProvider) =>
 JsonRpcServerContainer.Create(outerServiceProvider)
 .AddLanguageClientInternals(options, outerServiceProvider);
        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);
        }
 public static LanguageClientOptions WithRootPath(this LanguageClientOptions options, string rootPath)
 {
     options.RootPath = rootPath;
     return(options);
 }
 public static LanguageClientOptions WithTrace(this LanguageClientOptions options, InitializeTrace trace)
 {
     options.Trace = trace;
     return(options);
 }
 public static LanguageClientOptions WithClientCapabilities(this LanguageClientOptions options, ClientCapabilities clientCapabilities)
 {
     options.ClientCapabilities = clientCapabilities;
     return(options);
 }
        internal LanguageClient(LanguageClientOptions options) : base(options)
        {
            _capabilities       = options.SupportedCapabilities;
            _clientCapabilities = options.ClientCapabilities;
            var services = options.Services;

            services.AddLogging(builder => options.LoggingBuilderAction(builder));
            options.RequestProcessIdentifier ??= (options.SupportsContentModified
                ? new RequestProcessIdentifier(RequestProcessType.Parallel)
                : new RequestProcessIdentifier(RequestProcessType.Serial));
            // services.AddSingleton<IOptionsMonitor<LoggerFilterOptions>, LanguageClientLoggerFilterOptions>();

            _clientInfo = options.ClientInfo;
            _receiver   = options.Receiver;
            var serializer            = options.Serializer;
            var supportedCapabilities = new SupportedCapabilities();

            _textDocumentIdentifiers = new TextDocumentIdentifiers();
            var collection = new SharedHandlerCollection(supportedCapabilities, _textDocumentIdentifiers);

            services.AddSingleton <IHandlersManager>(collection);
            _collection = collection;
            // _initializeDelegates = initializeDelegates;
            // _initializedDelegates = initializedDelegates;
            _startedDelegates      = options.StartedDelegates;
            _rootUri               = options.RootUri;
            _trace                 = options.Trace;
            _initializationOptions = options.InitializationOptions;

            services.AddSingleton <IOutputHandler>(_ =>
                                                   new OutputHandler(options.Output, options.Serializer, options.Receiver.ShouldFilterOutput, _.GetService <ILogger <OutputHandler> >()));
            services.AddSingleton(_collection);
            services.AddSingleton(_textDocumentIdentifiers);
            services.AddSingleton(serializer);
            services.AddSingleton <OmniSharp.Extensions.JsonRpc.ISerializer>(serializer);
            services.AddSingleton(options.RequestProcessIdentifier);
            services.AddSingleton <OmniSharp.Extensions.JsonRpc.IReceiver>(options.Receiver);
            services.AddSingleton(options.Receiver);
            services.AddSingleton <ILanguageClient>(this);
            services.AddSingleton <LspRequestRouter>();
            services.AddSingleton <IRequestRouter <ILspHandlerDescriptor> >(_ => _.GetRequiredService <LspRequestRouter>());
            services.AddSingleton <IRequestRouter <IHandlerDescriptor> >(_ => _.GetRequiredService <LspRequestRouter>());
            services.AddSingleton <IResponseRouter, ResponseRouter>();

            services.AddSingleton <IProgressManager, ProgressManager>();
            services.AddSingleton(_ => _.GetRequiredService <IProgressManager>() as IJsonRpcHandler);
            services.AddSingleton <IClientWorkDoneManager, ClientWorkDoneManager>();
            services.AddSingleton(_ => _.GetRequiredService <IClientWorkDoneManager>() as IJsonRpcHandler);

            EnsureAllHandlersAreRegistered();

            services.AddSingleton <RegistrationManager>();
            services.AddSingleton <IRegistrationManager>(_ => _.GetRequiredService <RegistrationManager>());
            if (options.DynamicRegistration)
            {
                services.AddSingleton(_ => _.GetRequiredService <RegistrationManager>() as IJsonRpcHandler);
            }

            var workspaceFoldersManager = new WorkspaceFoldersManager(this);

            services.AddSingleton(workspaceFoldersManager);
            services.AddSingleton <IWorkspaceFoldersManager>(workspaceFoldersManager);
            if (options.WorkspaceFolders)
            {
                services.AddSingleton <IJsonRpcHandler>(workspaceFoldersManager);
            }

            var serviceProvider = services.BuildServiceProvider();

            _disposable.Add(serviceProvider);
            _serviceProvider = serviceProvider;
            collection.SetServiceProvider(_serviceProvider);

            _responseRouter          = _serviceProvider.GetRequiredService <IResponseRouter>();
            _progressManager         = _serviceProvider.GetRequiredService <IProgressManager>();
            _workDoneManager         = _serviceProvider.GetRequiredService <IClientWorkDoneManager>();
            _registrationManager     = _serviceProvider.GetRequiredService <RegistrationManager>();
            _workspaceFoldersManager = _serviceProvider.GetRequiredService <IWorkspaceFoldersManager>();

            _connection = new Connection(
                options.Input,
                _serviceProvider.GetRequiredService <IOutputHandler>(),
                options.Receiver,
                options.RequestProcessIdentifier,
                _serviceProvider.GetRequiredService <IRequestRouter <IHandlerDescriptor> >(),
                _responseRouter,
                _serviceProvider.GetRequiredService <ILoggerFactory>(),
                options.OnUnhandledException ?? (e => { }),
                options.CreateResponseException,
                options.MaximumRequestTimeout,
                options.SupportsContentModified,
                options.Concurrency
                );

            // We need to at least create Window here in case any handler does loggin in their constructor
            TextDocument = new TextDocumentLanguageClient(this, _serviceProvider);
            Client       = new ClientLanguageClient(this, _serviceProvider);
            General      = new GeneralLanguageClient(this, _serviceProvider);
            Window       = new WindowLanguageClient(this, _serviceProvider);
            Workspace    = new WorkspaceLanguageClient(this, _serviceProvider);

            workspaceFoldersManager.Add(options.Folders);

            var serviceHandlers    = _serviceProvider.GetServices <IJsonRpcHandler>().ToArray();
            var serviceIdentifiers = _serviceProvider.GetServices <ITextDocumentIdentifier>().ToArray();

            _disposable.Add(_textDocumentIdentifiers.Add(serviceIdentifiers));
            _disposable.Add(_collection.Add(serviceHandlers));
            options.AddLinks(_collection);
        }
        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);
        }
 public static Task <LanguageClient> From(LanguageClientOptions options, CancellationToken cancellationToken) => From(options, null, cancellationToken);
 /// <summary>
 /// Create the server without connecting to the client
 ///
 /// Mainly used for unit testing
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public static ILanguageClient PreInit(LanguageClientOptions options)
 {
     return(new LanguageClient(options));
 }
 public static Task <LanguageClient> From(LanguageClientOptions options, IServiceProvider outerServiceProvider) =>
 From(options, outerServiceProvider, CancellationToken.None);
 /// <summary>
 /// Create the server without connecting to the client
 ///
 /// Mainly used for unit testing
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public static LanguageClient PreInit(LanguageClientOptions options) => Create(options);
 public static Task <ILanguageClient> From(LanguageClientOptions options)
 {
     return(From(options, CancellationToken.None));
 }
 public static LanguageClientOptions OnInitialized(this LanguageClientOptions options, OnLanguageClientInitializedDelegate @delegate)
 {
     options.Services.AddSingleton(@delegate);
     return(options);
 }