Skip to content

Commit

Permalink
Using the action title in the hover message when auto-running on clic…
Browse files Browse the repository at this point in the history
…king of sparkle (#199521)

* using the action title prepended with Run keyword

* setting the title in one function which is outside of _updateLightBulbTitleAndIcon
  • Loading branch information
aiday-mar authored Dec 11, 2023
1 parent 3fca41e commit 83180a3
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions src/vs/editor/contrib/codeAction/browser/lightBulbWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,60 +244,53 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
if (this.state.type !== LightBulbState.Type.Showing) {
return;
}
const updateAutoFixLightbulbTitle = () => {
if (this._preferredKbLabel) {
this.title = nls.localize('preferredcodeActionWithKb', "Show Code Actions. Preferred Quick Fix Available ({0})", this._preferredKbLabel);
}
};
const updateLightbulbTitle = () => {
if (this._quickFixKbLabel) {
this.title = nls.localize('codeActionWithKb', "Show Code Actions ({0})", this._quickFixKbLabel);
} else {
this.title = nls.localize('codeAction', "Show Code Actions");
}
};
let icon: ThemeIcon;
let autoRun = false;
const option = this._editor.getOption(EditorOption.lightbulb).experimental.showAiIcon;
if (option === ShowAiIconMode.On || option === ShowAiIconMode.OnCode) {
if (option === ShowAiIconMode.On && this.state.actions.allAIFixes) {
icon = Codicon.sparkleFilled;
if (this.state.actions.validActions.length === 1) {
if (this.state.actions.validActions[0].action.command?.id === `inlineChat.start`) {
const keybinding = this._keybindingService.lookupKeybinding('inlineChat.start')?.getLabel() ?? undefined;
this.title = keybinding ? nls.localize('codeActionStartInlineChatWithKb', 'Start Inline Chat ({0})', keybinding) : nls.localize('codeActionStartInlineChat', 'Start Inline Chat',);
} else {
this.title = nls.localize('codeActionTriggerAiAction', "Trigger AI Action");
}
} else {
updateLightbulbTitle();
autoRun = true;
}
} else if (this.state.actions.hasAutoFix) {
if (this.state.actions.hasAIFix) {
icon = Codicon.lightbulbSparkleAutofix;
} else {
icon = Codicon.lightbulbAutofix;
}
updateAutoFixLightbulbTitle();
} else if (this.state.actions.hasAIFix) {
icon = Codicon.lightbulbSparkle;
updateLightbulbTitle();
} else {
icon = Codicon.lightBulb;
updateLightbulbTitle();
}
} else {
if (this.state.actions.hasAutoFix) {
icon = Codicon.lightbulbAutofix;
updateAutoFixLightbulbTitle();
} else {
icon = Codicon.lightBulb;
updateLightbulbTitle();
}
}
this._updateLightbulbTitle(this.state.actions.hasAutoFix, autoRun);
this._iconClasses = ThemeIcon.asClassNameArray(icon);
this._domNode.classList.add(...this._iconClasses);
}

private _updateLightbulbTitle(autoFix: boolean, autoRun: boolean): void {
if (this.state.type !== LightBulbState.Type.Showing) {
return;
}
if (autoRun) {
this.title = nls.localize('codeActionAutoRun', "Run: {0}", this.state.actions.validActions[0].action.title);
} else if (autoFix && this._preferredKbLabel) {
this.title = nls.localize('preferredcodeActionWithKb', "Show Code Actions. Preferred Quick Fix Available ({0})", this._preferredKbLabel);
} else if (!autoFix && this._quickFixKbLabel) {
this.title = nls.localize('codeActionWithKb', "Show Code Actions ({0})", this._quickFixKbLabel);
} else if (!autoFix) {
this.title = nls.localize('codeAction', "Show Code Actions");
}
}

private set title(value: string) {
this._domNode.title = value;
}
Expand Down

0 comments on commit 83180a3

Please sign in to comment.