Skip to content

Commit 6ef629c

Browse files
Make RazorFileChangeDetectorManager implement IOnInitialized
1 parent e3594cd commit 6ef629c

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public static void AddDocumentManagementServices(this IServiceCollection service
212212
services.AddSingleton<IRazorStartupService, OpenDocumentGenerator>();
213213
services.AddSingleton<IRazorDocumentMappingService, RazorDocumentMappingService>();
214214
services.AddSingleton<RazorFileChangeDetectorManager>();
215+
services.AddSingleton<IOnInitialized>(sp => sp.GetRequiredService<RazorFileChangeDetectorManager>());
215216

216217
if (featureOptions.UseProjectConfigurationEndpoint)
217218
{

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileChangeDetectorManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
using System.Linq;
88
using System.Threading;
99
using System.Threading.Tasks;
10+
using Microsoft.CommonLanguageServerProtocol.Framework;
1011

1112
namespace Microsoft.AspNetCore.Razor.LanguageServer;
1213

1314
internal class RazorFileChangeDetectorManager(
1415
WorkspaceDirectoryPathResolver workspaceDirectoryPathResolver,
15-
IEnumerable<IFileChangeDetector> fileChangeDetectors) : IDisposable
16+
IEnumerable<IFileChangeDetector> fileChangeDetectors) : IOnInitialized, IDisposable
1617
{
1718
private readonly WorkspaceDirectoryPathResolver _workspaceDirectoryPathResolver = workspaceDirectoryPathResolver;
1819
private readonly ImmutableArray<IFileChangeDetector> _fileChangeDetectors = fileChangeDetectors.ToImmutableArray();
1920
private readonly object _disposeLock = new();
2021
private bool _disposed;
2122

22-
public async Task InitializedAsync(CancellationToken cancellationToken)
23+
public async Task OnInitializedAsync(ILspServices services, CancellationToken cancellationToken)
2324
{
2425
// Initialized request, this occurs once the server and client have agreed on what sort of features they both support. It only happens once.
2526

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorInitializedEndpoint.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public async Task HandleNotificationAsync(InitializedParams request, RazorReques
2020
{
2121
var onStartedItems = requestContext.LspServices.GetRequiredServices<IOnInitialized>();
2222

23-
var fileChangeDetectorManager = requestContext.LspServices.GetRequiredService<RazorFileChangeDetectorManager>();
24-
await fileChangeDetectorManager.InitializedAsync(cancellationToken).ConfigureAwait(false);
25-
2623
foreach (var onStartedItem in onStartedItems)
2724
{
2825
await onStartedItem.OnInitializedAsync(requestContext.LspServices, cancellationToken).ConfigureAwait(false);

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorFileChangeDetectorManagerTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public async Task InitializedAsync_StartsFileChangeDetectors()
6060
using (var detectorManager = new RazorFileChangeDetectorManager(workspaceDirectoryPathResolver, [detectorMock1.Object, detectorMock2.Object]))
6161
{
6262
// Act
63-
await detectorManager.InitializedAsync(DisposalToken);
63+
await detectorManager.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
6464
}
6565

6666
// Assert
@@ -98,7 +98,7 @@ public async Task InitializedAsync_Disposed_ReStopsFileChangeDetectors()
9898
using var detectorManager = new RazorFileChangeDetectorManager(workspaceDirectoryPathResolver, [detectorMock.Object]);
9999

100100
// Act
101-
var initializeTask = detectorManager.InitializedAsync(DisposalToken);
101+
var initializeTask = detectorManager.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
102102
detectorManager.Dispose();
103103

104104
// Unblock the detector start

0 commit comments

Comments
 (0)