Skip to content

Commit 0a57d82

Browse files
authored
Report cohost status in initialize telemetry (#12001)
Fixes #11654
2 parents f7f9a7c + 2f65230 commit 0a57d82

File tree

6 files changed

+56
-21
lines changed

6 files changed

+56
-21
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" />

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/IncompatibleProjectNotifier.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.CodeAnalysis.Razor;
1212
using Microsoft.CodeAnalysis.Razor.Cohost;
1313
using Microsoft.CodeAnalysis.Razor.Logging;
14+
using Microsoft.CodeAnalysis.Razor.Telemetry;
1415
using WorkspacesSR = Microsoft.CodeAnalysis.Razor.Workspaces.Resources.SR;
1516

1617
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
@@ -19,14 +20,17 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
1920
[Export(typeof(IIncompatibleProjectNotifier))]
2021
[method: ImportingConstructor]
2122
internal sealed class IncompatibleProjectNotifier(
23+
ITelemetryReporter telemetryReporter,
2224
ILoggerFactory loggerFactory) : IIncompatibleProjectNotifier, IProjectCapabilityListener
2325
{
2426
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<IncompatibleProjectNotifier>();
2527

2628
private readonly HashSet<string> _frameworkProjects = new(PathUtilities.OSSpecificPathComparer);
29+
private readonly ITelemetryReporter _telemetryReporter = telemetryReporter;
2730

2831
public void NotifyMiscFilesDocument(TextDocument textDocument)
2932
{
33+
_telemetryReporter.ReportEvent("cohost/miscFilesDocument", Severity.Normal);
3034
_logger.Log(LogLevel.Error, $"{WorkspacesSR.FormatIncompatibleProject_MiscFiles(Path.GetFileName(textDocument.FilePath))}");
3135
}
3236

@@ -41,11 +45,13 @@ public void NotifyMissingDocument(Project project, string filePath)
4145
if (_frameworkProjects.Contains(project.FilePath.AssumeNotNull()))
4246
{
4347
// This project doesn't have the .NET Core C# capability, so it's a .NET Framework project and we don't want
48+
4449
// to notify the user, as those projects use a different editor.
4550
return;
4651
}
4752
}
4853

54+
_telemetryReporter.ReportEvent("cohost/missingDocument", Severity.Normal);
4955
_logger.Log(LogLevel.Error, $"{(
5056
project.AdditionalDocuments.Any(d => d.FilePath is not null && d.FilePath.IsRazorFilePath())
5157
? WorkspacesSR.FormatIncompatibleProject_NotAnAdditionalFile(Path.GetFileName(filePath), project.Name)

src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.Custom.pkgdef

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"Description"="Uses the Razor language server that is cohosted in Roslyn to provide some Razor tooling functionality."
6262
"Value"=dword:00000000
6363
"Title"="Use Roslyn Cohost server for Razor (requires restart)"
64-
"PreviewPaneChannels"="IntPreview,int.main"
64+
"PreviewPaneChannels"="*"
6565

6666
[$RootKey$\FeatureFlags\Razor\LSP\ForceRuntimeCodeGeneration]
6767
"Description"="Enable combined design time/runtime code generation for Razor files"

src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/IncompatibleProjectNotifier.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,29 @@
1010
using Microsoft.CodeAnalysis.Razor;
1111
using Microsoft.CodeAnalysis.Razor.Cohost;
1212
using Microsoft.CodeAnalysis.Razor.Logging;
13+
using Microsoft.CodeAnalysis.Razor.Telemetry;
1314
using WorkspacesSR = Microsoft.CodeAnalysis.Razor.Workspaces.Resources.SR;
1415

1516
namespace Microsoft.VisualStudioCode.RazorExtension.Services;
1617

1718
[Export(typeof(IIncompatibleProjectNotifier))]
1819
[method: ImportingConstructor]
19-
internal sealed class IncompatibleProjectNotifier(ILoggerFactory loggerFactory) : IIncompatibleProjectNotifier
20+
internal sealed class IncompatibleProjectNotifier(
21+
ITelemetryReporter telemetryReporter,
22+
ILoggerFactory loggerFactory) : IIncompatibleProjectNotifier
2023
{
2124
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<IncompatibleProjectNotifier>();
25+
private readonly ITelemetryReporter _telemetryReporter = telemetryReporter;
2226

2327
public void NotifyMiscFilesDocument(TextDocument textDocument)
2428
{
29+
_telemetryReporter.ReportEvent("cohost/miscFilesDocument", Severity.Normal);
2530
_logger.Log(LogLevel.Error, $"{WorkspacesSR.FormatIncompatibleProject_MiscFiles(Path.GetFileName(textDocument.FilePath))}");
2631
}
2732

2833
public void NotifyMissingDocument(Project project, string filePath)
2934
{
35+
_telemetryReporter.ReportEvent("cohost/missingDocument", Severity.Normal);
3036
_logger.Log(LogLevel.Error, $"{(
3137
project.AdditionalDocuments.Any(d => d.FilePath is not null && d.FilePath.IsRazorFilePath())
3238
? WorkspacesSR.FormatIncompatibleProject_NotAnAdditionalFile(Path.GetFileName(filePath), project.Name)

0 commit comments

Comments
 (0)