/// <summary> /// Configure language server components. /// </summary> /// <param name="builder"> /// The container builder to configure. /// </param> protected override void Load(ContainerBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.RegisterInstance(Configuration).AsSelf(); builder .Register(componentContext => new LanguageServer( input: Console.OpenStandardInput(), output: Console.OpenStandardOutput(), loggerFactory: componentContext.Resolve <MSLogging.ILoggerFactory>() )) .AsSelf() .As <ILanguageServer>() .SingleInstance() .OnActivated(activated => { LanguageServer languageServer = activated.Instance; // Register configuration handler (which is not a Handler). var configurationHandler = activated.Context.Resolve <ConfigurationHandler>(); languageServer.AddHandler(configurationHandler); void configureServerLogLevel() { if (configurationHandler.Configuration.Logging.Level < LogEventLevel.Verbose) { languageServer.MinimumLogLevel = MSLogging.LogLevel.Warning; } } languageServer.OnInitialize(initializationParameters => { configurationHandler.Configuration.UpdateFrom(initializationParameters); configureServerLogLevel(); // Handle subsequent logging configuration changes. configurationHandler.ConfigurationChanged += (sender, args) => configureServerLogLevel(); return(Task.CompletedTask); }); // Register all other handlers. var handlers = activated.Context.Resolve <IEnumerable <Handler> >(); foreach (Handler handler in handlers) { languageServer.AddHandler(handler); } }); builder.RegisterType <LspDiagnosticsPublisher>() .As <IPublishDiagnostics>() .InstancePerDependency(); builder.RegisterType <ConfigurationHandler>() .AsSelf() .SingleInstance(); builder.RegisterType <Documents.Workspace>() .AsSelf() .SingleInstance() .OnActivated(activated => { Documents.Workspace workspace = activated.Instance; workspace.RestoreTaskMetadataCache(); }); builder .RegisterTypes( typeof(ConfigurationHandler), typeof(DocumentSyncHandler), typeof(DocumentSymbolHandler), typeof(DefinitionHandler), typeof(HoverHandler) ) .AsSelf() .As <Handler>() .SingleInstance(); builder.RegisterType <CompletionHandler>() .AsSelf().As <Handler>() .SingleInstance() .OnActivated(activated => { CompletionHandler completionHandler = activated.Instance; completionHandler.Providers.AddRange( activated.Context.Resolve <IEnumerable <ICompletionProvider> >() ); }); Type completionProviderType = typeof(CompletionProvider); builder.RegisterAssemblyTypes(ThisAssembly) .Where( type => type.IsSubclassOf(completionProviderType) && !type.IsAbstract ) .AsSelf() .As <CompletionProvider>() .As <ICompletionProvider>() .SingleInstance(); }
/// <summary> /// Create a new <see cref="MasterProjectDocument"/>. /// </summary> /// <param name="workspace"> /// The document workspace. /// </param> /// <param name="documentUri"> /// The document URI. /// </param> /// <param name="logger"> /// The application logger. /// </param> public MasterProjectDocument(Workspace workspace, Uri documentUri, ILogger logger) : base(workspace, documentUri, logger) { }