mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
adding code in order to be able to detect when different code actions partitions appear
This commit is contained in:
parent
abd005b78b
commit
a037c7e8e9
|
@ -81,6 +81,14 @@ class ManagedCodeActionSet extends Disposable implements CodeActionSet {
|
|||
public get hasAutoFix() {
|
||||
return this.validActions.some(({ action: fix }) => !!fix.kind && CodeActionKind.QuickFix.contains(new CodeActionKind(fix.kind)) && !!fix.isPreferred);
|
||||
}
|
||||
|
||||
public get hasAIFix() {
|
||||
return this.validActions.some(({ action: fix }) => !!fix.isAI);
|
||||
}
|
||||
|
||||
public get allAIFixes() {
|
||||
return this.validActions.every(({ action: fix }) => !!fix.isAI);
|
||||
}
|
||||
}
|
||||
|
||||
const emptyCodeActionsResponse = { actions: [] as CodeActionItem[], documentation: undefined };
|
||||
|
|
|
@ -22,7 +22,7 @@ import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeat
|
|||
import { ApplyCodeActionReason, applyCodeAction } from 'vs/editor/contrib/codeAction/browser/codeAction';
|
||||
import { CodeActionKeybindingResolver } from 'vs/editor/contrib/codeAction/browser/codeActionKeybindingResolver';
|
||||
import { toMenuItems } from 'vs/editor/contrib/codeAction/browser/codeActionMenu';
|
||||
import { LightBulbMenuIconMode, LightBulbWidget } from 'vs/editor/contrib/codeAction/browser/lightBulbWidget';
|
||||
import { LightBulbWidget } from 'vs/editor/contrib/codeAction/browser/lightBulbWidget';
|
||||
import { MessageController } from 'vs/editor/contrib/message/browser/messageController';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IActionListDelegate } from 'vs/platform/actionWidget/browser/actionList';
|
||||
|
@ -260,27 +260,6 @@ export class CodeActionController extends Disposable implements IEditorContribut
|
|||
return;
|
||||
}
|
||||
|
||||
// place into the lightBulbWidget file, will need to define the icon there
|
||||
console.log('actionsToShow : ', actionsToShow);
|
||||
let lightbulbMode = LightBulbMenuIconMode.Standard;
|
||||
actionsToShow.forEach(action => {
|
||||
if (action.action.isAI && lightbulbMode === LightBulbMenuIconMode.Standard) {
|
||||
lightbulbMode = LightBulbMenuIconMode.AI;
|
||||
}
|
||||
if (action.action.isAI && lightbulbMode === LightBulbMenuIconMode.AI) {
|
||||
lightbulbMode = LightBulbMenuIconMode.StandardAI;
|
||||
}
|
||||
});
|
||||
console.log('lightbulbMode : ', lightbulbMode);
|
||||
this._lightBulbWidget.rawValue?.updateLightBulbTitleAndIcon(lightbulbMode);
|
||||
//
|
||||
|
||||
if (actionsToShow.length === 1 && actionsToShow[0].action.isAI) {
|
||||
// There is exactly one code action and it is an AI code action, then automatically trigger it
|
||||
actionsToShow[0].resolve(CancellationToken.None);
|
||||
return;
|
||||
}
|
||||
|
||||
const anchor = Position.isIPosition(at) ? this.toCoords(at) : at;
|
||||
|
||||
const delegate: IActionListDelegate<CodeActionItem> = {
|
||||
|
|
|
@ -111,7 +111,9 @@ const emptyCodeActionSet = Object.freeze<CodeActionSet>({
|
|||
validActions: [],
|
||||
dispose: () => { },
|
||||
documentation: [],
|
||||
hasAutoFix: false
|
||||
hasAutoFix: false,
|
||||
hasAIFix: false,
|
||||
allAIFixes: false,
|
||||
});
|
||||
|
||||
|
||||
|
@ -262,7 +264,7 @@ export class CodeActionModel extends Disposable {
|
|||
});
|
||||
|
||||
// Only retriggers if actually found quickfix on the same line as cursor
|
||||
return { validActions: filteredActions, allActions: allCodeActions, documentation: codeActionSet.documentation, hasAutoFix: codeActionSet.hasAutoFix, dispose: () => { codeActionSet.dispose(); } };
|
||||
return { validActions: filteredActions, allActions: allCodeActions, documentation: codeActionSet.documentation, hasAutoFix: codeActionSet.hasAutoFix, hasAIFix: codeActionSet.hasAIFix, allAIFixes: codeActionSet.allAIFixes, dispose: () => { codeActionSet.dispose(); } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,12 +42,6 @@ namespace LightBulbState {
|
|||
export type State = typeof Hidden | Showing;
|
||||
}
|
||||
|
||||
export enum LightBulbMenuIconMode {
|
||||
Standard,
|
||||
StandardAI,
|
||||
AI
|
||||
}
|
||||
|
||||
export class LightBulbWidget extends Disposable implements IContentWidget {
|
||||
|
||||
public static readonly ID = 'editor.contrib.lightbulbWidget';
|
||||
|
@ -130,7 +124,7 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
|
|||
this._preferredKbLabel = keybindingService.lookupKeybinding(autoFixCommandId)?.getLabel() ?? undefined;
|
||||
this._quickFixKbLabel = keybindingService.lookupKeybinding(quickFixCommandId)?.getLabel() ?? undefined;
|
||||
|
||||
this.updateLightBulbTitleAndIcon();
|
||||
this._updateLightBulbTitleAndIcon();
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -210,44 +204,37 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
|
|||
|
||||
private set state(value) {
|
||||
this._state = value;
|
||||
this.updateLightBulbTitleAndIcon();
|
||||
this._updateLightBulbTitleAndIcon();
|
||||
}
|
||||
|
||||
// make private once again, because we can find the actions directly from this file, do not need to trigger this method from someplace else
|
||||
public updateLightBulbTitleAndIcon(iconMode: LightBulbMenuIconMode = LightBulbMenuIconMode.Standard): void {
|
||||
private _updateLightBulbTitleAndIcon(): void {
|
||||
|
||||
if (iconMode !== LightBulbMenuIconMode.Standard) {
|
||||
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.lightbulbAutofix));
|
||||
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.lightBulb));
|
||||
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.sparkle));
|
||||
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.alert));
|
||||
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.lightBulb));
|
||||
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.lightbulbAutofix));
|
||||
|
||||
if (iconMode === LightBulbMenuIconMode.StandardAI) {
|
||||
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.alert));
|
||||
}
|
||||
if (iconMode === LightBulbMenuIconMode.AI) {
|
||||
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.sparkle));
|
||||
}
|
||||
if (this.state.type !== LightBulbState.Type.Showing) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.state.type === LightBulbState.Type.Showing && this.state.actions.hasAutoFix) {
|
||||
// update icon
|
||||
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.lightBulb));
|
||||
if (this.state.actions.allAIFixes) {
|
||||
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.sparkle));
|
||||
} else if (this.state.actions.hasAIFix) {
|
||||
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.alert));
|
||||
} else if (this.state.actions.hasAutoFix) {
|
||||
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.lightbulbAutofix));
|
||||
|
||||
if (this._preferredKbLabel) {
|
||||
this.title = nls.localize('preferredcodeActionWithKb', "Show Code Actions. Preferred Quick Fix Available ({0})", this._preferredKbLabel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// update icon
|
||||
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.lightbulbAutofix));
|
||||
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.lightBulb));
|
||||
|
||||
if (this._quickFixKbLabel) {
|
||||
this.title = nls.localize('codeActionWithKb', "Show Code Actions ({0})", this._quickFixKbLabel);
|
||||
} else {
|
||||
this.title = nls.localize('codeAction', "Show Code Actions");
|
||||
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.lightBulb));
|
||||
if (this._quickFixKbLabel) {
|
||||
this.title = nls.localize('codeActionWithKb', "Show Code Actions ({0})", this._quickFixKbLabel);
|
||||
} else {
|
||||
this.title = nls.localize('codeAction', "Show Code Actions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,4 +9,6 @@ export interface ActionSet<T> extends IDisposable {
|
|||
readonly validActions: readonly T[];
|
||||
readonly allActions: readonly T[];
|
||||
readonly hasAutoFix: boolean;
|
||||
readonly hasAIFix: boolean;
|
||||
readonly allAIFixes: boolean;
|
||||
}
|
||||
|
|
|
@ -122,6 +122,8 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon,
|
|||
documentation,
|
||||
allActions: actions,
|
||||
hasAutoFix: false,
|
||||
hasAIFix: false,
|
||||
allAIFixes: false,
|
||||
validActions: actions,
|
||||
dispose: () => { }
|
||||
} as ActionSet<TerminalQuickFixItem>;
|
||||
|
|
Loading…
Reference in a new issue