Add telemetry for TS ai refactorings (#198708)

This commit is contained in:
Matt Bierner 2023-11-20 15:01:33 -08:00 committed by GitHub
parent 2d8e9cbb8f
commit 1d92f24bd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 5 deletions

View file

@ -223,7 +223,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
commandManager.register(new CompositeCommand());
commandManager.register(new ApplyCodeActionCommand(client, diagnosticsManager, telemetryReporter));
commandManager.register(new ApplyFixAllCodeAction(client, telemetryReporter));
commandManager.register(new EditorChatFollowUp(client));
commandManager.register(new EditorChatFollowUp(client, telemetryReporter));
this.supportedCodeActionProvider = new SupportedCodeActionProvider(client);
}
@ -349,7 +349,8 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
arguments: [<EditorChatFollowUp_Args>{
message: 'Add types to this code. Add separate interfaces when possible. Do not change the code except for adding types.',
expand: { kind: 'navtree-function', pos: diagnostic.range.start },
document
document,
action: { type: 'quickfix', quickfix: action }
}],
title: ''
};

View file

@ -465,7 +465,7 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
commandManager.register(new CompositeCommand());
commandManager.register(new SelectRefactorCommand(this.client));
commandManager.register(new MoveToFileRefactorCommand(this.client, didApplyRefactoringCommand));
commandManager.register(new EditorChatFollowUp(this.client));
commandManager.register(new EditorChatFollowUp(this.client, telemetryReporter));
}
public static readonly metadata: vscode.CodeActionProviderMetadata = {
@ -579,7 +579,8 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
if (Extract_Constant.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractConstant')
|| Extract_Function.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractFunction')
|| Extract_Type.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractType')
|| Extract_Interface.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractInterface')) {
|| Extract_Interface.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractInterface')
) {
const newName = Extract_Constant.matches(action) ? 'newLocal'
: Extract_Function.matches(action) ? 'newFunction'
: Extract_Type.matches(action) ? 'NewType'
@ -597,6 +598,7 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
kind: 'refactor-info',
refactor: info,
},
action: { type: 'refactor', refactor: action },
document,
}]
});

View file

@ -9,6 +9,7 @@ import { nulToken } from '../../utils/cancellation';
import type * as Proto from '../../tsServer/protocol/protocol';
import * as typeConverters from '../../typeConverters';
import { ITypeScriptServiceClient } from '../../typescriptService';
import { TelemetryReporter } from '../../logging/telemetry';
export class EditorChatFollowUp implements Command {
public static readonly ID = '_typescript.quickFix.editorChatReplacement2';
@ -16,9 +17,38 @@ export class EditorChatFollowUp implements Command {
constructor(
private readonly client: ITypeScriptServiceClient,
private readonly telemetryReporter: TelemetryReporter,
) { }
async execute({ message, document, expand }: EditorChatFollowUp_Args) {
async execute({ message, document, expand, action }: EditorChatFollowUp_Args) {
if (action.type === 'quickfix') {
/* __GDPR__
"aiQuickfix.execute" : {
"owner": "mjbvz",
"action" : { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
"${include}": [
"${TypeScriptCommonProperties}"
]
}
*/
this.telemetryReporter.logTelemetry('aiQuickfix.execute', {
action: action.quickfix.fixName,
});
} else {
/* __GDPR__
"aiRefactor.execute" : {
"owner": "mjbvz",
"action" : { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
"${include}": [
"${TypeScriptCommonProperties}"
]
}
*/
this.telemetryReporter.logTelemetry('aiRefactor.execute', {
action: action.refactor.name,
});
}
const initialRange =
expand.kind === 'navtree-function'
? await findScopeEndLineFromNavTree(
@ -50,6 +80,13 @@ export interface EditorChatFollowUp_Args {
readonly message: string;
readonly document: vscode.TextDocument;
readonly expand: Expand;
readonly action: {
readonly type: 'refactor';
readonly refactor: Proto.RefactorActionInfo;
} | {
readonly type: 'quickfix';
readonly quickfix: Proto.CodeFixAction;
};
}
export class CompositeCommand implements Command {