diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostSemanticTokensRangeEndpointTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostSemanticTokensRangeEndpointTest.cs index 02d79678d9..760defdd87 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostSemanticTokensRangeEndpointTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostSemanticTokensRangeEndpointTest.cs @@ -101,13 +101,13 @@ public class CohostSemanticTokensRangeEndpointTest(ITestOutputHelper testOutputH var legendService = OOPExportProvider.GetExportedValue(); legendService.SetLegend(legend.TokenTypes.All, legend.TokenModifiers.All); - var featureOptions = OOPExportProvider.GetExportedValue(); - featureOptions.SetOptions(_clientInitializationOptions with { UsePreciseSemanticTokenRanges = precise }); + // Update the client initialization options to control the precise ranges option + UpdateClientInitializationOptions(c => c with { UsePreciseSemanticTokenRanges = precise }); var clientSettingsManager = new ClientSettingsManager([], null, null); clientSettingsManager.Update(ClientAdvancedSettings.Default with { ColorBackground = colorBackground }); - var endpoint = new CohostSemanticTokensRangeEndpoint(RemoteServiceProvider, clientSettingsManager, legend, NoOpTelemetryReporter.Instance, LoggerFactory); + var endpoint = new CohostSemanticTokensRangeEndpoint(RemoteServiceInvoker, clientSettingsManager, legend, NoOpTelemetryReporter.Instance, LoggerFactory); var span = new LinePositionSpan(new(0, 0), new(sourceText.Lines.Count, 0)); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostTestBase.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostTestBase.cs index 139a7fa3e5..47cd7bd476 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostTestBase.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostTestBase.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. +using System; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Razor.Remote; using Microsoft.CodeAnalysis.Remote.Razor; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Composition; @@ -22,8 +24,8 @@ public abstract class CohostTestBase(ITestOutputHelper testOutputHelper) : Works private const string CSharpVirtualDocumentSuffix = ".g.cs"; private ExportProvider? _exportProvider; private TestRemoteServiceInvoker? _remoteServiceInvoker; + private RemoteClientInitializationOptions _clientInitializationOptions; - private protected RemoteClientInitializationOptions _clientInitializationOptions; private protected TestRemoteServiceInvoker RemoteServiceInvoker => _remoteServiceInvoker.AssumeNotNull(); /// @@ -37,13 +39,12 @@ public abstract class CohostTestBase(ITestOutputHelper testOutputHelper) : Works // Create a new isolated MEF composition. // Note that this uses a cached catalog and configuration for performance. - var exportProvider = await RemoteMefComposition.CreateExportProviderAsync(DisposalToken); - AddDisposable(exportProvider); + _exportProvider = await RemoteMefComposition.CreateExportProviderAsync(DisposalToken); + AddDisposable(_exportProvider); - _remoteServiceInvoker = new TestRemoteServiceInvoker(JoinableTaskContext, exportProvider, LoggerFactory); + _remoteServiceInvoker = new TestRemoteServiceInvoker(JoinableTaskContext, _exportProvider, LoggerFactory); AddDisposable(_remoteServiceInvoker); - var featureOptions = OOPExportProvider.GetExportedValue(); _clientInitializationOptions = new() { CSharpVirtualDocumentSuffix = CSharpVirtualDocumentSuffix, @@ -52,7 +53,13 @@ public abstract class CohostTestBase(ITestOutputHelper testOutputHelper) : Works UsePreciseSemanticTokenRanges = false, UseRazorCohostServer = true }; + UpdateClientInitializationOptions(c => c); + } + private protected void UpdateClientInitializationOptions(Func mutation) + { + _clientInitializationOptions = mutation(_clientInitializationOptions); + var featureOptions = OOPExportProvider.GetExportedValue(); featureOptions.SetOptions(_clientInitializationOptions); }