diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel.cs b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel.cs index 843518bdded54..82ca473f38881 100644 --- a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel.cs +++ b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel.cs @@ -16,11 +16,12 @@ using Microsoft.CodeAnalysis.EditorFeatures.Lightup; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; +using Microsoft.CodeAnalysis.Telemetry; using Microsoft.VisualStudio.PlatformUI; namespace Microsoft.CodeAnalysis.InlineRename.UI.SmartRename; -internal sealed class SmartRenameViewModel : INotifyPropertyChanged, IDisposable +internal sealed partial class SmartRenameViewModel : INotifyPropertyChanged, IDisposable { #pragma warning disable CS0618 // Editor team use Obsolete attribute to mark potential changing API private readonly ISmartRenameSessionWrapper _smartRenameSession; @@ -124,6 +125,7 @@ public SmartRenameViewModel( var getSuggestionsAutomatically = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.GetSuggestionsAutomatically); IsUsingResultPanel = getSuggestionsAutomatically; IsUsingDropdown = !IsUsingResultPanel; + SetupTelemetry(); if (IsUsingResultPanel && IsSuggestionsPanelExpanded) { OnGetSuggestionsCommandExecute(); @@ -142,6 +144,11 @@ private void OnGetSuggestionsCommandExecute() { var listener = _listenerProvider.GetListener(FeatureAttribute.SmartRename); var listenerToken = listener.BeginAsyncOperation(nameof(_smartRenameSession.GetSuggestionsAsync)); + if (IsUsingDropdown && _suggestionsDropdownTelemetry is not null) + { + _suggestionsDropdownTelemetry.DropdownButtonClickTimes += 1; + } + _getSuggestionsTask = _smartRenameSession.GetSuggestionsAsync(_cancellationTokenSource.Token).CompletesAsyncOperation(listenerToken); } } @@ -198,12 +205,14 @@ public void Cancel() _cancellationTokenSource.Cancel(); // It's needed by editor-side telemetry. _smartRenameSession.OnCancel(); + PostTelemetry(isCommit: false); } public void Commit(string finalIdentifierName) { // It's needed by editor-side telemetry. _smartRenameSession.OnSuccess(finalIdentifierName); + PostTelemetry(isCommit: true); } public void Dispose() diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs new file mode 100644 index 0000000000000..d52c99ffd26a3 --- /dev/null +++ b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs @@ -0,0 +1,65 @@ +using System.Diagnostics.CodeAnalysis; +using Microsoft.CodeAnalysis.Editor.InlineRename; +using Microsoft.CodeAnalysis.Internal.Log; +using Microsoft.CodeAnalysis.Telemetry; +using Roslyn.Utilities; + +namespace Microsoft.CodeAnalysis.InlineRename.UI.SmartRename +{ + internal partial class SmartRenameViewModel + { + private SuggestionsPanelTelemetry? _suggestionsPanelTelemetry; + private SuggestionsDropdownTelemetry? _suggestionsDropdownTelemetry; + + private sealed class SuggestionsPanelTelemetry + { + public bool CollapseSuggestionsPanelWhenRenameStarts { get; set; } + } + + private sealed class SuggestionsDropdownTelemetry + { + public int DropdownButtonClickTimes { get; set; } + } + + private void SetupTelemetry() + { + var getSuggestionsAutomatically = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.GetSuggestionsAutomatically); + if (getSuggestionsAutomatically) + { + _suggestionsPanelTelemetry = new SuggestionsPanelTelemetry + { + CollapseSuggestionsPanelWhenRenameStarts = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.CollapseSuggestionsPanel) + }; + } + else + { + _suggestionsDropdownTelemetry = new SuggestionsDropdownTelemetry(); + } + } + + private void PostTelemetry(bool isCommit) + { + if (_suggestionsPanelTelemetry is not null) + { + RoslynDebug.Assert(_suggestionsDropdownTelemetry is null); + TelemetryLogging.Log(FunctionId.Copilot_Rename, KeyValueLogMessage.Create(m => + { + m[nameof(isCommit)] = isCommit; + m["UseSuggestionsPanel"] = true; + m[nameof(SuggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts)] = _suggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts; + m["CollapseSuggestionsPanelWhenRenameEnds"] = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.CollapseSuggestionsPanel); + })); + } + else + { + RoslynDebug.Assert(_suggestionsDropdownTelemetry is not null); + TelemetryLogging.Log(FunctionId.Copilot_Rename, KeyValueLogMessage.Create(m => + { + m[nameof(isCommit)] = isCommit; + m["UseDropDown"] = true; + m[nameof(SuggestionsDropdownTelemetry.DropdownButtonClickTimes)] = _suggestionsDropdownTelemetry.DropdownButtonClickTimes; + })); + } + } + } +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Log/FunctionId.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Log/FunctionId.cs index 77d2d04e8bddc..6c9ff33564a73 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Log/FunctionId.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Log/FunctionId.cs @@ -624,4 +624,5 @@ internal enum FunctionId // 800-850 for Copilot performance logging. Copilot_Suggestion_Dismissed = 800, + Copilot_Rename = 851 }