Skip to content

Commit a4f9d32

Browse files
authored
Add telemetry reporting to rename suggestions (microsoft#205869)
rename suggestions: add telemetry reporting
1 parent a6ba9af commit a4f9d32

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/vs/editor/contrib/rename/browser/rename.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import { ILogService } from 'vs/platform/log/common/log';
3636
import { INotificationService } from 'vs/platform/notification/common/notification';
3737
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
3838
import { Registry } from 'vs/platform/registry/common/platform';
39-
import { CONTEXT_RENAME_INPUT_FOCUSED, CONTEXT_RENAME_INPUT_VISIBLE, RenameInputField } from './renameInputField';
39+
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
40+
import { CONTEXT_RENAME_INPUT_FOCUSED, CONTEXT_RENAME_INPUT_VISIBLE, RenameInputField, RenameInputFieldResult } from './renameInputField';
4041

4142
class RenameSkeleton {
4243

@@ -149,6 +150,7 @@ class RenameController implements IEditorContribution {
149150
@ILogService private readonly _logService: ILogService,
150151
@ITextResourceConfigurationService private readonly _configService: ITextResourceConfigurationService,
151152
@ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService,
153+
@ITelemetryService private readonly _telemetryService: ITelemetryService,
152154
) {
153155
this._renameInputField = this._disposableStore.add(this._instaService.createInstance(RenameInputField, this.editor, ['acceptRenameInput', 'acceptRenameInputWithPreview']));
154156
}
@@ -240,6 +242,8 @@ class RenameController implements IEditorContribution {
240242
const inputFieldResult = await this._renameInputField.getInput(loc.range, loc.text, selectionStart, selectionEnd, supportPreview, newSymbolNameProvidersResults, renameCandidatesCts);
241243
trace('received response from rename input field');
242244

245+
this._reportTelemetry(inputFieldResult);
246+
243247
// no result, only hint to focus the editor or not
244248
if (typeof inputFieldResult === 'boolean') {
245249
trace(`returning early - rename input field response - ${inputFieldResult}`);
@@ -325,6 +329,38 @@ class RenameController implements IEditorContribution {
325329
focusPreviousRenameSuggestion(): void {
326330
this._renameInputField.focusPreviousRenameSuggestion();
327331
}
332+
333+
private _reportTelemetry(inputFieldResult: boolean | RenameInputFieldResult) {
334+
type RenameInvokedEvent =
335+
{
336+
kind: 'accepted' | 'cancelled';
337+
/** provided only if kind = 'accepted' */
338+
wantsPreview?: boolean;
339+
/** provided only if kind = 'accepted' */
340+
source?: RenameInputFieldResult['source'];
341+
/** provided only if kind = 'accepted' */
342+
hadRenameSuggestions?: boolean;
343+
};
344+
345+
type RenameInvokedClassification = {
346+
owner: 'ulugbekna';
347+
comment: 'A rename operation was invoked.';
348+
kind: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Whether the rename operation was cancelled or accepted.' };
349+
wantsPreview?: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'If user wanted preview.'; isMeasurement: true };
350+
source?: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Whether the new name came from the input field or rename suggestions.' };
351+
hadRenameSuggestions?: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Whether the user had rename suggestions.'; isMeasurement: true };
352+
};
353+
354+
this._telemetryService.publicLog2<RenameInvokedEvent, RenameInvokedClassification>(
355+
'renameInvokedEvent',
356+
typeof inputFieldResult === 'boolean' ? { kind: 'cancelled' } : {
357+
kind: 'accepted',
358+
wantsPreview: inputFieldResult.wantsPreview,
359+
source: inputFieldResult.source,
360+
hadRenameSuggestions: inputFieldResult.hadRenameSuggestions,
361+
}
362+
);
363+
}
328364
}
329365

330366
// ---- action implementation

src/vs/editor/contrib/rename/browser/renameInputField.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export const CONTEXT_RENAME_INPUT_FOCUSED = new RawContextKey<boolean>('renameIn
4949
export interface RenameInputFieldResult {
5050
newName: string;
5151
wantsPreview?: boolean;
52+
source: 'inputField' | 'renameSuggestion';
53+
hadRenameSuggestions: boolean;
5254
}
5355

5456
export class RenameInputField implements IContentWidget {
@@ -298,7 +300,19 @@ export class RenameInputField implements IContentWidget {
298300
assertType(this._input !== undefined);
299301
assertType(this._candidatesView !== undefined);
300302

301-
const newName = this._candidatesView.focusedCandidate ?? this._input.value;
303+
const hadRenameSuggestions = this._candidatesView.hasCandidates();
304+
305+
let newName: string;
306+
let source: 'inputField' | 'renameSuggestion';
307+
if (this._candidatesView.focusedCandidate !== undefined) {
308+
this._trace('using new name from renameSuggestion');
309+
newName = this._candidatesView.focusedCandidate;
310+
source = 'renameSuggestion';
311+
} else {
312+
this._trace('using new name from inputField');
313+
newName = this._input.value;
314+
source = 'inputField';
315+
}
302316

303317
if (newName === value || newName.trim().length === 0 /* is just whitespace */) {
304318
this.cancelInput(true, '_currentAcceptInput (because newName === value || newName.trim().length === 0)');
@@ -311,7 +325,9 @@ export class RenameInputField implements IContentWidget {
311325

312326
resolve({
313327
newName,
314-
wantsPreview: supportPreview && wantsPreview
328+
wantsPreview: supportPreview && wantsPreview,
329+
source,
330+
hadRenameSuggestions,
315331
});
316332
};
317333

@@ -513,6 +529,10 @@ class CandidatesView {
513529
this._listWidget.splice(0, this._listWidget.length, []);
514530
}
515531

532+
public hasCandidates() {
533+
return this._listWidget.length > 0;
534+
}
535+
516536
public get focusedCandidate(): string | undefined {
517537
if (this._listWidget.length === 0) {
518538
return;

0 commit comments

Comments
 (0)