public IServiceProvider ConfigureServices(IServiceCollection services) { var configuration = new ConfigurationBuilder(_environment).Build(); var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(_environment, configuration, _eventEmitter, services, configureLogging: builder => { builder.AddConsole(); var workspaceInformationServiceName = typeof(WorkspaceInformationService).FullName; var projectEventForwarder = typeof(ProjectEventForwarder).FullName; var exceptionHandlerMiddlewareName = typeof(ExceptionHandlerMiddleware).FullName; builder.AddFilter( (category, logLevel) => category.Equals(exceptionHandlerMiddlewareName, StringComparison.OrdinalIgnoreCase) || (_environment.LogLevel <= logLevel && category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) && !category.Equals(workspaceInformationServiceName, StringComparison.OrdinalIgnoreCase) && !category.Equals(projectEventForwarder, StringComparison.OrdinalIgnoreCase))); }); var options = serviceProvider.GetRequiredService <IOptionsMonitor <OmniSharpOptions> >(); var plugins = _commandLinePlugins.AssemblyNames.Concat(options.CurrentValue.Plugins.GetNormalizedLocationPaths(_environment)); var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var logger = loggerFactory.CreateLogger <Startup>(); var assemblyLoader = serviceProvider.GetRequiredService <IAssemblyLoader>(); _compositionHost = new CompositionHostBuilder(serviceProvider) .WithOmniSharpAssemblies() .WithAssemblies(assemblyLoader.LoadByAssemblyNameOrPath(logger, plugins).ToArray()) .Build(); return(serviceProvider); }
public IServiceProvider ConfigureServices(IServiceCollection services) { var configuration = new ConfigurationBuilder(_environment).Build(); var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(_environment, configuration, _eventEmitter, services, configureLogging: builder => { builder.AddConsole(); var workspaceInformationServiceName = typeof(WorkspaceInformationService).FullName; var projectEventForwarder = typeof(ProjectEventForwarder).FullName; var exceptionHandlerMiddlewareName = typeof(ExceptionHandlerMiddleware).FullName; builder.AddFilter( (category, logLevel) => category.Equals(exceptionHandlerMiddlewareName, StringComparison.OrdinalIgnoreCase) || (_environment.LogLevel <= logLevel && category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) && !category.Equals(workspaceInformationServiceName, StringComparison.OrdinalIgnoreCase) && !category.Equals(projectEventForwarder, StringComparison.OrdinalIgnoreCase))); }); _compositionHost = new CompositionHostBuilder(serviceProvider) .WithOmniSharpAssemblies() .Build(); return(serviceProvider); }
static int Main(string[] args) => HostHelpers.Start(() => { var application = new StdioCommandLineApplication(); application.OnExecute(() => { // If an encoding was specified, be sure to set the Console with it before we access the input/output streams. // Otherwise, the streams will be created with the default encoding. if (application.Encoding != null) { var encoding = Encoding.GetEncoding(application.Encoding); Console.InputEncoding = encoding; Console.OutputEncoding = encoding; } var cancellation = new CancellationTokenSource(); if (application.Lsp) { Configuration.ZeroBasedIndices = true; using (var host = new LanguageServerHost( Console.OpenStandardInput(), Console.OpenStandardOutput(), application, cancellation)) { host.Start().Wait(); cancellation.Token.WaitHandle.WaitOne(); } } else { var input = Console.In; var output = Console.Out; var environment = application.CreateEnvironment(); Configuration.ZeroBasedIndices = application.ZeroBasedIndices; var configuration = new ConfigurationBuilder(environment).Build(); var writer = new SharedTextWriter(output); var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(environment, configuration, new StdioEventEmitter(writer)); var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var plugins = application.CreatePluginAssemblies(); var assemblyLoader = serviceProvider.GetRequiredService <IAssemblyLoader>(); var compositionHostBuilder = new CompositionHostBuilder(serviceProvider) .WithOmniSharpAssemblies() .WithAssemblies(assemblyLoader.LoadByAssemblyNameOrPath(plugins.AssemblyNames).ToArray()); using (var host = new Host(input, writer, environment, configuration, serviceProvider, compositionHostBuilder, loggerFactory, cancellation)) { host.Start(); cancellation.Token.WaitHandle.WaitOne(); } } return(0); }); return(application.Execute(args)); });
private PlugInHost CreatePlugInHost(params Assembly[] assemblies) { var serviceProvider = TestServiceProvider.Create(this.TestOutput, new OmniSharpEnvironment()); var compositionHost = new CompositionHostBuilder(serviceProvider) .WithAssemblies(assemblies) .Build(); return(new PlugInHost(serviceProvider, compositionHost)); }
public static OmniSharpTestHost Create( string path = null, ITestOutputHelper testOutput = null, IEnumerable <KeyValuePair <string, string> > configurationData = null, DotNetCliVersion dotNetCliVersion = DotNetCliVersion.Current, IEnumerable <ExportDescriptorProvider> additionalExports = null) { var environment = new OmniSharpEnvironment(path, logLevel: LogLevel.Trace); var loggerFactory = new LoggerFactory().AddXunit(testOutput); var logger = loggerFactory.CreateLogger <OmniSharpTestHost>(); var sharedTextWriter = new TestSharedTextWriter(testOutput); var dotNetCliService = CreateTestDotNetCliService(dotNetCliVersion, loggerFactory); var info = dotNetCliService.GetInfo(); logger.LogInformation($"Using .NET CLI: {info.Version}"); var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); builder.AddInMemoryCollection(configurationData); // We need to set the "UseLegacySdkResolver" for tests because // MSBuild's SDK resolver will not be able to locate the .NET Core SDKs // that we install locally in the ".dotnet" and ".dotnet-legacy" directories. // This property will cause the MSBuild project loader to set the // MSBuildSDKsPath environment variable to the correct path "Sdks" folder // within the appropriate .NET Core SDK. var msbuildProperties = new Dictionary <string, string>() { [$"MSBuild:{nameof(MSBuildOptions.UseLegacySdkResolver)}"] = "true", [$"MSBuild:{nameof(MSBuildOptions.MSBuildSDKsPath)}"] = Path.Combine(info.BasePath, "Sdks") }; builder.AddInMemoryCollection(msbuildProperties); var configuration = builder.Build(); var serviceProvider = new TestServiceProvider(environment, loggerFactory, sharedTextWriter, configuration, NullEventEmitter.Instance, dotNetCliService); var compositionHost = new CompositionHostBuilder(serviceProvider, s_lazyAssemblies.Value, additionalExports) .Build(); var workspace = compositionHost.GetExport <OmniSharpWorkspace>(); WorkspaceInitializer.Initialize(serviceProvider, compositionHost, configuration, logger); var host = new OmniSharpTestHost(serviceProvider, loggerFactory, workspace, compositionHost); // Force workspace to be updated var service = host.GetWorkspaceInformationService(); service.Handle(new WorkspaceInformationRequest()).Wait(); return(host); }
public IServiceProvider ConfigureServices(IServiceCollection services) { var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(_configuration, services); _compositionHost = new CompositionHostBuilder(serviceProvider, _environment, _writer, _eventEmitter) .WithOmniSharpAssemblies() .Build(); return(serviceProvider); }
public static OmniSharpTestHost Create(string path = null, ITestOutputHelper testOutput = null, IEnumerable <KeyValuePair <string, string> > configurationData = null, DotNetCliVersion dotNetCliVersion = DotNetCliVersion.Current) { var dotNetPath = Path.Combine( TestAssets.Instance.RootFolder, GetDotNetCliFolderName(dotNetCliVersion), "dotnet"); if (!File.Exists(dotNetPath)) { dotNetPath = Path.ChangeExtension(dotNetPath, ".exe"); } if (!File.Exists(dotNetPath)) { throw new InvalidOperationException($"Local .NET CLI path does not exist. Did you run build.(ps1|sh) from the command line?"); } var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); builder.AddInMemoryCollection(configurationData); var configuration = builder.Build(); var environment = new OmniSharpEnvironment(path, logLevel: LogLevel.Trace); var loggerFactory = new LoggerFactory().AddXunit(testOutput); var sharedTextWriter = new TestSharedTextWriter(testOutput); var serviceProvider = new TestServiceProvider(environment, loggerFactory, sharedTextWriter, configuration); var compositionHost = new CompositionHostBuilder(serviceProvider, environment, NullEventEmitter.Instance) .WithAssemblies(s_lazyAssemblies.Value) .Build(); var workspace = compositionHost.GetExport <OmniSharpWorkspace>(); var logger = loggerFactory.CreateLogger <OmniSharpTestHost>(); var dotNetCli = compositionHost.GetExport <DotNetCliService>(); dotNetCli.SetDotNetPath(dotNetPath); var version = dotNetCli.GetVersion(); logger.LogInformation($"Using .NET CLI: {version}"); var oldMSBuildSdksPath = SetMSBuildSdksPath(dotNetCli); WorkspaceInitializer.Initialize(serviceProvider, compositionHost, configuration, logger); var host = new OmniSharpTestHost(serviceProvider, loggerFactory, workspace, compositionHost, oldMSBuildSdksPath); // Force workspace to be updated var service = host.GetWorkspaceInformationService(); service.Handle(new WorkspaceInformationRequest()).Wait(); return(host); }
private PlugInHost CreatePlugInHost(params Assembly[] assemblies) { var environment = new OmniSharpEnvironment(); var sharedTextWriter = new TestSharedTextWriter(this.TestOutput); var serviceProvider = new TestServiceProvider(environment, this.LoggerFactory, sharedTextWriter, new Microsoft.Extensions.Configuration.ConfigurationBuilder().Build()); var compositionHost = new CompositionHostBuilder(serviceProvider, environment, sharedTextWriter, NullEventEmitter.Instance) .WithAssemblies(assemblies) .Build(); return(new PlugInHost(serviceProvider, compositionHost)); }
public IServiceProvider ConfigureServices(IServiceCollection services) { var configuration = new ConfigurationBuilder(_environment).Build(); var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(_environment, configuration, _eventEmitter, services, configureLogging: builder => { builder.AddConsole(); }); _compositionHost = new CompositionHostBuilder(serviceProvider) .WithOmniSharpAssemblies() .Build(); return(serviceProvider); }
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 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)); }
public static OmniSharpTestHost Create( IServiceProvider serviceProvider, IEnumerable <ExportDescriptorProvider> additionalExports = null) { var compositionHost = new CompositionHostBuilder(serviceProvider, s_lazyAssemblies.Value, additionalExports) .Build(); WorkspaceInitializer.Initialize(serviceProvider, compositionHost); var host = new OmniSharpTestHost(serviceProvider, compositionHost); // Force workspace to be updated var service = host.GetWorkspaceInformationService(); service.Handle(new WorkspaceInformationRequest()).Wait(); return(host); }
public Host( TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment, IConfiguration configuration, IServiceProvider serviceProvider, CompositionHostBuilder compositionHostBuilder, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource) { _cancellationTokenSource = cancellationTokenSource; _input = input; _writer = writer; _environment = environment; _configuration = configuration; _serviceProvider = serviceProvider; _loggerFactory = loggerFactory.AddStdio(_writer, (category, level) => HostHelpers.LogFilter(category, level, _environment)); _compositionHost = compositionHostBuilder.Build(); _cachedStringBuilder = new CachedStringBuilder(); var handlers = Initialize(); _endpointHandlers = handlers; }
private Host BuildTestServerAndStart(TextReader reader, ISharedTextWriter writer, Action <Host> programDelegate = null) { var configuration = new Microsoft.Extensions.Configuration.ConfigurationBuilder().Build(); var environment = new OmniSharpEnvironment(); var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(environment, configuration, NullEventEmitter.Instance); var cancelationTokenSource = new CancellationTokenSource(); var host = new Host(reader, writer, environment, serviceProvider, new CompositionHostBuilder(serviceProvider), serviceProvider.GetRequiredService <ILoggerFactory>(), cancelationTokenSource); programDelegate?.Invoke(host); host.Start(); return(host); }
private static (IServiceProvider serviceProvider, CompositionHost compositionHost) CreateCompositionHost( ILanguageServer server, InitializeParams initializeParams, CommandLineApplication application, IServiceCollection services ) { var logLevel = GetLogLevel(initializeParams.Trace); var environment = new OmniSharpEnvironment( Helpers.FromUri(initializeParams.RootUri), Convert.ToInt32(initializeParams.ProcessId ?? -1L), 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); var serviceProvider = CompositionHostBuilder.CreateDefaultServiceProvider(environment, configurationRoot, eventEmitter, services); 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()); }
public static OmniSharpTestHost Create( IServiceProvider serviceProvider, IEnumerable <ExportDescriptorProvider> additionalExports = null, [CallerMemberName] string callerName = "") { var environment = serviceProvider.GetRequiredService <IOmniSharpEnvironment>(); var compositionHost = new CompositionHostBuilder(serviceProvider, s_lazyAssemblies.Value, additionalExports) .Build(environment.TargetDirectory); WorkspaceInitializer.Initialize(serviceProvider, compositionHost); var host = new OmniSharpTestHost(serviceProvider, compositionHost, callerName); // Force workspace to be updated var service = host.GetWorkspaceInformationService(); service.Handle(new WorkspaceInformationRequest()).Wait(); return(host); }
public Host( TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment, IServiceProvider serviceProvider, CompositionHostBuilder compositionHostBuilder, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource) { _cancellationTokenSource = cancellationTokenSource; _input = input; _writer = writer; _environment = environment; _serviceProvider = serviceProvider; _logger = loggerFactory.CreateLogger <Host>(); _logger.LogInformation($"Starting OmniSharp on {Platform.Current}"); _compositionHost = compositionHostBuilder.Build(_environment.TargetDirectory); _cachedStringBuilder = new CachedStringBuilder(); var handlers = Initialize(); _endpointHandlers = handlers; }
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 ---"); }