diff --git a/src/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler.cs b/src/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler.cs index 2f988beec8053..0fc92f10bfef3 100644 --- a/src/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler.cs +++ b/src/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler.cs @@ -62,8 +62,16 @@ public DidChangeConfigurationNotificationHandler( public bool RequiresLSPSolution => false; - public Task HandleNotificationAsync(DidChangeConfigurationParams request, RequestContext requestContext, CancellationToken cancellationToken) - => RefreshOptionsAsync(cancellationToken); + public async Task HandleNotificationAsync(DidChangeConfigurationParams request, RequestContext requestContext, CancellationToken cancellationToken) + { + await RefreshOptionsAsync(cancellationToken).ConfigureAwait(false); + + var onChangedList = requestContext.GetRequiredServices(); + foreach (var onConfigurationChanged in onChangedList) + { + await onConfigurationChanged.OnConfigurationChangedAsync(requestContext, cancellationToken).ConfigureAwait(false); + } + } private async Task RefreshOptionsAsync(CancellationToken cancellationToken) { diff --git a/src/LanguageServer/Protocol/IOnConfigurationChanged.cs b/src/LanguageServer/Protocol/IOnConfigurationChanged.cs new file mode 100644 index 0000000000000..772721e33b229 --- /dev/null +++ b/src/LanguageServer/Protocol/IOnConfigurationChanged.cs @@ -0,0 +1,14 @@ +// 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.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.LanguageServer.Handler; + +namespace Microsoft.CodeAnalysis.LanguageServer; + +internal interface IOnConfigurationChanged +{ + Task OnConfigurationChangedAsync(RequestContext context, CancellationToken cancellationToken); +} diff --git a/src/Tools/ExternalAccess/Razor/Features/Cohost/ICohostConfigurationChangedService.cs b/src/Tools/ExternalAccess/Razor/Features/Cohost/ICohostConfigurationChangedService.cs new file mode 100644 index 0000000000000..3ff98708bf93b --- /dev/null +++ b/src/Tools/ExternalAccess/Razor/Features/Cohost/ICohostConfigurationChangedService.cs @@ -0,0 +1,13 @@ +// 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.Threading; +using System.Threading.Tasks; + +namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; + +internal interface ICohostConfigurationChangedService +{ + Task OnConfigurationChangedAsync(RazorCohostRequestContext requestContext, CancellationToken cancellationToken); +} diff --git a/src/Tools/ExternalAccess/Razor/Features/Cohost/RazorConfigurationChangedServiceFactory.cs b/src/Tools/ExternalAccess/Razor/Features/Cohost/RazorConfigurationChangedServiceFactory.cs new file mode 100644 index 0000000000000..83371b4a1a4e7 --- /dev/null +++ b/src/Tools/ExternalAccess/Razor/Features/Cohost/RazorConfigurationChangedServiceFactory.cs @@ -0,0 +1,46 @@ +// 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; +using System.Composition; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.LanguageServer; +using Microsoft.CodeAnalysis.LanguageServer.Handler; + +namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; + +[ExportCSharpVisualBasicLspServiceFactory(typeof(RazorConfigurationChangedService)), Shared] +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class RazorConfigurationChangedServiceFactory( + [Import(AllowDefault = true)] Lazy? cohostConfigurationChangedService) : ILspServiceFactory +{ + public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind) + { + return new RazorConfigurationChangedService(cohostConfigurationChangedService); + } + + private class RazorConfigurationChangedService( + Lazy? cohostConfigurationChangedService) : ILspService, IOnConfigurationChanged + { + public Task OnConfigurationChangedAsync(RequestContext context, CancellationToken cancellationToken) + { + if (context.ServerKind is not (WellKnownLspServerKinds.AlwaysActiveVSLspServer or WellKnownLspServerKinds.CSharpVisualBasicLspServer)) + { + return Task.CompletedTask; + } + + if (cohostConfigurationChangedService is null) + { + return Task.CompletedTask; + } + + using var languageScope = context.Logger.CreateLanguageContext(Constants.RazorLanguageName); + var requestContext = new RazorCohostRequestContext(context); + return cohostConfigurationChangedService.Value.OnConfigurationChangedAsync(requestContext, cancellationToken); + } + } +}