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

Enforce all properties on output matchers #161779

Merged
merged 1 commit 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: 19 additions & 3 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,27 @@ export interface ICommandAction extends IAction {
addNewLine?: boolean;
}

/**
* A matcher that runs on a sub-section of a terminal command's output
*/
export interface ITerminalOutputMatcher {
/**
* A string or regex to match against the unwrapped line.
*/
lineMatcher: string | RegExp;
anchor?: 'top' | 'bottom';
offset?: number;
length?: number;
/**
* Which side of the output to anchor the {@link offset} and {@link length} against.
*/
anchor: 'top' | 'bottom';
/**
* How far from either the top or the bottom of the butter to start matching against.
*/
offset: number;
/**
* The number of rows to match against, this should be as small as possible for performance
* reasons.
*/
length: number;
}

export interface IXtermTerminal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export const GitCreatePrOutputRegex = /Create a pull request for \'([^\s]+)\' on
export function gitSimilarCommand(): ITerminalContextualActionOptions {
return {
commandLineMatcher: GitCommandLineRegex,
outputMatcher: { lineMatcher: GitSimilarOutputRegex, anchor: 'bottom' },
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) => {
Expand All @@ -45,7 +50,14 @@ export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITermin
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Free port ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: AnyCommandLineRegex,
outputMatcher: !isWindows ? { lineMatcher: FreePortOutputRegex, anchor: 'bottom' } : undefined,
// TODO: Support free port on Windows https://github.com/microsoft/vscode/issues/161775
outputMatcher: isWindows ? undefined : {
lineMatcher: FreePortOutputRegex,
anchor: 'bottom',
offset: 0,
length: 20
},
exitStatus: false,
getActions: (matchResult: ContextualMatchResult, command: ITerminalCommand) => {
const port = matchResult?.outputMatch?.[1];
if (!port) {
Expand All @@ -69,7 +81,12 @@ export function gitPushSetUpstream(): ITerminalContextualActionOptions {
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Git push ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: GitPushCommandLineRegex,
outputMatcher: { lineMatcher: GitPushOutputRegex, anchor: 'bottom' },
outputMatcher: {
lineMatcher: GitPushOutputRegex,
anchor: 'bottom',
offset: 0,
length: 5
},
exitStatus: false,
getActions: (matchResult: ContextualMatchResult, command: ITerminalCommand) => {
const branch = matchResult?.outputMatch?.[1];
Expand All @@ -94,7 +111,12 @@ export function gitCreatePr(openerService: IOpenerService): ITerminalContextualA
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Create PR for ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: GitPushCommandLineRegex,
outputMatcher: { lineMatcher: GitCreatePrOutputRegex, anchor: 'bottom' },
outputMatcher: {
lineMatcher: GitCreatePrOutputRegex,
anchor: 'bottom',
offset: 0,
length: 5
},
exitStatus: true,
getActions: (matchResult: ContextualMatchResult, command?: ITerminalCommand) => {
if (!command) {
Expand Down