Skip to content

Commit e260767

Browse files
committed
Forgot to make it lazy 🤦‍♂️
1 parent 3cc5eb9 commit e260767

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Tools/ExternalAccess/Razor/Features/Cohost/RazorStartupServiceFactory.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
2323
internal sealed class RazorStartupServiceFactory(
2424
[Import(AllowDefault = true)] IUIContextActivationService? uIContextActivationService,
2525
[Import(AllowDefault = true)] Lazy<ICohostStartupService>? cohostStartupService,
26-
[Import(AllowDefault = true)] AbstractRazorCohostLifecycleService? razorCohostLifecycleService) : ILspServiceFactory
26+
[Import(AllowDefault = true)] Lazy<AbstractRazorCohostLifecycleService>? razorCohostLifecycleService) : ILspServiceFactory
2727
{
2828
public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
2929
{
@@ -35,15 +35,18 @@ private class RazorStartupService(
3535
#pragma warning disable CS0618 // Type or member is obsolete
3636
Lazy<ICohostStartupService>? cohostStartupService,
3737
#pragma warning restore CS0618 // Type or member is obsolete
38-
AbstractRazorCohostLifecycleService? razorCohostLifecycleService) : ILspService, IOnInitialized, IDisposable
38+
Lazy<AbstractRazorCohostLifecycleService>? razorCohostLifecycleService) : ILspService, IOnInitialized, IDisposable
3939
{
4040
private readonly CancellationTokenSource _disposalTokenSource = new();
4141
private IDisposable? _cohostActivation;
4242
private IDisposable? _razorFilePresentActivation;
4343

4444
public void Dispose()
4545
{
46-
razorCohostLifecycleService?.Dispose();
46+
if (razorCohostLifecycleService is { IsValueCreated: true, Value: var service })
47+
{
48+
service.Dispose();
49+
}
4750

4851
_razorFilePresentActivation?.Dispose();
4952
_razorFilePresentActivation = null;
@@ -101,7 +104,7 @@ private async Task PreinitializeRazorAsync(CancellationToken cancellationToken)
101104

102105
if (razorCohostLifecycleService is not null)
103106
{
104-
await razorCohostLifecycleService.LspServerIntializedAsync(cancellationToken).ConfigureAwait(false);
107+
await razorCohostLifecycleService.Value.LspServerIntializedAsync(cancellationToken).ConfigureAwait(false);
105108
}
106109
}
107110

@@ -121,7 +124,7 @@ private async Task InitializeRazorAsync(ClientCapabilities clientCapabilities, R
121124
if (razorCohostLifecycleService is not null)
122125
{
123126
// If we have a cohost lifecycle service, fire post-initialization, which happens when the UIContext is activated.
124-
await razorCohostLifecycleService.RazorActivatedAsync(clientCapabilities, requestContext, cancellationToken).ConfigureAwait(false);
127+
await razorCohostLifecycleService.Value.RazorActivatedAsync(clientCapabilities, requestContext, cancellationToken).ConfigureAwait(false);
125128
}
126129

127130
if (cohostStartupService is not null)

0 commit comments

Comments
 (0)