Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Composition;
using Microsoft.CodeAnalysis.Contracts.Telemetry;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.Razor;

[Shared]
[ExportRazorStatelessLspService(typeof(RazorInitializer))]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class RazorInitializer(Lazy<LanguageServerWorkspaceFactory> workspaceFactory, [Import(AllowDefault = true)] ITelemetryReporter? telemetryReporter) : ILspService, IOnInitialized
{
public Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken)
{
var razorInitializerService = context.GetService<AbstractRazorInitializer>();
if (razorInitializerService is null)
{
// No initializer service registered, nothing to do.
return Task.CompletedTask;
}

razorInitializerService.Initialize(workspaceFactory.Value.HostWorkspace);

var razorTelemetryReporter = context.GetService<RazorTelemetryReporter>();
if (telemetryReporter is not null && razorTelemetryReporter is not null)
{
razorTelemetryReporter.Initialize(new TelemetryReporterWrapper(telemetryReporter));
}

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.Contracts.Telemetry;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;

namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.Razor;

internal class TelemetryReporterWrapper(ITelemetryReporter telemetryReporter) : ILanguageServerTelemetryReporterWrapper
{
public void ReportEvent(string name, List<KeyValuePair<string, object?>> properties)
{
telemetryReporter.Log(name, properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;

internal abstract class AbstractRazorInitializer : AbstractRazorLspService
{
internal abstract void Initialize(Workspace workspace);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;

internal interface ILanguageServerTelemetryReporterWrapper
{
void ReportEvent(string name, List<KeyValuePair<string, object?>> properties);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;

internal abstract class RazorTelemetryReporter : AbstractRazorLspService
{
private ILanguageServerTelemetryReporterWrapper? _wrapper;

internal void Initialize(ILanguageServerTelemetryReporterWrapper wrapper)
{
_wrapper = wrapper;
}

public void ReportEvent(string name, List<KeyValuePair<string, object?>> properties)
{
_wrapper?.ReportEvent(name, properties);
}
}
Loading