Skip to content

Commit

Permalink
Consume new Razor EA (#74134)
Browse files Browse the repository at this point in the history
Update to open a named pipe communication to rzls
  • Loading branch information
ryzngard committed Jun 28, 2024
1 parent 5e84fbf commit 7039c4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion eng/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<PackageVersion Include="NuGet.ProjectModel" Version="6.8.0-rc.112" />
<PackageVersion Include="Microsoft.TestPlatform.TranslationLayer" Version="$(MicrosoftTestPlatformVersion)" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="$(MicrosoftTestPlatformVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace" Version="9.0.0-preview.24316.1" />
<PackageVersion Include="Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace" Version="9.0.0-preview.24327.6" />

<!--
Analyzers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Composition;
using System.Text.Json.Serialization;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CommonLanguageServerProtocol.Framework;
Expand All @@ -11,7 +12,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace;

[ExportCSharpVisualBasicStatelessLspService(typeof(RazorInitializeHandler)), Shared]
[Method("razor/initialize")]
internal class RazorInitializeHandler : ILspServiceNotificationHandler<object>
internal class RazorInitializeHandler : ILspServiceNotificationHandler<RazorInitializeParams>
{
private readonly Lazy<RazorWorkspaceListenerInitializer> _razorWorkspaceListenerInitializer;

Expand All @@ -25,10 +26,16 @@ public RazorInitializeHandler(Lazy<RazorWorkspaceListenerInitializer> razorWorks
public bool MutatesSolutionState => false;
public bool RequiresLSPSolution => false;

Task INotificationHandler<object, RequestContext>.HandleNotificationAsync(object request, RequestContext requestContext, CancellationToken cancellationToken)
Task INotificationHandler<RazorInitializeParams, RequestContext>.HandleNotificationAsync(RazorInitializeParams request, RequestContext requestContext, CancellationToken cancellationToken)
{
_razorWorkspaceListenerInitializer.Value.Initialize();
_razorWorkspaceListenerInitializer.Value.Initialize(request.PipeName);

return Task.CompletedTask;
}
}

internal class RazorInitializeParams
{
[JsonPropertyName("pipeName")]
public required string PipeName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace;
[Export(typeof(RazorWorkspaceListenerInitializer)), Shared]
internal sealed class RazorWorkspaceListenerInitializer
{
// This should be moved to the Razor side once things are announced, so defaults are all in one
// place, in case things ever need to change
private const string _projectRazorJsonFileName = "project.razor.vscode.bin";

private readonly ILogger _logger;
private readonly Workspace _workspace;
private readonly ILoggerFactory _loggerFactory;
Expand All @@ -36,7 +32,7 @@ public RazorWorkspaceListenerInitializer(LanguageServerWorkspaceFactory workspac
_loggerFactory = loggerFactory;
}

internal void Initialize()
internal void Initialize(string pipeName)
{
HashSet<ProjectId> projectsToInitialize;
lock (_initializeGate)
Expand All @@ -47,9 +43,9 @@ internal void Initialize()
return;
}

_logger.LogTrace("Initializing the Razor workspace listener");
_logger.LogTrace("Initializing the Razor workspace listener with pipe name {0}", pipeName);
_razorWorkspaceListener = new RazorWorkspaceListener(_loggerFactory);
_razorWorkspaceListener.EnsureInitialized(_workspace, _projectRazorJsonFileName);
_razorWorkspaceListener.EnsureInitialized(_workspace, pipeName);

projectsToInitialize = _projectIdWithDynamicFiles;
// May as well clear out the collection, it will never get used again anyway.
Expand Down

0 comments on commit 7039c4c

Please sign in to comment.