/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/BrokeredServiceContainer.cs
90 строк
4 KB
David Barbet
Refactor LSP server logging to remove singleton lsp instance (#84001)
16 июн 2026, 05:04
Не верифицирован
16 июн 2026, 05:04
82e81e5
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Collections.Immutable; using System.Diagnostics; using Microsoft.CodeAnalysis.BrokeredServices; using Microsoft.CodeAnalysis.LanguageServer.BrokeredServices.Services; using Microsoft.Extensions.Logging; using Microsoft.ServiceHub.Framework; using Microsoft.ServiceHub.Framework.Services; using Microsoft.VisualStudio.Composition; using Microsoft.VisualStudio.Threading; using Microsoft.VisualStudio.Utilities.ServiceBroker; namespace Microsoft.CodeAnalysis.LanguageServer.BrokeredServices; internal sealed class BrokeredServiceContainer : GlobalBrokeredServiceContainer { public BrokeredServiceContainer(TraceSource traceSource) : base(ImmutableDictionary<ServiceMoniker, ServiceRegistration>.Empty, isClientOfExclusiveServer: false, joinableTaskFactory: null, traceSource) { } public override IReadOnlyDictionary<string, string> LocalUserCredentials => ImmutableDictionary<string, string>.Empty; /// <inheritdoc cref="GlobalBrokeredServiceContainer.RegisterServices(IReadOnlyDictionary{ServiceMoniker, ServiceRegistration})"/> internal new void RegisterServices(IReadOnlyDictionary<ServiceMoniker, ServiceRegistration> services) => base.RegisterServices(services); /// <inheritdoc cref="GlobalBrokeredServiceContainer.UnregisterServices(IEnumerable{ServiceMoniker})"/> internal new void UnregisterServices(IEnumerable<ServiceMoniker> services) => base.UnregisterServices(services); internal ImmutableDictionary<ServiceMoniker, ServiceRegistration> GetRegisteredServices() => RegisteredServices; internal static async Task<BrokeredServiceContainer> CreateAsync( ExportProvider exportProvider, ImmutableArray<IServiceBrokerInitializer> serviceBrokerInitializers, ILoggerFactory loggerFactory, CancellationToken cancellationToken) { var container = new BrokeredServiceContainer(BrokeredServiceTraceListener.CreateTraceSource(loggerFactory)); container.ProfferIntrinsicService( FrameworkServices.Authorization, new ServiceRegistration(VisualStudio.Shell.ServiceBroker.ServiceAudience.Local, null, allowGuestClients: true), async (moniker, options, serviceBroker, cancellationToken) => new NoOpAuthorizationService()); var mefServiceBroker = exportProvider.GetExportedValue<MefServiceBrokerOfExportedServices>(); mefServiceBroker.SetContainer(container); // Register local mef services. await mefServiceBroker.RegisterAndProfferServicesAsync(cancellationToken); // Register and proffer all services that come from service broker manual initialization var servicesToRegister = serviceBrokerInitializers.SelectMany(s => s.ServicesToRegister).ToDictionary(a => a.Key, a => a.Value); container.RegisterServices(servicesToRegister); foreach (var onInitialized in serviceBrokerInitializers) onInitialized.Proffer(container); // Register the desired remote services container.RegisterServices(Descriptors.RemoteServicesToRegister); return container; } private class NoOpAuthorizationService : IAuthorizationService { public event EventHandler? CredentialsChanged; public event EventHandler? AuthorizationChanged; public async ValueTask<bool> CheckAuthorizationAsync(ProtectedOperation operation, CancellationToken cancellationToken = default) { return true; } public async ValueTask<IReadOnlyDictionary<string, string>> GetCredentialsAsync(CancellationToken cancellationToken = default) { return ImmutableDictionary<string, string>.Empty; } protected virtual void OnCredentialsChanged(EventArgs args) => this.CredentialsChanged?.Invoke(this, args); protected virtual void OnAuthorizationChanged(EventArgs args) => this.AuthorizationChanged?.Invoke(this, args); } }