Skip to content

Commit bad0049

Browse files
committed
Make sure we don't include disabled actions in the standard light bulb menu
1 parent 827e94e commit bad0049

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { MessageController } from 'vs/editor/contrib/message/messageController';
1616
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1717
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1818
import { CodeActionsState } from './codeActionModel';
19-
import { CodeActionWidget } from './codeActionWidget';
19+
import { CodeActionWidget, CodeActionShowOptions } from './codeActionWidget';
2020
import { LightBulbWidget } from './lightBulbWidget';
2121
import { CodeActionAutoApply, CodeActionTrigger } from './types';
2222

@@ -48,7 +48,7 @@ export class CodeActionUi extends Disposable {
4848

4949
this._lightBulbWidget = new Lazy(() => {
5050
const widget = this._register(new LightBulbWidget(this._editor, quickFixActionId, preferredFixActionId, keybindingService));
51-
this._register(widget.onClick(e => this.showCodeActionList(e.actions, e)));
51+
this._register(widget.onClick(e => this.showCodeActionList(e.actions, e, { includeDisabledActions: false })));
5252
return widget;
5353
});
5454
}
@@ -69,12 +69,6 @@ export class CodeActionUi extends Disposable {
6969

7070
this._lightBulbWidget.getValue().update(actions, newState.position);
7171

72-
if (!actions.allActions.length && newState.trigger.context) {
73-
MessageController.get(this._editor).showMessage(newState.trigger.context.notAvailableMessage, newState.trigger.context.position);
74-
this._activeCodeActions.value = actions;
75-
return;
76-
}
77-
7872
if (newState.trigger.type === 'manual') {
7973
if (newState.trigger.filter?.include) { // Triggered for specific scope
8074
// Check to see if we want to auto apply.
@@ -100,8 +94,18 @@ export class CodeActionUi extends Disposable {
10094
}
10195
}
10296

97+
const includeDisabledActions = !!newState.trigger.filter?.include;
98+
if (newState.trigger.context) {
99+
if (!actions.allActions.length || !includeDisabledActions && !actions.validActions.length) {
100+
MessageController.get(this._editor).showMessage(newState.trigger.context.notAvailableMessage, newState.trigger.context.position);
101+
this._activeCodeActions.value = actions;
102+
actions.dispose();
103+
return;
104+
}
105+
}
106+
103107
this._activeCodeActions.value = actions;
104-
this._codeActionWidget.getValue().show(actions, newState.position);
108+
this._codeActionWidget.getValue().show(actions, newState.position, { includeDisabledActions });
105109
} else {
106110
// auto magically triggered
107111
if (this._codeActionWidget.getValue().isVisible) {
@@ -141,7 +145,7 @@ export class CodeActionUi extends Disposable {
141145
return undefined;
142146
}
143147

144-
public async showCodeActionList(actions: CodeActionSet, at: IAnchor | IPosition): Promise<void> {
145-
this._codeActionWidget.getValue().show(actions, at);
148+
public async showCodeActionList(actions: CodeActionSet, at: IAnchor | IPosition, options: CodeActionShowOptions): Promise<void> {
149+
this._codeActionWidget.getValue().show(actions, at, options);
146150
}
147151
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class CodeActionAction extends Action {
3939
}
4040
}
4141

42+
export interface CodeActionShowOptions {
43+
readonly includeDisabledActions: boolean;
44+
}
45+
4246
export class CodeActionWidget extends Disposable {
4347

4448
private _visible: boolean = false;
@@ -63,8 +67,9 @@ export class CodeActionWidget extends Disposable {
6367
return this._visible;
6468
}
6569

66-
public async show(codeActions: CodeActionSet, at: IAnchor | IPosition): Promise<void> {
67-
if (!codeActions.allActions.length) {
70+
public async show(codeActions: CodeActionSet, at: IAnchor | IPosition, options: CodeActionShowOptions): Promise<void> {
71+
const actionsToShow = options.includeDisabledActions ? codeActions.allActions : codeActions.validActions;
72+
if (!actionsToShow.length) {
6873
this._visible = false;
6974
return;
7075
}
@@ -78,15 +83,15 @@ export class CodeActionWidget extends Disposable {
7883
this._visible = true;
7984
this._showingActions.value = codeActions;
8085

81-
const actions = codeActions.allActions.map(action =>
86+
const menuActions = actionsToShow.map(action =>
8287
new CodeActionAction(action, () => this._delegate.onSelectCodeAction(action)));
8388

8489
const anchor = Position.isIPosition(at) ? this._toCoords(at) : at || { x: 0, y: 0 };
8590
const resolver = this._keybindingResolver.getResolver();
8691

8792
this._contextMenuService.showContextMenu({
8893
getAnchor: () => anchor,
89-
getActions: () => actions,
94+
getActions: () => menuActions,
9095
onHide: () => {
9196
this._visible = false;
9297
this._editor.focus();

0 commit comments

Comments
 (0)