Skip to content

Commit

Permalink
Initial cohost server implementation (#9674)
Browse files Browse the repository at this point in the history
First part of #9519
Razor side of dotnet/roslyn#70819

This PR consumes the new Cohost server from Roslyn, and when enabled,
moves DocumentColor requests from being handled by our existing Razor
Language Server, to instead be handled by the new server. There is
currently no sharing of project system data or anything like that yet. A
few TODOs for follow ups, ~can't be merged, and indeed won't build,
until a Roslyn package is available etc. but~ it's reviewable while we
keep working, and more important its shippable in its "off" state.

~Ignore the last commit, obviously won't be merged :)~
  • Loading branch information
davidwengier committed Jan 4, 2024
2 parents 376aca3 + 463f869 commit 13d3145
Show file tree
Hide file tree
Showing 35 changed files with 481 additions and 177 deletions.
1 change: 1 addition & 0 deletions Razor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{4CAC99E0-6ECE-4264-96C3-AF4EEE7BC9D1}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
NuGet.config = NuGet.config
SpellingExclusions.dic = SpellingExclusions.dic
eng\Versions.props = eng\Versions.props
EndProjectSection
Expand Down
72 changes: 36 additions & 36 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,78 @@
<Sha>2a008ae4f42c0db384db5a4864752b2ff52d720b</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
<SourceBuild RepoName="roslyn" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="4.9.0-1.23530.5">
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="4.9.0-3.23613.4">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>5a41731d6717929d437137c1d0373135b5af88a0</Sha>
<Sha>93677976e310e7f910f289e962566485cbabf8f3</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
Expand Down
36 changes: 18 additions & 18 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@
<MicrosoftNETCoreBrowserDebugHostTransportPackageVersion>6.0.2-servicing.22064.6</MicrosoftNETCoreBrowserDebugHostTransportPackageVersion>
<MicrosoftNETCorePlatformsPackageVersion>6.0.1</MicrosoftNETCorePlatformsPackageVersion>
<MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>9.0.0-alpha.1.23627.2</MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.9.0-1.23530.5</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.9.0-1.23530.5</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.9.0-1.23530.5</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftVisualStudioLanguageServicesPackageVersion>4.9.0-1.23530.5</MicrosoftVisualStudioLanguageServicesPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.9.0-3.23613.4</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.9.0-3.23613.4</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.9.0-3.23613.4</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftVisualStudioLanguageServicesPackageVersion>4.9.0-3.23613.4</MicrosoftVisualStudioLanguageServicesPackageVersion>
<MicrosoftDotNetXliffTasksPackageVersion>1.0.0-beta.23475.1</MicrosoftDotNetXliffTasksPackageVersion>
<!--
Exception - Microsoft.Extensions.ObjectPool and System.Collections.Immutable packages are not updated by automation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Composition;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -11,7 +12,9 @@

namespace Microsoft.AspNetCore.Razor.LanguageServer.Common;

internal class DefaultRemoteTextLoaderFactory : RemoteTextLoaderFactory
[Export(typeof(RemoteTextLoaderFactory)), Shared]
[method: ImportingConstructor]
internal class DefaultRemoteTextLoaderFactory() : RemoteTextLoaderFactory
{
public override TextLoader Create(string filePath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class ConfigurableLanguageServerFeatureOptions : LanguageServerFeatureO
private readonly bool? _updateBuffersForClosedDocuments;
private readonly bool? _includeProjectKeyInGeneratedFilePath;
private readonly bool? _monitorWorkspaceFolderForConfigurationFiles;
private readonly bool? _useRazorCohostServer;

public override bool SupportsFileManipulation => _supportsFileManipulation ?? _defaults.SupportsFileManipulation;
public override string ProjectConfigurationFileName => _projectConfigurationFileName ?? _defaults.ProjectConfigurationFileName;
Expand All @@ -37,6 +38,7 @@ internal class ConfigurableLanguageServerFeatureOptions : LanguageServerFeatureO
public override bool UpdateBuffersForClosedDocuments => _updateBuffersForClosedDocuments ?? _defaults.UpdateBuffersForClosedDocuments;
public override bool IncludeProjectKeyInGeneratedFilePath => _includeProjectKeyInGeneratedFilePath ?? _defaults.IncludeProjectKeyInGeneratedFilePath;
public override bool MonitorWorkspaceFolderForConfigurationFiles => _monitorWorkspaceFolderForConfigurationFiles ?? _defaults.MonitorWorkspaceFolderForConfigurationFiles;
public override bool UseRazorCohostServer => _useRazorCohostServer ?? _defaults.UseRazorCohostServer;

public ConfigurableLanguageServerFeatureOptions(string[] args)
{
Expand All @@ -60,6 +62,7 @@ public ConfigurableLanguageServerFeatureOptions(string[] args)
TryProcessBoolOption(nameof(UpdateBuffersForClosedDocuments), ref _updateBuffersForClosedDocuments, option, args, i);
TryProcessBoolOption(nameof(IncludeProjectKeyInGeneratedFilePath), ref _includeProjectKeyInGeneratedFilePath, option, args, i);
TryProcessBoolOption(nameof(MonitorWorkspaceFolderForConfigurationFiles), ref _monitorWorkspaceFolderForConfigurationFiles, option, args, i);
TryProcessBoolOption(nameof(UseRazorCohostServer), ref _useRazorCohostServer, option, args, i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash
public override bool UsePreciseSemanticTokenRanges => false;

public override bool MonitorWorkspaceFolderForConfigurationFiles => true;

public override bool UseRazorCohostServer => false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,26 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentColor;

[LanguageServerEndpoint(Methods.TextDocumentDocumentColorName)]
internal sealed class DocumentColorEndpoint : IRazorRequestHandler<DocumentColorParams, ColorInformation[]>, ICapabilitiesProvider
internal sealed class DocumentColorEndpoint(IDocumentColorService documentColorService, IClientConnection clientConnection) : IRazorRequestHandler<DocumentColorParams, ColorInformation[]>, ICapabilitiesProvider
{
private readonly IClientConnection _clientConnection;

public DocumentColorEndpoint(IClientConnection clientConnection)
{
_clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection));
}
private readonly IDocumentColorService _documentColorService = documentColorService ?? throw new ArgumentNullException(nameof(documentColorService));
private readonly IClientConnection _clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection));

public bool MutatesSolutionState => false;

public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, VSInternalClientCapabilities clientCapabilities)
{
serverCapabilities.DocumentColorProvider = new DocumentColorOptions();
}
=> _documentColorService.ApplyCapabilities(serverCapabilities, clientCapabilities);

public TextDocumentIdentifier GetTextDocumentIdentifier(DocumentColorParams request)
=> request.TextDocument;

public async Task<ColorInformation[]> HandleRequestAsync(DocumentColorParams request, RazorRequestContext requestContext, CancellationToken cancellationToken)
{
// Workaround for Web Tools bug https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1743689 where they sometimes
// send requests for filenames that are stale, possibly due to adornment taggers being cached incorrectly (or caching
// filenames incorrectly)
if (requestContext.DocumentContext is null)
{
return Array.Empty<ColorInformation>();
}

var delegatedRequest = new DelegatedDocumentColorParams()
{
HostDocumentVersion = requestContext.GetRequiredDocumentContext().Version,
TextDocument = request.TextDocument
};

var documentColors = await _clientConnection.SendRequestAsync<DelegatedDocumentColorParams, ColorInformation[]>(
CustomMessageNames.RazorProvideHtmlDocumentColorEndpoint,
delegatedRequest,
cancellationToken).ConfigureAwait(false);

if (documentColors is null)
{
return Array.Empty<ColorInformation>();
}

// HTML and Razor documents have identical mapping locations. Because of this we can return the result as-is.
return documentColors;
}
public Task<ColorInformation[]> HandleRequestAsync(DocumentColorParams request, RazorRequestContext requestContext, CancellationToken cancellationToken)
=> _documentColorService.GetColorInformationAsync(_clientConnection, request, requestContext.DocumentContext, cancellationToken);
}
Loading

0 comments on commit 13d3145

Please sign in to comment.