Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contextual action -> quick fix #161638

Merged
merged 7 commits into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Expand Up @@ -19,7 +19,7 @@ import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { IEditableData } from 'vs/workbench/common/views';
import { TerminalFindWidget } from 'vs/workbench/contrib/terminal/browser/terminalFindWidget';
import { ITerminalStatusList } from 'vs/workbench/contrib/terminal/browser/terminalStatusList';
import { IContextualAction } from 'vs/workbench/contrib/terminal/browser/xterm/contextualActionAddon';
import { ITerminalQuickFix } from 'vs/workbench/contrib/terminal/browser/xterm/quickFixAddon';
import { INavigationMode, IRegisterContributedProfileArgs, IRemoteTerminalAttachTarget, IStartExtensionTerminalRequest, ITerminalBackend, ITerminalConfigHelper, ITerminalFont, ITerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/common/terminal';
import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn';
import { IMarker } from 'xterm';
Expand Down Expand Up @@ -459,7 +459,7 @@ export interface ITerminalInstance {

readonly statusList: ITerminalStatusList;

contextualActions: IContextualAction | undefined;
quickFix: ITerminalQuickFix | undefined;

readonly findWidget: Lazy<TerminalFindWidget>;

Expand Down Expand Up @@ -912,25 +912,25 @@ export interface ITerminalInstance {
openRecentLink(type: 'localFile' | 'url'): Promise<void>;

/**
* Registers contextual action listeners
* Registers quick fix providers
*/
registerContextualActions(...options: ITerminalContextualActionOptions[]): void;
registerQuickFixProvider(...options: ITerminalQuickFixOptions[]): void;

freePortKillProcess(port: string): Promise<void>;
}

export interface ITerminalContextualActionOptions {
actionName: string | DynamicActionName;
export interface ITerminalQuickFixOptions {
quickFixLabel: string | DynamicQuickFixLabel;
commandLineMatcher: string | RegExp;
outputMatcher?: ITerminalOutputMatcher;
getActions: ContextualActionCallback;
getQuickFixes: QuickFixCallback;
exitStatus?: boolean;
}
export type ContextualMatchResult = { commandLineMatch: RegExpMatchArray; outputMatch?: RegExpMatchArray | null };
export type DynamicActionName = (matchResult: ContextualMatchResult) => string;
export type ContextualActionCallback = (matchResult: ContextualMatchResult, command: ITerminalCommand) => ICommandAction[] | undefined;
export type QuickFixMatchResult = { commandLineMatch: RegExpMatchArray; outputMatch?: RegExpMatchArray | null };
export type DynamicQuickFixLabel = (matchResult: QuickFixMatchResult) => string;
export type QuickFixCallback = (matchResult: QuickFixMatchResult, command: ITerminalCommand) => ITerminalQuickFixAction[] | undefined;

export interface ICommandAction extends IAction {
export interface ITerminalQuickFixAction extends IAction {
commandToRunInTerminal?: string;
addNewLine?: boolean;
}
Expand Down
Expand Up @@ -159,7 +159,7 @@ export function registerTerminalActions() {
});
}
async run(accessor: ServicesAccessor) {
accessor.get(ITerminalService).activeInstance?.contextualActions?.showQuickFixMenu();
accessor.get(ITerminalService).activeInstance?.quickFix?.showMenu();
}
});

