Skip to content

Commit f22b494

Browse files
authored
Port document color endpoints to cohosting in VS Code (#11775)
Part of #11759 Razor side of dotnet/vscode-csharp#8210 This PR does the infra for html requests in cohosting, and ports document color as the first test case. It's extremely simple after the re-layering PR from the other day :)
2 parents 19b46b4 + 564a0c6 commit f22b494

File tree

14 files changed

+145
-20
lines changed

14 files changed

+145
-20
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
using Microsoft.AspNetCore.Razor;
88
using Microsoft.CodeAnalysis;
99
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
10+
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
1011

1112
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
1213

1314
#pragma warning disable RS0030 // Do not use banned APIs
1415
[Shared]
1516
[CohostEndpoint(Methods.TextDocumentColorPresentationName)]
16-
[ExportCohostStatelessLspService(typeof(CohostColorPresentationEndpoint))]
17+
[ExportRazorStatelessLspService(typeof(CohostColorPresentationEndpoint))]
1718
[method: ImportingConstructor]
1819
#pragma warning restore RS0030 // Do not use banned APIs
1920
internal sealed class CohostColorPresentationEndpoint(
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
using Microsoft.AspNetCore.Razor;
99
using Microsoft.CodeAnalysis;
1010
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
11+
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
1112

1213
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
1314

1415
#pragma warning disable RS0030 // Do not use banned APIs
1516
[Shared]
1617
[CohostEndpoint(Methods.TextDocumentDocumentColorName)]
1718
[Export(typeof(IDynamicRegistrationProvider))]
18-
[ExportCohostStatelessLspService(typeof(CohostDocumentColorEndpoint))]
19+
[ExportRazorStatelessLspService(typeof(CohostDocumentColorEndpoint))]
1920
[method: ImportingConstructor]
2021
#pragma warning restore RS0030 // Do not use banned APIs
2122
internal sealed class CohostDocumentColorEndpoint(
@@ -30,16 +31,11 @@ internal sealed class CohostDocumentColorEndpoint(
3031

3132
public ImmutableArray<Registration> GetRegistrations(VSInternalClientCapabilities clientCapabilities, RazorCohostRequestContext requestContext)
3233
{
33-
if (clientCapabilities.SupportsVisualStudioExtensions)
34+
return [new Registration
3435
{
35-
return [new Registration
36-
{
37-
Method = Methods.TextDocumentDocumentColorName,
38-
RegisterOptions = new DocumentColorRegistrationOptions()
39-
}];
40-
}
41-
42-
return [];
36+
Method = Methods.TextDocumentDocumentColorName,
37+
RegisterOptions = new DocumentColorRegistrationOptions()
38+
}];
4339
}
4440

4541
protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(DocumentColorParams request)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Threading;
66
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Razor;
78
using Microsoft.CodeAnalysis;
89

910
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
@@ -33,7 +34,7 @@ private void Start(TextDocument document, Func<TextDocument, CancellationToken,
3334
_cts.Token.Register(Dispose);
3435
_ = syncFunction.Invoke(document, _cts.Token).ContinueWith((t, state) =>
3536
{
36-
var tcs = (TaskCompletionSource<bool>)state;
37+
var tcs = (TaskCompletionSource<bool>)state.AssumeNotNull();
3738
if (t.IsCanceled)
3839
{
3940
tcs.SetResult(false);

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Microsoft.CodeAnalysis.Razor.CohostingShared.projitems

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
<Compile Include="$(MSBuildThisFileDirectory)CohostEndpointAttribute.cs" />
1313
<Compile Include="$(MSBuildThisFileDirectory)CohostDocSyncEndpointRegistration.cs" />
1414
<Compile Include="$(MSBuildThisFileDirectory)CohostStartupService.cs" />
15+
<Compile Include="$(MSBuildThisFileDirectory)DocumentColor\CohostColorPresentationEndpoint.cs" />
16+
<Compile Include="$(MSBuildThisFileDirectory)DocumentColor\CohostDocumentColorEndpoint.cs" />
1517
<Compile Include="$(MSBuildThisFileDirectory)DocumentSymbol\CohostDocumentSymbolEndpoint.cs" />
18+
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocumentServices\HtmlDocumentSynchronizer.cs" />
19+
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocumentServices\HtmlDocumentSynchronizer.RazorDocumentVersion.cs" />
20+
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocumentServices\HtmlDocumentSynchronizer.SynchronizationRequest.cs" />
21+
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocumentServices\IHtmlDocumentPublisher.cs" />
22+
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocumentServices\IHtmlDocumentSynchronizer.cs" />
23+
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocumentServices\HtmlRequestInvokerExtensions.cs" />
24+
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocumentServices\IHtmlRequestInvoker.cs" />
1625
<Compile Include="$(MSBuildThisFileDirectory)InlayHints\CohostInlayHintEndpoint.cs" />
1726
<Compile Include="$(MSBuildThisFileDirectory)InlayHints\CohostInlayHintResolveEndpoint.cs" />
1827
<Compile Include="$(MSBuildThisFileDirectory)IRazorCohostStartupService.cs" />

0 commit comments

Comments
 (0)