Skip to content

Commit

Permalink
Post merge updates, and rejig of client initialization options
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier committed Jul 16, 2024
1 parent b2dae75 commit 55fee1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ private async Task VerifySemanticTokensAsync(string input, bool colorBackground,
var legendService = OOPExportProvider.GetExportedValue<RemoteSemanticTokensLegendService>();
legendService.SetLegend(legend.TokenTypes.All, legend.TokenModifiers.All);

var featureOptions = OOPExportProvider.GetExportedValue<RemoteLanguageServerFeatureOptions>();
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));

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +11,7 @@
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;
Expand All @@ -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();

/// <summary>
Expand All @@ -37,13 +39,12 @@ protected override async Task InitializeAsync()

// 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<RemoteLanguageServerFeatureOptions>();
_clientInitializationOptions = new()
{
CSharpVirtualDocumentSuffix = CSharpVirtualDocumentSuffix,
Expand All @@ -52,7 +53,13 @@ protected override async Task InitializeAsync()
UsePreciseSemanticTokenRanges = false,
UseRazorCohostServer = true
};
UpdateClientInitializationOptions(c => c);
}

private protected void UpdateClientInitializationOptions(Func<RemoteClientInitializationOptions, RemoteClientInitializationOptions> mutation)
{
_clientInitializationOptions = mutation(_clientInitializationOptions);
var featureOptions = OOPExportProvider.GetExportedValue<RemoteLanguageServerFeatureOptions>();
featureOptions.SetOptions(_clientInitializationOptions);
}

Expand Down

0 comments on commit 55fee1e

Please sign in to comment.