Expand Down
24 changes: 12 additions & 12 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Expand Up @@ -60,9 +60,9 @@ import { AudioCue, IAudioCueService } from 'vs/workbench/contrib/audioCues/brows
import { TaskSettingId } from 'vs/workbench/contrib/tasks/common/tasks';
import { IDetectedLinks, TerminalLinkManager } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkManager';
import { TerminalLinkQuickpick } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkQuickpick';
import { IRequestAddInstanceToGroupEvent, ITerminalContextualActionOptions, ITerminalExternalLinkProvider, ITerminalInstance, TerminalDataTransfers } from 'vs/workbench/contrib/terminal/browser/terminal';
import { IRequestAddInstanceToGroupEvent, ITerminalQuickFixOptions, ITerminalExternalLinkProvider, ITerminalInstance, TerminalDataTransfers } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalLaunchHelpAction } from 'vs/workbench/contrib/terminal/browser/terminalActions';
import { gitSimilarCommand, gitCreatePr, gitPushSetUpstream, freePort } from 'vs/workbench/contrib/terminal/browser/terminalBaseContextualActions';
import { gitSimilarCommand, gitCreatePr, gitPushSetUpstream, freePort } from 'vs/workbench/contrib/terminal/browser/terminalQuickFixBuiltinActions';
import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/terminalConfigHelper';
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
import { TerminalFindWidget } from 'vs/workbench/contrib/terminal/browser/terminalFindWidget';
Expand All @@ -74,7 +74,7 @@ import { TypeAheadAddon } from 'vs/workbench/contrib/terminal/browser/terminalTy
import { getTerminalResourcesFromDragEvent, getTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
import { EnvironmentVariableInfoWidget } from 'vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget';
import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/widgets/widgetManager';
import { ContextualActionAddon, IContextualAction } from 'vs/workbench/contrib/terminal/browser/xterm/contextualActionAddon';
import { ITerminalQuickFix, TerminalQuickFixAddon } from 'vs/workbench/contrib/terminal/browser/xterm/quickFixAddon';
import { LineDataEventAddon } from 'vs/workbench/contrib/terminal/browser/xterm/lineDataEventAddon';
import { NavigationModeAddon } from 'vs/workbench/contrib/terminal/browser/xterm/navigationModeAddon';
import { XtermTerminal } from 'vs/workbench/contrib/terminal/browser/xterm/xtermTerminal';
Expand Down Expand Up @@ -207,7 +207,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private _target?: TerminalLocation | undefined;
private _disableShellIntegrationReporting: boolean | undefined;
private _usedShellIntegrationInjection: boolean = false;
private _contextualActionAddon: ContextualActionAddon | undefined;
private _quickFixAddon: TerminalQuickFixAddon | undefined;

readonly capabilities = new TerminalCapabilityStoreMultiplexer();
readonly statusList: ITerminalStatusList;
Expand All @@ -216,7 +216,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
* Enables opening the contextual actions, if any, that are available
* and registering of command finished listeners
*/
get contextualActions(): IContextualAction | undefined { return this._contextualActionAddon; }
get quickFix(): ITerminalQuickFix | undefined { return this._quickFixAddon; }

readonly findWidget: Lazy<TerminalFindWidget>;

Expand Down Expand Up @@ -610,9 +610,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
return undefined;
}

