Skip to content

Commit 1f607b6

Browse files
committed
Move initialize telemetry to a shared location, and add cohost flag
1 parent 5d06658 commit 1f607b6

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@
1111
namespace Microsoft.AspNetCore.Razor.LanguageServer;
1212

1313
[RazorLanguageServerEndpoint(Methods.InitializeName)]
14-
internal class RazorInitializeEndpoint(
15-
LanguageServerFeatureOptions options,
16-
ITelemetryReporter telemetryReporter) : IRazorDocumentlessRequestHandler<InitializeParams, InitializeResult>
14+
internal class RazorInitializeEndpoint() : IRazorDocumentlessRequestHandler<InitializeParams, InitializeResult>
1715
{
18-
private static bool s_reportedFeatureFlagState = false;
19-
20-
private readonly LanguageServerFeatureOptions _options = options;
21-
private readonly ITelemetryReporter _telemetryReporter = telemetryReporter;
22-
2316
public bool MutatesSolutionState { get; } = true;
2417

2518
public Task<InitializeResult> HandleRequestAsync(InitializeParams request, RazorRequestContext requestContext, CancellationToken cancellationToken)
@@ -29,17 +22,6 @@ public Task<InitializeResult> HandleRequestAsync(InitializeParams request, Razor
2922
capabilitiesManager.SetInitializeParams(request);
3023
var serverCapabilities = capabilitiesManager.GetInitializeResult();
3124

32-
// Initialize can be called multiple times in a VS session, but the feature flag can't change in that time, so we only
33-
// need to report once. In VS Code things could change between solution loads, but each solution load starts a new rzls
34-
// process, so the static field gets reset anyway.
35-
if (!s_reportedFeatureFlagState)
36-
{
37-
s_reportedFeatureFlagState = true;
38-
_telemetryReporter.ReportEvent("initialize", Severity.Normal,
39-
new Property(nameof(LanguageServerFeatureOptions.ForceRuntimeCodeGeneration), _options.ForceRuntimeCodeGeneration),
40-
new Property(nameof(LanguageServerFeatureOptions.UseNewFormattingEngine), _options.UseNewFormattingEngine));
41-
}
42-
4325
return Task.FromResult(serverCapabilities);
4426
}
4527
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.ComponentModel.Composition;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
8+
using Microsoft.CodeAnalysis.Razor.Telemetry;
9+
using Microsoft.CodeAnalysis.Razor.Workspaces;
10+
11+
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
12+
13+
[Export(typeof(IRazorCohostStartupService))]
14+
[method: ImportingConstructor]
15+
internal class CohostInitializeReporter(
16+
LanguageServerFeatureOptions languageServerFeatureOptions,
17+
ITelemetryReporter telemetryReporter) : IRazorCohostStartupService
18+
{
19+
private static bool s_reportedFeatureFlagState = false;
20+
21+
private readonly LanguageServerFeatureOptions _options = languageServerFeatureOptions;
22+
private readonly ITelemetryReporter _telemetryReporter = telemetryReporter;
23+
24+
public int Order => WellKnownStartupOrder.Default;
25+
26+
public Task StartupAsync(VSInternalClientCapabilities clientCapabilities, RazorCohostRequestContext requestContext, CancellationToken cancellationToken)
27+
{
28+
// Make sure we don't report telemetry multiple times in the same VS session (as solutions are closed and opened).
29+
if (!s_reportedFeatureFlagState)
30+
{
31+
s_reportedFeatureFlagState = true;
32+
_telemetryReporter.ReportEvent("initialize", Severity.Normal,
33+
new Property(nameof(LanguageServerFeatureOptions.ForceRuntimeCodeGeneration), _options.ForceRuntimeCodeGeneration),
34+
new Property(nameof(LanguageServerFeatureOptions.UseNewFormattingEngine), _options.UseNewFormattingEngine),
35+
new Property(nameof(LanguageServerFeatureOptions.UseRazorCohostServer), _options.UseRazorCohostServer));
36+
}
37+
38+
return Task.CompletedTask;
39+
}
40+
}

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Microsoft.CodeAnalysis.Razor.CohostingShared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<Compile Include="$(MSBuildThisFileDirectory)CodeActions\CohostCodeActionsResolveEndpoint.cs" />
1414
<Compile Include="$(MSBuildThisFileDirectory)CohostEndpointAttribute.cs" />
1515
<Compile Include="$(MSBuildThisFileDirectory)CohostDocSyncEndpointRegistration.cs" />
16+
<Compile Include="$(MSBuildThisFileDirectory)CohostInitializeReporter.cs" />
1617
<Compile Include="$(MSBuildThisFileDirectory)CohostStartupService.cs" />
1718
<Compile Include="$(MSBuildThisFileDirectory)Completion\CohostCompletionListCache.cs" />
1819
<Compile Include="$(MSBuildThisFileDirectory)Completion\CohostDocumentCompletionEndpoint.cs" />

0 commit comments

Comments
 (0)