Skip to content

Commit e3594cd

Browse files
Make SnapshotResolver implement IOnInitialized
1 parent 1d7c262 commit e3594cd

17 files changed

+100
-139
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
3636

3737
internal static class IServiceCollectionExtensions
3838
{
39-
public static void AddLifeCycleServices(this IServiceCollection services, RazorLanguageServer razorLanguageServer, ClientConnection serverManager, ILspServerActivationTracker? lspServerActivationTracker)
39+
public static void AddLifeCycleServices(this IServiceCollection services, RazorLanguageServer razorLanguageServer, ClientConnection clientConnection, ILspServerActivationTracker? lspServerActivationTracker)
4040
{
4141
services.AddHandler<RazorInitializeEndpoint>();
4242
services.AddHandler<RazorInitializedEndpoint>();
@@ -51,7 +51,7 @@ public static void AddLifeCycleServices(this IServiceCollection services, RazorL
5151

5252
services.AddSingleton<ICapabilitiesProvider, RazorLanguageServerCapability>();
5353

54-
services.AddSingleton<IOnInitialized>(serverManager);
54+
services.AddSingleton<IOnInitialized>(clientConnection);
5555
}
5656

5757
public static void AddFormattingServices(this IServiceCollection services)
@@ -207,6 +207,7 @@ public static void AddDocumentManagementServices(this IServiceCollection service
207207

208208
services.AddSingleton<RemoteTextLoaderFactory, DefaultRemoteTextLoaderFactory>();
209209
services.AddSingleton<ISnapshotResolver, SnapshotResolver>();
210+
services.AddSingleton<IOnInitialized>(sp => (SnapshotResolver)sp.GetRequiredService<ISnapshotResolver>());
210211
services.AddSingleton<IRazorProjectService, RazorProjectService>();
211212
services.AddSingleton<IRazorStartupService, OpenDocumentGenerator>();
212213
services.AddSingleton<IRazorDocumentMappingService, RazorDocumentMappingService>();

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/ISnapshotResolver.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
1111

1212
internal interface ISnapshotResolver
1313
{
14-
Task InitializeAsync(CancellationToken cancellationToken);
15-
1614
/// <summary>
1715
/// Finds all the projects where the document path starts with the path of the folder that contains the project file.
1816
/// </summary>

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/SnapshotResolver.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
using Microsoft.CodeAnalysis.Razor;
1414
using Microsoft.CodeAnalysis.Razor.Logging;
1515
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
16+
using Microsoft.CommonLanguageServerProtocol.Framework;
1617

1718
namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
1819

19-
internal sealed class SnapshotResolver : ISnapshotResolver
20+
internal sealed class SnapshotResolver : ISnapshotResolver, IOnInitialized
2021
{
2122
private readonly IProjectSnapshotManager _projectManager;
2223
private readonly ILogger _logger;
@@ -34,7 +35,7 @@ public SnapshotResolver(IProjectSnapshotManager projectManager, ILoggerFactory l
3435
MiscellaneousHostProject = new HostProject(normalizedPath, normalizedPath, FallbackRazorConfiguration.Latest, rootNamespace: null, "Miscellaneous Files");
3536
}
3637

37-
public Task InitializeAsync(CancellationToken cancellationToken)
38+
public Task OnInitializedAsync(ILspServices services, CancellationToken cancellationToken)
3839
{
3940
// This is called when the language server is initialized.
4041

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 snapshotResolver = requestContext.LspServices.GetRequiredService<ISnapshotResolver>();
24-
await snapshotResolver.InitializeAsync(cancellationToken).ConfigureAwait(false);
25-
2623
var fileChangeDetectorManager = requestContext.LspServices.GetRequiredService<RazorFileChangeDetectorManager>();
2724
await fileChangeDetectorManager.InitializedAsync(cancellationToken).ConfigureAwait(false);
2825

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultLSPTagHelperTooltipFactoryTest.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public async Task TryCreateTooltip_Markup_NoAssociatedTagHelperDescriptions_Retu
6767
{
6868
// Arrange
6969
var snapshotResolver = new TestSnapshotResolver();
70-
await snapshotResolver.InitializeAsync(DisposalToken);
7170
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
7271
var elementDescription = AggregateBoundElementDescription.Empty;
7372

@@ -83,7 +82,6 @@ public async Task TryCreateTooltip_Markup_Element_SingleAssociatedTagHelper_Retu
8382
{
8483
// Arrange
8584
var snapshotResolver = new TestSnapshotResolver();
86-
await snapshotResolver.InitializeAsync(DisposalToken);
8785
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
8886
var associatedTagHelperInfos = new[]
8987
{
@@ -106,7 +104,6 @@ public async Task TryCreateTooltip_Markup_Element_PlainText_NoBold()
106104
{
107105
// Arrange
108106
var snapshotResolver = new TestSnapshotResolver();
109-
await snapshotResolver.InitializeAsync(DisposalToken);
110107
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
111108
var associatedTagHelperInfos = new[]
112109
{
@@ -126,11 +123,10 @@ public async Task TryCreateTooltip_Markup_Element_PlainText_NoBold()
126123
}
127124

128125
[Fact]
129-
public async Task TryCreateTooltip_Markup_Attribute_PlainText_NoBold()
126+
public void TryCreateTooltip_Markup_Attribute_PlainText_NoBold()
130127
{
131128
// Arrange
132129
var snapshotResolver = new TestSnapshotResolver();
133-
await snapshotResolver.InitializeAsync(DisposalToken);
134130
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
135131
var associatedAttributeDescriptions = new[]
136132
{
@@ -158,7 +154,6 @@ public async Task TryCreateTooltip_Markup_Element_MultipleAssociatedTagHelpers_R
158154
{
159155
// Arrange
160156
var snapshotResolver = new TestSnapshotResolver();
161-
await snapshotResolver.InitializeAsync(DisposalToken);
162157
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
163158
var associatedTagHelperInfos = new[]
164159
{
@@ -183,11 +178,10 @@ public async Task TryCreateTooltip_Markup_Element_MultipleAssociatedTagHelpers_R
183178
}
184179

185180
[Fact]
186-
public async Task TryCreateTooltip_Markup_Attribute_SingleAssociatedAttribute_ReturnsTrue()
181+
public void TryCreateTooltip_Markup_Attribute_SingleAssociatedAttribute_ReturnsTrue()
187182
{
188183
// Arrange
189184
var snapshotResolver = new TestSnapshotResolver();
190-
await snapshotResolver.InitializeAsync(DisposalToken);
191185
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
192186
var associatedAttributeDescriptions = new[]
193187
{
@@ -211,11 +205,10 @@ public async Task TryCreateTooltip_Markup_Attribute_SingleAssociatedAttribute_Re
211205
}
212206

213207
[Fact]
214-
public async Task TryCreateTooltip_Markup_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
208+
public void TryCreateTooltip_Markup_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
215209
{
216210
// Arrange
217211
var snapshotResolver = new TestSnapshotResolver();
218-
await snapshotResolver.InitializeAsync(DisposalToken);
219212
var descriptionFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
220213
var associatedAttributeDescriptions = new[]
221214
{

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/DefaultVSLSPTagHelperTooltipFactoryTest.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ public async Task TryCreateTooltip_ClassifiedTextElement_NoAssociatedTagHelperDe
171171
{
172172
// Arrange
173173
var snapshotResolver = new TestSnapshotResolver();
174-
await snapshotResolver.InitializeAsync(DisposalToken);
175174
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
176175
var elementDescription = AggregateBoundElementDescription.Empty;
177176

@@ -187,7 +186,6 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Element_SingleAssociate
187186
{
188187
// Arrange
189188
var snapshotResolver = new TestSnapshotResolver();
190-
await snapshotResolver.InitializeAsync(DisposalToken);
191189
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
192190
var associatedTagHelperInfos = new[]
193191
{
@@ -229,7 +227,6 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Element_NamespaceContai
229227
{
230228
// Arrange
231229
var snapshotResolver = new TestSnapshotResolver();
232-
await snapshotResolver.InitializeAsync(DisposalToken);
233230
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
234231
var associatedTagHelperInfos = new[]
235232
{
@@ -270,7 +267,6 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Element_MultipleAssocia
270267
{
271268
// Arrange
272269
var snapshotResolver = new TestSnapshotResolver();
273-
await snapshotResolver.InitializeAsync(DisposalToken);
274270
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
275271
var associatedTagHelperInfos = new[]
276272
{
@@ -321,11 +317,10 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Element_MultipleAssocia
321317
}
322318

323319
[Fact]
324-
public async Task TryCreateTooltip_ClassifiedTextElement_NoAssociatedAttributeDescriptions_ReturnsFalse()
320+
public void TryCreateTooltip_ClassifiedTextElement_NoAssociatedAttributeDescriptions_ReturnsFalse()
325321
{
326322
// Arrange
327323
var snapshotResolver = new TestSnapshotResolver();
328-
await snapshotResolver.InitializeAsync(DisposalToken);
329324
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
330325
var elementDescription = AggregateBoundAttributeDescription.Empty;
331326

@@ -338,11 +333,10 @@ public async Task TryCreateTooltip_ClassifiedTextElement_NoAssociatedAttributeDe
338333
}
339334

340335
[Fact]
341-
public async Task TryCreateTooltip_ClassifiedTextElement_Attribute_SingleAssociatedAttribute_ReturnsTrue_NestedTypes()
336+
public void TryCreateTooltip_ClassifiedTextElement_Attribute_SingleAssociatedAttribute_ReturnsTrue_NestedTypes()
342337
{
343338
// Arrange
344339
var snapshotResolver = new TestSnapshotResolver();
345-
await snapshotResolver.InitializeAsync(DisposalToken);
346340
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
347341
var associatedAttributeDescriptions = new[]
348342
{
@@ -388,11 +382,10 @@ public async Task TryCreateTooltip_ClassifiedTextElement_Attribute_SingleAssocia
388382
}
389383

390384
[Fact]
391-
public async Task TryCreateTooltip_ClassifiedTextElement_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
385+
public void TryCreateTooltip_ClassifiedTextElement_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
392386
{
393387
// Arrange
394388
var snapshotResolver = new TestSnapshotResolver();
395-
await snapshotResolver.InitializeAsync(DisposalToken);
396389
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
397390
var associatedAttributeDescriptions = new[]
398391
{
@@ -468,7 +461,6 @@ public async Task TryCreateTooltip_ContainerElement_NoAssociatedTagHelperDescrip
468461
{
469462
// Arrange
470463
var snapshotResolver = new TestSnapshotResolver();
471-
await snapshotResolver.InitializeAsync(DisposalToken);
472464
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
473465
var elementDescription = AggregateBoundElementDescription.Empty;
474466

@@ -484,7 +476,6 @@ public async Task TryCreateTooltip_ContainerElement_Attribute_MultipleAssociated
484476
{
485477
// Arrange
486478
var snapshotResolver = new TestSnapshotResolver();
487-
await snapshotResolver.InitializeAsync(DisposalToken);
488479
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
489480
var associatedTagHelperInfos = new[]
490481
{
@@ -565,11 +556,10 @@ public async Task TryCreateTooltip_ContainerElement_Attribute_MultipleAssociated
565556
}
566557

567558
[Fact]
568-
public async Task TryCreateTooltip_ContainerElement_NoAssociatedAttributeDescriptions_ReturnsFalse()
559+
public void TryCreateTooltip_ContainerElement_NoAssociatedAttributeDescriptions_ReturnsFalse()
569560
{
570561
// Arrange
571562
var snapshotResolver = new TestSnapshotResolver();
572-
await snapshotResolver.InitializeAsync(DisposalToken);
573563
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
574564
var elementDescription = AggregateBoundAttributeDescription.Empty;
575565

@@ -582,11 +572,10 @@ public async Task TryCreateTooltip_ContainerElement_NoAssociatedAttributeDescrip
582572
}
583573

584574
[Fact]
585-
public async Task TryCreateTooltip_ContainerElement_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
575+
public void TryCreateTooltip_ContainerElement_Attribute_MultipleAssociatedAttributes_ReturnsTrue()
586576
{
587577
// Arrange
588578
var snapshotResolver = new TestSnapshotResolver();
589-
await snapshotResolver.InitializeAsync(DisposalToken);
590579
var descriptionFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
591580
var associatedAttributeDescriptions = new[]
592581
{

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/LegacyRazorCompletionResolveEndpointTest.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@
2020

2121
namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion;
2222

23-
public class LegacyRazorCompletionResolveEndpointTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
23+
public class LegacyRazorCompletionResolveEndpointTest : LanguageServerTestBase
2424
{
25-
private LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
26-
private VSLSPTagHelperTooltipFactory _vsLspTagHelperTooltipFactory;
27-
private CompletionListCache _completionListCache;
28-
private VSInternalCompletionSetting _completionCapability;
29-
private VSInternalClientCapabilities _defaultClientCapability;
30-
31-
protected async override Task InitializeAsync()
25+
private readonly LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
26+
private readonly VSLSPTagHelperTooltipFactory _vsLspTagHelperTooltipFactory;
27+
private readonly CompletionListCache _completionListCache;
28+
private readonly VSInternalCompletionSetting _completionCapability;
29+
private readonly VSInternalClientCapabilities _defaultClientCapability;
30+
31+
public LegacyRazorCompletionResolveEndpointTest(ITestOutputHelper testOutput)
32+
: base(testOutput)
3233
{
3334
var snapshotResolver = new TestSnapshotResolver();
34-
await snapshotResolver.InitializeAsync(DisposalToken);
3535
_lspTagHelperTooltipFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver).Object;
3636
_vsLspTagHelperTooltipFactory = new Mock<VSLSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver).Object;
3737
_completionListCache = new CompletionListCache();
3838
_completionCapability = new VSInternalCompletionSetting()
3939
{
4040
CompletionItem = new CompletionItemSetting()
4141
{
42-
DocumentationFormat = new[] { MarkupKind.PlainText, MarkupKind.Markdown },
42+
DocumentationFormat = [MarkupKind.PlainText, MarkupKind.Markdown],
4343
}
4444
};
4545

@@ -97,7 +97,6 @@ public async Task Handle_Resolve_DirectiveAttributeCompletion_ReturnsCompletionI
9797
{
9898
// Arrange
9999
var snapshotResolver = new TestSnapshotResolver();
100-
await snapshotResolver.InitializeAsync(DisposalToken);
101100
var lspDescriptionFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver);
102101
var markdown = new MarkupContent
103102
{
@@ -127,7 +126,6 @@ public async Task Handle_Resolve_DirectiveAttributeParameterCompletion_ReturnsCo
127126
{
128127
// Arrange
129128
var snapshotResolver = new TestSnapshotResolver();
130-
await snapshotResolver.InitializeAsync(DisposalToken);
131129
var descriptionFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver);
132130
var markdown = new MarkupContent
133131
{
@@ -157,7 +155,6 @@ public async Task Handle_Resolve_TagHelperElementCompletion_ReturnsCompletionIte
157155
{
158156
// Arrange
159157
var snapshotResolver = new TestSnapshotResolver();
160-
await snapshotResolver.InitializeAsync(DisposalToken);
161158
var lspDescriptionFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver);
162159
var markdown = new MarkupContent
163160
{
@@ -187,7 +184,6 @@ public async Task Handle_Resolve_TagHelperAttribute_ReturnsCompletionItemWithDoc
187184
{
188185
// Arrange
189186
var snapshotResolver = new TestSnapshotResolver();
190-
await snapshotResolver.InitializeAsync(DisposalToken);
191187
var lspDescriptionFactory = new Mock<LSPTagHelperTooltipFactory>(MockBehavior.Strict, snapshotResolver);
192188
var markdown = new MarkupContent
193189
{

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionItemResolverTest.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@
1717

1818
namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion;
1919

20-
public class RazorCompletionItemResolverTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
20+
public class RazorCompletionItemResolverTest : LanguageServerTestBase
2121
{
22-
private LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
23-
private VSLSPTagHelperTooltipFactory _vsLspTagHelperTooltipFactory;
24-
private VSInternalCompletionSetting _completionCapability;
25-
private VSInternalClientCapabilities _defaultClientCapability;
26-
private VSInternalClientCapabilities _vsClientCapability;
27-
private AggregateBoundAttributeDescription _attributeDescription;
28-
private AggregateBoundElementDescription _elementDescription;
29-
30-
protected async override Task InitializeAsync()
22+
private readonly LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
23+
private readonly VSLSPTagHelperTooltipFactory _vsLspTagHelperTooltipFactory;
24+
private readonly VSInternalCompletionSetting _completionCapability;
25+
private readonly VSInternalClientCapabilities _defaultClientCapability;
26+
private readonly VSInternalClientCapabilities _vsClientCapability;
27+
private readonly AggregateBoundAttributeDescription _attributeDescription;
28+
private readonly AggregateBoundElementDescription _elementDescription;
29+
30+
public RazorCompletionItemResolverTest(ITestOutputHelper testOutput)
31+
: base(testOutput)
3132
{
3233
var snapshotResolver = new TestSnapshotResolver();
33-
await snapshotResolver.InitializeAsync(DisposalToken);
3434

3535
_lspTagHelperTooltipFactory = new DefaultLSPTagHelperTooltipFactory(snapshotResolver);
3636
_vsLspTagHelperTooltipFactory = new DefaultVSLSPTagHelperTooltipFactory(snapshotResolver);
3737
_completionCapability = new VSInternalCompletionSetting()
3838
{
3939
CompletionItem = new CompletionItemSetting()
4040
{
41-
DocumentationFormat = new[] { MarkupKind.PlainText, MarkupKind.Markdown },
41+
DocumentationFormat = [MarkupKind.PlainText, MarkupKind.Markdown],
4242
}
4343
};
4444

@@ -60,9 +60,9 @@ protected async override Task InitializeAsync()
6060
};
6161

6262
var attributeDescriptionInfo = new BoundAttributeDescriptionInfo("System.DateTime", "System.DateTime", "DateTime", "Returns the time.");
63-
_attributeDescription = new AggregateBoundAttributeDescription(ImmutableArray.Create(attributeDescriptionInfo));
63+
_attributeDescription = new AggregateBoundAttributeDescription([attributeDescriptionInfo]);
6464
var elementDescriptionInfo = new BoundElementDescriptionInfo("System.SomeTagHelper", "This is some TagHelper.");
65-
_elementDescription = new AggregateBoundElementDescription(ImmutableArray.Create(elementDescriptionInfo));
65+
_elementDescription = new AggregateBoundElementDescription([elementDescriptionInfo]);
6666
}
6767

6868
[Fact]

0 commit comments

Comments
 (0)