Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Copilot rename telemetry #76045

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -21,6 +21,7 @@
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.InlineRename.UI.SmartRename;

Expand All @@ -37,6 +38,9 @@ internal sealed partial class SmartRenameViewModel : INotifyPropertyChanged, IDi
private bool _isDisposed;
private TimeSpan AutomaticFetchDelay => _smartRenameSession.AutomaticFetchDelay;
private Task _getSuggestionsTask = Task.CompletedTask;
private TimeSpan _semanticContextDelay;
private bool _semanticContextError;
private bool _semanticContextUsed;

public event PropertyChangedEventHandler? PropertyChanged;

Expand Down Expand Up @@ -176,6 +180,8 @@ await Task.Delay(_smartRenameSession.AutomaticFetchDelay, cancellationToken)

if (IsUsingSemanticContext)
{
var stopwatch = SharedStopwatch.StartNew();
_semanticContextUsed = true;
var document = this.BaseViewModel.Session.TriggerDocument;
var smartRenameContext = ImmutableDictionary<string, ImmutableArray<(string filePath, string content)>>.Empty;
try
Expand All @@ -188,9 +194,11 @@ await Task.Delay(_smartRenameSession.AutomaticFetchDelay, cancellationToken)
smartRenameContext = ImmutableDictionary.CreateRange<string, ImmutableArray<(string filePath, string content)>>(
context
.Select(n => new KeyValuePair<string, ImmutableArray<(string filePath, string content)>>(n.Key, n.Value)));
_semanticContextDelay = stopwatch.Elapsed;
}
catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Diagnostic))
{
_semanticContextError = true;
// use empty smartRenameContext
}
_ = await _smartRenameSession.GetSuggestionsAsync(smartRenameContext, cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ private void PostTelemetry(bool isCommit)
m[nameof(SuggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts)] = _suggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts;
m["CollapseSuggestionsPanelWhenRenameEnds"] = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.CollapseSuggestionsPanel);
m["smartRenameSessionInProgress"] = _smartRenameSession.IsInProgress;
m["smartRenameCorrelationId"] = _smartRenameSession.CorrelationId;
m["smartRenameSemanticContextUsed"] = _semanticContextUsed;
m["smartRenameSemanticContextDelay"] = _semanticContextDelay;
m["smartRenameSemanticContextError"] = _semanticContextError;
}));
}
else
Expand All @@ -63,6 +67,10 @@ private void PostTelemetry(bool isCommit)
m["UseDropDown"] = true;
m[nameof(SuggestionsDropdownTelemetry.DropdownButtonClickTimes)] = _suggestionsDropdownTelemetry.DropdownButtonClickTimes;
m["smartRenameSessionInProgress"] = _smartRenameSession.IsInProgress;
m["smartRenameCorrelationId"] = _smartRenameSession.CorrelationId;
m["smartRenameSemanticContextUsed"] = _semanticContextUsed;
m["smartRenameSemanticContextDelay"] = _semanticContextDelay;
m["smartRenameSemanticContextError"] = _semanticContextError;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Microsoft.CodeAnalysis.EditorFeatures.Lightup;
private static readonly Func<object, string> s_statusMessageAccessor;
private static readonly Func<object, bool> s_statusMessageVisibilityAccessor;
private static readonly Func<object, IReadOnlyList<string>> s_suggestedNamesAccessor;
private static readonly Func<object, Guid> s_correlationIdAccessor;
private static readonly Func<object?, object?>? s_renameContextImmutableListCreateBuilderAccessor;
private static readonly Action<object, object>? s_renameContextImmutableListBuilderAddAccessor;
private static readonly Func<object, object>? s_renameContextImmutableListBuilderToArrayAccessor;
Expand All @@ -52,6 +53,7 @@ static ISmartRenameSessionWrapper()
s_statusMessageAccessor = LightupHelpers.CreatePropertyAccessor<object, string>(s_wrappedType, nameof(StatusMessage), "");
s_statusMessageVisibilityAccessor = LightupHelpers.CreatePropertyAccessor<object, bool>(s_wrappedType, nameof(StatusMessageVisibility), false);
s_suggestedNamesAccessor = LightupHelpers.CreatePropertyAccessor<object, IReadOnlyList<string>>(s_wrappedType, nameof(SuggestedNames), []);
s_correlationIdAccessor = LightupHelpers.CreatePropertyAccessor<object, Guid>(s_wrappedType, nameof(CorrelationId), Guid.Empty);

if (s_wrappedRenameContextType is not null)
{
Expand Down Expand Up @@ -93,6 +95,7 @@ private ISmartRenameSessionWrapper(object instance)
public string StatusMessage => s_statusMessageAccessor(_instance);
public bool StatusMessageVisibility => s_statusMessageVisibilityAccessor(_instance);
public IReadOnlyList<string> SuggestedNames => s_suggestedNamesAccessor(_instance);
public Guid CorrelationId => s_correlationIdAccessor(_instance);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need to insert editor change first


public event PropertyChangedEventHandler PropertyChanged
{
Expand Down
Loading