Skip to content

Commit 3c95e8c

Browse files
committed
Add a proper initializer, rather that abusing dynamic files
1 parent 0a57d82 commit 3c95e8c

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/DynamicFileProviderFactory.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ namespace Microsoft.VisualStudioCode.RazorExtension.Services;
1111
[ExportRazorLspServiceFactory(typeof(RazorLspDynamicFileInfoProvider)), Shared]
1212
[method: ImportingConstructor]
1313
internal sealed class DynamicFileProviderFactory(
14-
LanguageServerFeatureOptions featureOptions,
15-
VSCodeWorkspaceProvider workspaceProvider) : AbstractRazorLspServiceFactory
14+
LanguageServerFeatureOptions featureOptions) : AbstractRazorLspServiceFactory
1615
{
1716
private readonly LanguageServerFeatureOptions _featureOptions = featureOptions;
18-
private readonly VSCodeWorkspaceProvider _workspaceProvider = workspaceProvider;
1917

2018
protected override AbstractRazorLspService CreateService(IRazorLspServices lspServices)
2119
{
2220
var clientLanguageServerManager = lspServices.GetRequiredService<IRazorClientLanguageServerManager>();
23-
return new LspDynamicFileProvider(clientLanguageServerManager, _featureOptions, _workspaceProvider);
21+
return new LspDynamicFileProvider(clientLanguageServerManager, _featureOptions);
2422
}
2523
}
2624

src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/LspDynamicFileProvider.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,16 @@ namespace Microsoft.VisualStudioCode.RazorExtension.Services;
1414

1515
internal sealed partial class LspDynamicFileProvider(
1616
IRazorClientLanguageServerManager clientLanguageServerManager,
17-
LanguageServerFeatureOptions languageServerFeatureOptions,
18-
VSCodeWorkspaceProvider workspaceProvider) : RazorLspDynamicFileInfoProvider
17+
LanguageServerFeatureOptions languageServerFeatureOptions) : RazorLspDynamicFileInfoProvider
1918
{
2019
private const string ProvideRazorDynamicFileInfoMethodName = "razor/provideDynamicFileInfo";
2120
private const string RemoveRazorDynamicFileInfoMethodName = "razor/removeDynamicFileInfo";
2221

2322
private readonly IRazorClientLanguageServerManager _clientLanguageServerManager = clientLanguageServerManager;
2423
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions;
25-
private readonly VSCodeWorkspaceProvider _workspaceProvider = workspaceProvider;
2624

2725
public override async Task<RazorDynamicFileInfo?> GetDynamicFileInfoAsync(Workspace workspace, ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken)
2826
{
29-
// TODO: Temporarily using this as a hook to get the workspace into cohosting. In future when we delete the IDynamicFileInfo
30-
// system as a whole, we'll need some other hook to get to the LspWorkspace
31-
_workspaceProvider.SetWorkspace(workspace);
32-
3327
if (_languageServerFeatureOptions.UseRazorCohostServer)
3428
{
3529
return null;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Composition;
5+
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
6+
using Microsoft.CodeAnalysis;
7+
8+
namespace Microsoft.VisualStudioCode.RazorExtension.Services;
9+
10+
[Shared]
11+
[ExportRazorStatelessLspService(typeof(AbstractRazorInitializer))]
12+
[method: ImportingConstructor]
13+
internal sealed class RazorInitializer(VSCodeWorkspaceProvider workspaceProvider) : AbstractRazorInitializer
14+
{
15+
private readonly VSCodeWorkspaceProvider _workspaceProvider = workspaceProvider;
16+
17+
internal override void Initialize(Workspace workspace)
18+
{
19+
_workspaceProvider.SetWorkspace(workspace);
20+
}
21+
}

0 commit comments

Comments
 (0)