Skip to content

Commit d5d51ba

Browse files
authored
add telemetry for clicking on sparkle (microsoft#203674)
add telemetry for clicking on sparke
1 parent 2027f70 commit d5d51ba

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ function getDocumentationFromProvider(
245245
export enum ApplyCodeActionReason {
246246
OnSave = 'onSave',
247247
FromProblemsView = 'fromProblemsView',
248-
FromCodeActions = 'fromCodeActions'
248+
FromCodeActions = 'fromCodeActions',
249+
FromAILightbulb = 'fromAILightbulb' // direct invocation when clicking on the AI lightbulb
249250
}
250251

251252
export async function applyCodeAction(

src/vs/editor/contrib/codeAction/browser/codeActionController.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class CodeActionController extends Disposable implements IEditorContribut
8888
this._lightBulbWidget = new Lazy(() => {
8989
const widget = this._editor.getContribution<LightBulbWidget>(LightBulbWidget.ID);
9090
if (widget) {
91-
this._register(widget.onClick(e => this.showCodeActionList(e.actions, e, { includeDisabledActions: false, fromLightbulb: true })));
91+
this._register(widget.onClick(e => this.showCodeActionsFromLightbulb(e.actions, e)));
9292
}
9393
return widget;
9494
});
@@ -103,6 +103,21 @@ export class CodeActionController extends Disposable implements IEditorContribut
103103
super.dispose();
104104
}
105105

106+
private async showCodeActionsFromLightbulb(actions: CodeActionSet, at: IAnchor | IPosition): Promise<void> {
107+
if (actions.allAIFixes && actions.validActions.length === 1) {
108+
const actionItem = actions.validActions[0];
109+
const command = actionItem.action.command;
110+
if (command && command.id === 'inlineChat.start') {
111+
if (command.arguments && command.arguments.length >= 1) {
112+
command.arguments[0] = { ...command.arguments[0], autoSend: false };
113+
}
114+
}
115+
await this._applyCodeAction(actionItem, false, false, ApplyCodeActionReason.FromAILightbulb);
116+
return;
117+
}
118+
await this.showCodeActionList(actions, at, { includeDisabledActions: false, fromLightbulb: true });
119+
}
120+
106121
public showCodeActions(_trigger: CodeActionTrigger, actions: CodeActionSet, at: IAnchor | IPosition) {
107122
return this.showCodeActionList(actions, at, { includeDisabledActions: false, fromLightbulb: false });
108123
}
@@ -130,9 +145,9 @@ export class CodeActionController extends Disposable implements IEditorContribut
130145
return this._model.trigger(trigger);
131146
}
132147

133-
private async _applyCodeAction(action: CodeActionItem, retrigger: boolean, preview: boolean): Promise<void> {
148+
private async _applyCodeAction(action: CodeActionItem, retrigger: boolean, preview: boolean, actionReason: ApplyCodeActionReason): Promise<void> {
134149
try {
135-
await this._instantiationService.invokeFunction(applyCodeAction, action, ApplyCodeActionReason.FromCodeActions, { preview, editor: this._editor });
150+
await this._instantiationService.invokeFunction(applyCodeAction, action, actionReason, { preview, editor: this._editor });
136151
} finally {
137152
if (retrigger) {
138153
this._trigger({ type: CodeActionTriggerType.Auto, triggerAction: CodeActionTriggerSource.QuickFix, filter: {} });
@@ -172,7 +187,7 @@ export class CodeActionController extends Disposable implements IEditorContribut
172187
if (validActionToApply) {
173188
try {
174189
this._lightBulbWidget.value?.hide();
175-
await this._applyCodeAction(validActionToApply, false, false);
190+
await this._applyCodeAction(validActionToApply, false, false, ApplyCodeActionReason.FromCodeActions);
176191
} finally {
177192
actions.dispose();
178193
}
@@ -264,7 +279,7 @@ export class CodeActionController extends Disposable implements IEditorContribut
264279

265280
const delegate: IActionListDelegate<CodeActionItem> = {
266281
onSelect: async (action: CodeActionItem, preview?: boolean) => {
267-
this._applyCodeAction(action, /* retrigger */ true, !!preview);
282+
this._applyCodeAction(action, /* retrigger */ true, !!preview, ApplyCodeActionReason.FromCodeActions);
268283
this._actionWidgetService.hide();
269284
currentDecorations.clear();
270285
},

src/vs/editor/contrib/codeAction/browser/lightBulbWidget.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,6 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
8686
return;
8787
}
8888

89-
if (
90-
this.state.actions.allAIFixes
91-
&& this.state.actions.validActions.length === 1
92-
) {
93-
const action = this.state.actions.validActions[0].action;
94-
const id = action.command?.id;
95-
if (id) {
96-
let args = action.command?.arguments;
97-
if (id === 'inlineChat.start' && args && args.length === 1) {
98-
args = [{ ...args[0], autoSend: false }];
99-
}
100-
commandService.executeCommand(id, ...(args || []));
101-
e.preventDefault();
102-
return;
103-
}
104-
}
10589
// Make sure that focus / cursor location is not lost when clicking widget icon
10690
this._editor.focus();
10791
e.preventDefault();

0 commit comments

Comments
 (0)