Skip to content

Commit

Permalink
Add telemetry for TS ai refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Nov 20, 2023
1 parent afbfcca commit 63fb8c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'
Expand All @@ -597,6 +598,7 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
kind: 'refactor-info',
refactor: info,
},
action: action,
document,
}]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,31 @@ 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';
public readonly id = EditorChatFollowUp.ID;

constructor(
private readonly client: ITypeScriptServiceClient,
private readonly telemetryReporter: TelemetryReporter,
) { }

async execute({ message, document, expand }: EditorChatFollowUp_Args) {
async execute({ message, document, expand, action }: EditorChatFollowUp_Args) {
/* __GDPR__
"aiRefactor.execute" : {
"owner": "mjbvz",
"action" : { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
"${include}": [
"${TypeScriptCommonProperties}"
]
}
*/
this.telemetryReporter.logTelemetry('aiRefactor.execute', {
action: action.name,
});

const initialRange =
expand.kind === 'navtree-function'
? await findScopeEndLineFromNavTree(
Expand Down Expand Up @@ -50,6 +65,7 @@ export interface EditorChatFollowUp_Args {
readonly message: string;
readonly document: vscode.TextDocument;
readonly expand: Expand;
readonly action: Proto.RefactorActionInfo;
}

export class CompositeCommand implements Command {
Expand Down

0 comments on commit 63fb8c7

Please sign in to comment.