Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume new Razor EA #74134

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidwengier not for right now, but is there a reason we don't just take a workspace in the constructor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea off the top of my head. Maybe left over from something we used to need to do to avoid a circular MEF dependency?

_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
Loading