Skip to content

Commit 7894744

Browse files
authored
add command to show terminal quick fixes (microsoft#167438)
* fix microsoft#167416 * move parts to showMenu
1 parent 3a88ca8 commit 7894744

File tree

3 files changed

+60
-35
lines changed

3 files changed

+60
-35
lines changed

src/vs/workbench/contrib/terminal/browser/terminalActions.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,23 @@ export function registerTerminalActions() {
22042204
clearShellFileHistory();
22052205
}
22062206
});
2207+
registerAction2(class extends Action2 {
2208+
constructor() {
2209+
super({
2210+
id: TerminalCommandId.ShowQuickFixes,
2211+
title: { value: localize('workbench.action.terminal.showQuickFixes', "Show Terminal Quick Fixes"), original: 'Show Terminal Quick Fixes' },
2212+
category,
2213+
precondition: TerminalContextKeys.focus,
2214+
keybinding: {
2215+
primary: KeyMod.CtrlCmd | KeyCode.Period,
2216+
weight: KeybindingWeight.EditorContrib
2217+
}
2218+
});
2219+
}
2220+
run(accessor: ServicesAccessor) {
2221+
accessor.get(ITerminalService).activeInstance?.quickFix?.showMenu();
2222+
}
2223+
});
22072224
registerAction2(class extends Action2 {
22082225
constructor() {
22092226
super({

src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { TerminalQuickFix, TerminalQuickFixType, toMenuItems } from 'vs/workbenc
2828
import { ITerminalQuickFixProviderSelector, ITerminalQuickFixService } from 'vs/workbench/contrib/terminal/common/terminal';
2929
import { ITerminalQuickFixOptions, IResolvedExtensionOptions, IUnresolvedExtensionOptions, ITerminalCommandSelector, ITerminalQuickFix, IInternalOptions, ITerminalQuickFixCommandAction, ITerminalQuickFixOpenerAction } from 'vs/platform/terminal/common/xterm/terminalQuickFix';
3030
import { getLinesForCommand } from 'vs/platform/terminal/common/capabilities/commandDetectionCapability';
31+
import { IAnchor } from 'vs/base/browser/ui/contextview/contextview';
3132

3233
const quickFixTelemetryTitle = 'terminal/quick-fix';
3334
type QuickFixResultTelemetryEvent = {
@@ -45,6 +46,7 @@ type QuickFixClassification = {
4546
const quickFixSelectors = [DecorationSelector.QuickFix, DecorationSelector.LightBulb, DecorationSelector.Codicon, DecorationSelector.CommandDecoration, DecorationSelector.XtermDecoration];
4647

4748
export interface ITerminalQuickFixAddon {
49+
showMenu(): void;
4850
onDidRequestRerunCommand: Event<{ command: string; addNewLine?: boolean }>;
4951
/**
5052
* Registers a listener on onCommandFinished scoped to a particular command or regular
@@ -68,6 +70,7 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon,
6870
private _fixesShown: boolean = false;
6971
private _expectedCommands: string[] | undefined;
7072
private _fixId: string | undefined;
73+
private _currentRenderContext: { quickFixes: ITerminalAction[]; anchor: IAnchor; parentElement: HTMLElement } | undefined;
7174

7275
constructor(
7376
private readonly _aliases: string[][] | undefined,
@@ -105,8 +108,31 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon,
105108
}
106109

107110
showMenu(): void {
111+
if (!this._currentRenderContext) {
112+
return;
113+
}
108114
this._fixesShown = true;
109-
this._decoration?.element?.click();
115+
// TODO: What's documentation do? Need a vscode command?
116+
const actions = this._currentRenderContext.quickFixes.map(f => new TerminalQuickFix(f, f.class || TerminalQuickFixType.Command, f.source, f.label));
117+
const documentation = this._currentRenderContext.quickFixes.map(f => { return { id: f.source, title: f.label, tooltip: f.source }; });
118+
const actionSet = {
119+
// TODO: Documentation and actions are separate?
120+
documentation,
121+
allActions: actions,
122+
hasAutoFix: false,
123+
validActions: actions,
124+
dispose: () => { }
125+
} as ActionSet<TerminalQuickFix>;
126+
const delegate = {
127+
onSelect: async (fix: TerminalQuickFix) => {
128+
fix.action?.run();
129+
this._actionWidgetService.hide();
130+
},
131+
onHide: () => {
132+
this._terminal?.focus();
133+
},
134+
};
135+
this._actionWidgetService.show('quickFixWidget', toMenuItems(actionSet.validActions, true), delegate, this._currentRenderContext.anchor, this._currentRenderContext.parentElement);
110136
}
111137

112138
registerCommandSelector(selector: ITerminalCommandSelector): void {
@@ -251,42 +277,23 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon,
251277
e.classList.add(...quickFixSelectors);
252278
updateLayout(this._configurationService, e);
253279
this._audioCueService.playAudioCue(AudioCue.terminalQuickFix);
254-
this._register(dom.addDisposableListener(e, dom.EventType.CLICK, () => {
255-
const rect = e.getBoundingClientRect();
256-
const anchor = {
257-
x: rect.x,
258-
y: rect.y,
259-
width: rect.width,
260-
height: rect.height
261-
};
262-
// TODO: What's documentation do? Need a vscode command?
263-
const actions = fixes.map(f => new TerminalQuickFix(f, f.class || TerminalQuickFixType.Command, f.source, f.label));
264-
const documentation = fixes.map(f => { return { id: f.source, title: f.label, tooltip: f.source }; });
265-
const actionSet = {
266-
// TODO: Documentation and actions are separate?
267-
documentation,
268-
allActions: actions,
269-
hasAutoFix: false,
270-
validActions: actions,
271-
dispose: () => { }
272-
} as ActionSet<TerminalQuickFix>;
280+
const rect = e.getBoundingClientRect();
281+
const anchor = {
282+
x: rect.x,
283+
y: rect.y,
284+
width: rect.width,
285+
height: rect.height
286+
};
273287

274-
const parentElement = e.parentElement?.parentElement?.parentElement?.parentElement;
275-
if (!parentElement) {
276-
return;
277-
}
278-
const delegate = {
279-
onSelect: async (fix: TerminalQuickFix) => {
280-
fix.action?.run();
281-
this._actionWidgetService.hide();
282-
},
283-
onHide: () => {
284-
this._terminal?.focus();
285-
},
286-
};
287-
this._actionWidgetService.show('quickFixWidget', toMenuItems(actionSet.validActions, true), delegate, anchor, parentElement);
288-
}));
288+
const parentElement = e.parentElement?.parentElement?.parentElement?.parentElement;
289+
if (!parentElement) {
290+
return;
291+
}
292+
293+
this._currentRenderContext = { quickFixes: fixes, anchor, parentElement };
294+
this._register(dom.addDisposableListener(e, dom.EventType.CLICK, () => this.showMenu()));
289295
});
296+
decoration.onDispose(() => this._currentRenderContext = undefined);
290297
}
291298
}
292299

src/vs/workbench/contrib/terminal/common/terminal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ export const enum TerminalCommandId {
513513
Split = 'workbench.action.terminal.split',
514514
SplitInstance = 'workbench.action.terminal.splitInstance',
515515
SplitInActiveWorkspace = 'workbench.action.terminal.splitInActiveWorkspace',
516+
ShowQuickFixes = 'workbench.action.terminal.showQuickFixes',
516517
Unsplit = 'workbench.action.terminal.unsplit',
517518
UnsplitInstance = 'workbench.action.terminal.unsplitInstance',
518519
JoinInstance = 'workbench.action.terminal.joinInstance',

0 commit comments

Comments
 (0)