Skip to content

Commit

Permalink
Cohosting: Add semantic tokens support, via Roslyn OOP (#10097)
Browse files Browse the repository at this point in the history
Part of #9519

This PR feels like the last month of my life, with most of that time
simply fighting ServiceHub.

This adds a new endpoint for the cohosting server to support semantic
tokens. It's the first endpoint in the server. (Almost) the only thing
it does is immediately call our to the OOP process to do the actual
work. Logic is mainly provided by the same service that the existing
semantic tokens endpoint uses, but for a small piece of functionality
that is plugged in, via MEF, to call Roslyn via a new C# API
(dotnet/roslyn#72495) instead of via LSP.
Currently the syntax tree is computed on the fly in OOP, and the
document Roslyn is asked about is the one that the LSP server creates
via IDynamicFile. In future this will change to get the real source
generated document, and data from the source generator for the tree etc.

Reviewing commit-at-a-time is probably best. There are still a bunch of
TODOs, some hard-coded bits, and some hacky bits, but I wanted to ensure
this was actually reviewable and not too big.

Worth nothing this won't build until the Roslyn PR mentioned above is
merged, and a new package is available to update to.
  • Loading branch information
davidwengier authored Mar 20, 2024
2 parents eb9363d + a220f73 commit 3c2dca5
Show file tree
Hide file tree
Showing 86 changed files with 1,410 additions and 571 deletions.
76 changes: 38 additions & 38 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,82 @@
<Sha>c0b5d69a1a1513528c77fffff708c7502d57c35c</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.10.0-2.24112.8">
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.10.0-3.24169.7">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>d8f4c5e29b3f988279ea48842eeba3b4c884e72a</Sha>
<Sha>98cd097bf122677378692ebe952b71ab6e5bb013</Sha>
<SourceBuild RepoName="roslyn" ManagedOnly="true" />
</Dependency>
</ProductDependencies>
Expand Down
46 changes: 23 additions & 23 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@
<MicrosoftSourceBuildIntermediatearcadePackageVersion>8.0.0-beta.24165.4</MicrosoftSourceBuildIntermediatearcadePackageVersion>
<MicrosoftDotNetXliffTasksPackageVersion>1.0.0-beta.23475.1</MicrosoftDotNetXliffTasksPackageVersion>
<MicrosoftSourceBuildIntermediatexlifftasksPackageVersion>1.0.0-beta.23475.1</MicrosoftSourceBuildIntermediatexlifftasksPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.10.0-2.24112.8</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.10.0-2.24112.8</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.10.0-2.24112.8</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftSourceBuildIntermediateroslynPackageVersion>4.10.0-2.24112.8</MicrosoftSourceBuildIntermediateroslynPackageVersion>
<MicrosoftVisualStudioLanguageServicesPackageVersion>4.10.0-2.24112.8</MicrosoftVisualStudioLanguageServicesPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.10.0-3.24169.7</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.10.0-3.24169.7</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.10.0-3.24169.7</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftSourceBuildIntermediateroslynPackageVersion>4.10.0-3.24169.7</MicrosoftSourceBuildIntermediateroslynPackageVersion>
<MicrosoftVisualStudioLanguageServicesPackageVersion>4.10.0-3.24169.7</MicrosoftVisualStudioLanguageServicesPackageVersion>
<!--
Exception - Microsoft.Extensions.ObjectPool and System.Collections.Immutable packages are not updated by automation,
but are present in Version.Details.xml for source-build PVP flow. See the comment in Version.Details.xml for more information.
Expand All @@ -97,7 +97,7 @@
<MicrosoftVisualStudioCopilotVersion>0.2.28-beta</MicrosoftVisualStudioCopilotVersion>
<!-- dotnet/runtime packages -->
<MicrosoftExtensionsPackageVersion>6.0.0</MicrosoftExtensionsPackageVersion>
<SystemCompositionPackageVersion>7.0.0</SystemCompositionPackageVersion>
<SystemCompositionPackageVersion>8.0.0</SystemCompositionPackageVersion>
<SystemDiagnosticsDiagnosticSourcePackageVersion>6.0.0</SystemDiagnosticsDiagnosticSourcePackageVersion>
<SystemResourcesExtensionsPackageVersion>6.0.0</SystemResourcesExtensionsPackageVersion>
<SystemTextEncodingsWebPackageVersion>6.0.0</SystemTextEncodingsWebPackageVersion>
Expand Down Expand Up @@ -130,12 +130,12 @@
<MicrosoftVisualStudioShellFrameworkPackageVersion>$(MicrosoftVisualStudioShellPackagesVersion)</MicrosoftVisualStudioShellFrameworkPackageVersion>
<MicrosoftVisualStudioInteropPackageVersion>$(MicrosoftVisualStudioShellPackagesVersion)</MicrosoftVisualStudioInteropPackageVersion>
<MicrosoftInternalVisualStudioInteropPackageVersion>$(MicrosoftVisualStudioShellPackagesVersion)</MicrosoftInternalVisualStudioInteropPackageVersion>
<MicrosoftVisualStudioRpcContractsPackageVersion>17.9.7</MicrosoftVisualStudioRpcContractsPackageVersion>
<MicrosoftVisualStudioTelemetryVersion>17.9.13</MicrosoftVisualStudioTelemetryVersion>
<MicrosoftVisualStudioRpcContractsPackageVersion>17.10.3-preview</MicrosoftVisualStudioRpcContractsPackageVersion>
<MicrosoftVisualStudioTelemetryVersion>17.9.102</MicrosoftVisualStudioTelemetryVersion>
<MicrosoftVisualStudioTextDataPackageVersion>$(MicrosoftVisualStudioPackagesVersion)</MicrosoftVisualStudioTextDataPackageVersion>
<MicrosoftVisualStudioTextImplementationPackageVersion>$(MicrosoftVisualStudioPackagesVersion)</MicrosoftVisualStudioTextImplementationPackageVersion>
<MicrosoftVisualStudioTextLogicPackageVersion>$(MicrosoftVisualStudioPackagesVersion)</MicrosoftVisualStudioTextLogicPackageVersion>
<MicrosoftVisualStudioThreadingPackageVersion>17.9.27</MicrosoftVisualStudioThreadingPackageVersion>
<MicrosoftVisualStudioThreadingPackageVersion>17.10.12-preview</MicrosoftVisualStudioThreadingPackageVersion>
<MicrosoftVisualStudioWebPackageVersion>16.10.0-preview-1-31008-014</MicrosoftVisualStudioWebPackageVersion>
<MicrosoftVisualStudioValidationPackageVersion>17.8.8</MicrosoftVisualStudioValidationPackageVersion>
<MicrosoftVisualStudioComponentModelHostPackageVersion>17.9.132-preview</MicrosoftVisualStudioComponentModelHostPackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Razor.LanguageServer;
using Microsoft.AspNetCore.Razor.LanguageServer.Semantic;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +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 Microsoft.AspNetCore.Razor.LanguageServer.Semantic;
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.CodeAnalysis.Razor.Completion;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -123,14 +124,17 @@ public static void AddHoverServices(this IServiceCollection services)
services.AddSingleton<IHoverService, HoverService>();
}

public static void AddSemanticTokensServices(this IServiceCollection services)
public static void AddSemanticTokensServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions)
{
services.AddHandlerWithCapabilities<SemanticTokensRangeEndpoint>();
// Ensure that we don't add the default service if something else has added one.
services.TryAddSingleton<IRazorSemanticTokensInfoService, RazorSemanticTokensInfoService>();
services.AddSingleton<ICSharpSemanticTokensProvider, LSPCSharpSemanticTokensProvider>();
if (!featureOptions.UseRazorCohostServer)
{
services.AddHandlerWithCapabilities<SemanticTokensRangeEndpoint>();
// Ensure that we don't add the default service if something else has added one.
services.TryAddSingleton<IRazorSemanticTokensInfoService, RazorSemanticTokensInfoService>();
services.AddSingleton<ICSharpSemanticTokensProvider, LSPCSharpSemanticTokensProvider>();

services.AddSingleton<ISemanticTokensLegendService, RazorSemanticTokensLegendService>();
services.AddSingleton<ISemanticTokensLegendService, RazorSemanticTokensLegendService>();
}

services.AddHandler<RazorSemanticTokensRefreshEndpoint>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected override ILspServices ConstructLspServices()
services.AddLifeCycleServices(this, _clientConnection, _lspServerActivationTracker);

services.AddDiagnosticServices();
services.AddSemanticTokensServices();
services.AddSemanticTokensServices(featureOptions);
services.AddDocumentManagementServices(featureOptions);
services.AddCompletionServices(featureOptions);
services.AddFormattingServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@
<data name="Unknown_ProjectChangeKind" xml:space="preserve">
<value>Unknown ProjectChangeKind {0}</value>
</data>
<data name="Unknown_RazorMetaCode" xml:space="preserve">
<value>Attempted to visit a RazorMetaCode other than '{' or '}'.</value>
</data>
<data name="Version_Should_Not_Be_Null" xml:space="preserve">
<value>Provided version should not be null.</value>
</data>
Expand Down
Loading

0 comments on commit 3c2dca5

Please sign in to comment.