registerContextualActions(...actionOptions: ITerminalContextualActionOptions[]): void {
for (const actionOption of actionOptions) {
this.contextualActions?.registerCommandFinishedListener(actionOption);
registerQuickFixProvider(...options: ITerminalQuickFixOptions[]): void {
for (const actionOption of options) {
this.quickFix?.registerCommandFinishedListener(actionOption);
}
}

Expand Down Expand Up @@ -728,10 +728,10 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {

const xterm = this._scopedInstantiationService.createInstance(XtermTerminal, Terminal, this._configHelper, this._cols, this._rows, this.target || TerminalLocation.Panel, this.capabilities, this.disableShellIntegrationReporting);
this.xterm = xterm;
this._contextualActionAddon = this._scopedInstantiationService.createInstance(ContextualActionAddon, this.capabilities);
this.xterm?.raw.loadAddon(this._contextualActionAddon);
this.registerContextualActions(gitSimilarCommand(), gitCreatePr(this._openerService), gitPushSetUpstream(), freePort(this));
this._register(this._contextualActionAddon.onDidRequestRerunCommand((e) => this.sendText(e.command, e.addNewLine || false)));
this._quickFixAddon = this._scopedInstantiationService.createInstance(TerminalQuickFixAddon, this.capabilities);
this.xterm?.raw.loadAddon(this._quickFixAddon);
this.registerQuickFixProvider(gitSimilarCommand(), gitCreatePr(this._openerService), gitPushSetUpstream(), freePort(this));
this._register(this._quickFixAddon.onDidRequestRerunCommand((e) => this.sendText(e.command, e.addNewLine || false)));
const lineDataEventAddon = new LineDataEventAddon();
this.xterm.raw.loadAddon(lineDataEventAddon);
this.updateAccessibilitySupport();
Expand Down
Expand Up @@ -7,7 +7,7 @@ import { IAction } from 'vs/base/common/actions';
import { isWindows } from 'vs/base/common/platform';
import { localize } from 'vs/nls';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ContextualMatchResult, ICommandAction, ITerminalContextualActionOptions, ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
import { QuickFixMatchResult, ITerminalQuickFixAction, ITerminalQuickFixOptions, ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ITerminalCommand } from 'vs/workbench/contrib/terminal/common/terminal';

export const GitCommandLineRegex = /git/;
Expand All @@ -18,19 +18,19 @@ export const FreePortOutputRegex = /address already in use \d\.\d\.\d\.\d:(\d\d\
export const GitPushOutputRegex = /git push --set-upstream origin ([^\s]+)/;
export const GitCreatePrOutputRegex = /Create a pull request for \'([^\s]+)\' on GitHub by visiting:\s+remote:\s+(https:.+pull.+)/;

export function gitSimilarCommand(): ITerminalContextualActionOptions {
export function gitSimilarCommand(): ITerminalQuickFixOptions {
return {
commandLineMatcher: GitCommandLineRegex,
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Run git ${matchResult.outputMatch[1]}` : ``,
outputMatcher: {
lineMatcher: GitSimilarOutputRegex,
anchor: 'bottom',
offset: 0,
length: 3
},
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Run git ${matchResult.outputMatch[1]}` : ``,
exitStatus: false,
getActions: (matchResult: ContextualMatchResult, command: ITerminalCommand) => {
const actions: ICommandAction[] = [];
getQuickFixes: (matchResult: QuickFixMatchResult, command: ITerminalCommand) => {
const actions: ITerminalQuickFixAction[] = [];
const fixedCommand = matchResult?.outputMatch?.[1];
if (!fixedCommand) {
return;
Expand All @@ -46,9 +46,9 @@ export function gitSimilarCommand(): ITerminalContextualActionOptions {
}
};
}
export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITerminalContextualActionOptions {
export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITerminalQuickFixOptions {
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Free port ${matchResult.outputMatch[1]}` : '',
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Free port ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: AnyCommandLineRegex,
// TODO: Support free port on Windows https://github.com/microsoft/vscode/issues/161775
outputMatcher: isWindows ? undefined : {
Expand All @@ -58,12 +58,12 @@ export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITermin
length: 20
},
exitStatus: false,
getActions: (matchResult: ContextualMatchResult, command: ITerminalCommand) => {
getQuickFixes: (matchResult: QuickFixMatchResult, command: ITerminalCommand) => {
const port = matchResult?.outputMatch?.[1];
if (!port) {
return;
}
const actions: ICommandAction[] = [];
const actions: ITerminalQuickFixAction[] = [];
const label = localize("terminal.freePort", "Free port {0}", port);
actions.push({
class: undefined, tooltip: label, id: 'terminal.freePort', label, enabled: true,
Expand All @@ -77,9 +77,9 @@ export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITermin
}
};
}
export function gitPushSetUpstream(): ITerminalContextualActionOptions {
export function gitPushSetUpstream(): ITerminalQuickFixOptions {
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Git push ${matchResult.outputMatch[1]}` : '',
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Git push ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: GitPushCommandLineRegex,
outputMatcher: {
lineMatcher: GitPushOutputRegex,
Expand All @@ -88,12 +88,12 @@ export function gitPushSetUpstream(): ITerminalContextualActionOptions {
length: 5
},
exitStatus: false,
getActions: (matchResult: ContextualMatchResult, command: ITerminalCommand) => {
getQuickFixes: (matchResult: QuickFixMatchResult, command: ITerminalCommand) => {
const branch = matchResult?.outputMatch?.[1];
if (!branch) {
return;
}
const actions: ICommandAction[] = [];
const actions: ITerminalQuickFixAction[] = [];
const label = localize("terminal.gitPush", "Git push {0}", branch);
command.command = `git push --set-upstream origin ${branch}`;
actions.push({
Expand All @@ -107,9 +107,9 @@ export function gitPushSetUpstream(): ITerminalContextualActionOptions {
};
}

export function gitCreatePr(openerService: IOpenerService): ITerminalContextualActionOptions {
export function gitCreatePr(openerService: IOpenerService): ITerminalQuickFixOptions {
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Create PR for ${matchResult.outputMatch[1]}` : '',
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Create PR for ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: GitPushCommandLineRegex,
outputMatcher: {
lineMatcher: GitCreatePrOutputRegex,
Expand All @@ -118,7 +118,7 @@ export function gitCreatePr(openerService: IOpenerService): ITerminalContextualA
length: 5
},
exitStatus: true,
getActions: (matchResult: ContextualMatchResult, command?: ITerminalCommand) => {
getQuickFixes: (matchResult: QuickFixMatchResult, command?: ITerminalCommand) => {
if (!command) {
return;
}
Expand Down