private static (IServiceProvider serviceProvider, CompositionHost compositionHost) CreateCompositionHost( ILanguageServer server, InitializeParams initializeParams, CommandLineApplication application, IServiceCollection services, Action <ILoggingBuilder> configureLogging) { var logLevel = GetLogLevel(initializeParams.Trace); var root = Helpers.FromUri(initializeParams.RootUri); var environment = new OmniSharpEnvironment( string.IsNullOrEmpty(root) ? application.ApplicationRoot : root, Convert.ToInt32(initializeParams.ProcessId ?? application.HostPid), application.LogLevel < logLevel ? application.LogLevel : logLevel, application.OtherArgs.ToArray()); var configurationRoot = new Microsoft.Extensions.Configuration.ConfigurationBuilder() .AddConfiguration(new ConfigurationBuilder(environment).Build()) .AddConfiguration(server.Configuration.GetSection("csharp")) .AddConfiguration(server.Configuration.GetSection("omnisharp")) .Build() ; var eventEmitter = new LanguageServerEventEmitter(server); services.AddSingleton(server) .AddSingleton <ILanguageServerFacade>(server); var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(environment, configurationRoot, eventEmitter, services, GetLogBuilderAction(configureLogging, environment.LogLevel)); var loggerFactory = serviceProvider.GetService <ILoggerFactory>(); var logger = loggerFactory.CreateLogger <LanguageServerHost>(); var options = serviceProvider.GetRequiredService <IOptionsMonitor <OmniSharpOptions> >(); var plugins = application.CreatePluginAssemblies(options.CurrentValue, environment); var assemblyLoader = serviceProvider.GetRequiredService <IAssemblyLoader>(); var compositionHostBuilder = new CompositionHostBuilder(serviceProvider) .WithOmniSharpAssemblies() .WithAssemblies(typeof(LanguageServerHost).Assembly) .WithAssemblies(assemblyLoader.LoadByAssemblyNameOrPath(logger, plugins.AssemblyNames).ToArray()); return(serviceProvider, compositionHostBuilder.Build(environment.TargetDirectory)); }
private void CreateCompositionHost(InitializeParams initializeParams) { _environment = new OmniSharpEnvironment( Helpers.FromUri(initializeParams.RootUri), Convert.ToInt32(initializeParams.ProcessId ?? -1L), GetLogLevel(initializeParams.Trace), _application.OtherArgs.ToArray()); // TODO: Make this work with logger factory differently // Maybe create a child logger factory? _loggerFactory.AddProvider(_server, _environment); _logger = _loggerFactory.CreateLogger <LanguageServerHost>(); var configurationRoot = new ConfigurationBuilder(_environment).Build(); var eventEmitter = new LanguageServerEventEmitter(_server); _serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(_environment, configurationRoot, eventEmitter, _services); var plugins = _application.CreatePluginAssemblies(); var assemblyLoader = _serviceProvider.GetRequiredService <IAssemblyLoader>(); var compositionHostBuilder = new CompositionHostBuilder(_serviceProvider) .WithOmniSharpAssemblies() .WithAssemblies(typeof(LanguageServerHost).Assembly) .WithAssemblies(assemblyLoader.LoadByAssemblyNameOrPath(plugins.AssemblyNames).ToArray()); _compositionHost = compositionHostBuilder.Build(); var projectSystems = _compositionHost.GetExports <IProjectSystem>(); var documentSelectors = projectSystems .GroupBy(x => x.Language) .Select(x => ( language: x.Key, selector: new DocumentSelector(x .SelectMany(z => z.Extensions) .Distinct() .Select(z => new DocumentFilter() { Pattern = $"**/*{z}" })) )); _logger.LogTrace( "Configured Document Selectors {@DocumentSelectors}", documentSelectors.Select(x => new { x.language, x.selector }) ); // TODO: Get these with metadata so we can attach languages // This will thne let us build up a better document filter, and add handles foreach type of handler // This will mean that we will have a strategy to create handlers from the interface type _handlers = new RequestHandlers( _compositionHost.GetExports <Lazy <IRequestHandler, OmniSharpRequestHandlerMetadata> >(), documentSelectors ); _logger.LogTrace("--- Handler Definitions ---"); foreach (var handlerCollection in _handlers) { foreach (var handler in handlerCollection) { _logger.LogTrace( "Handler: {Language}:{DocumentSelector}:{Handler}", handlerCollection.Language, handlerCollection.DocumentSelector.ToString(), handler.GetType().FullName ); } } _logger.LogTrace("--- Handler Definitions ---"); }
private static (IServiceProvider serviceProvider, CompositionHost compositionHost) CreateCompositionHost( ILanguageServer server, InitializeParams initializeParams, CommandLineApplication application, IServiceCollection services, Action <ILoggingBuilder> configureLogging) { var logLevel = GetLogLevel(initializeParams.Trace); var environment = new OmniSharpEnvironment( // TODO: Support solution selection from the server side in the future // For now selection can be done by passing -s to the server !string.IsNullOrEmpty(application.ApplicationRoot) ? application.ApplicationRoot : Helpers.FromUri(initializeParams.RootUri), Convert.ToInt32(initializeParams.ProcessId ?? application.HostPid), application.LogLevel < logLevel ? application.LogLevel : logLevel, application.OtherArgs.ToArray()); var configurationResult = new ConfigurationBuilder(environment).Build(b => b.AddConfiguration(server.Configuration.GetSection("csharp")).AddConfiguration(server.Configuration.GetSection("omnisharp"))); var eventEmitter = new LanguageServerEventEmitter(server); services.AddSingleton(server) .AddSingleton <ILanguageServerFacade>(server); var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(environment, configurationResult.Configuration, eventEmitter, services, GetLogBuilderAction(configureLogging, environment.LogLevel)); var loggerFactory = serviceProvider.GetService <ILoggerFactory>(); var logger = loggerFactory.CreateLogger <LanguageServerHost>(); if (configurationResult.HasError()) { logger.LogError(configurationResult.Exception, "There was an error when reading the OmniSharp configuration, starting with the default options."); } var options = serviceProvider.GetRequiredService <IOptionsMonitor <OmniSharpOptions> >(); var plugins = application.CreatePluginAssemblies(options.CurrentValue, environment); var assemblyLoader = serviceProvider.GetRequiredService <IAssemblyLoader>(); var compositionHostBuilder = new CompositionHostBuilder(serviceProvider) .WithOmniSharpAssemblies() .WithAssemblies(typeof(LanguageServerHost).Assembly) .WithAssemblies(assemblyLoader.LoadByAssemblyNameOrPath(logger, plugins.AssemblyNames).ToArray()); return(serviceProvider, compositionHostBuilder.Build(environment.TargetDirectory)); }