Skip to content

Commit

Permalink
contribute git push quick fix as test
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Oct 20, 2022
1 parent 7f24e91 commit 0d97708
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { IDetectedLinks, TerminalLinkManager } from 'vs/workbench/contrib/termin
import { TerminalLinkQuickpick } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkQuickpick';
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, gitTwoDashes } from 'vs/workbench/contrib/terminal/browser/terminalQuickFixBuiltinActions';
import { gitSimilarCommand, gitCreatePr, freePort, gitTwoDashes } 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 Down Expand Up @@ -731,7 +731,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this.xterm = xterm;
this._quickFixAddon = this._scopedInstantiationService.createInstance(TerminalQuickFixAddon, this.capabilities);
this.xterm?.raw.loadAddon(this._quickFixAddon);
this.registerQuickFixProvider(gitSimilarCommand(), gitTwoDashes(), gitCreatePr(), gitPushSetUpstream(), freePort(this));
this.registerQuickFixProvider(gitSimilarCommand(), gitTwoDashes(), gitCreatePr(), freePort(this));
this._register(this._quickFixAddon.onDidRequestRerunCommand(async (e) => await this.runCommand(e.command, e.addNewLine || false)));
const lineDataEventAddon = new LineDataEventAddon();
this.xterm.raw.loadAddon(lineDataEventAddon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const GitTwoDashesRegex = /error: did you mean `--(.+)` \(with two dashes
export const AnyCommandLineRegex = /.+/;
export const GitSimilarOutputRegex = /(?:(most similar (command|commands) (is|are)))((\n\s*[^\s]+)+)/m;
export const FreePortOutputRegex = /address already in use (0\.0\.0\.0|127\.0\.0\.1|localhost|::):(?<portNumber>\d{4,5})|Unable to bind [^ ]*:(\d{4,5})|can't listen on port (\d{4,5})|listen EADDRINUSE [^ ]*:(\d{4,5})/;
export const GitPushOutputRegex = /git push --set-upstream origin ([^\s]+)/;
export const GitPushOutputRegex = /git push --set-upstream origin (?<branch>[^\s]+)/;
// The previous line starts with "Create a pull request for \'([^\s]+)\' on GitHub by visiting:\s*"
// it's safe to assume it's a github pull request if the URL includes `/pull/`
export const GitCreatePrOutputRegex = /remote:\s*(https:\/\/github\.com\/.+\/.+\/pull\/new\/.+)/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { flatten } from 'vs/base/common/arrays';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IExtensionTerminalProfile, IExtensionTerminalQuickFix, ITerminalContributions, ITerminalProfileContribution } from 'vs/platform/terminal/common/terminal';
import { URI } from 'vs/base/common/uri';
export const GitPushCommandLineRegex = /git\s+push/;
export const GitPushOutputRegex = /git push --set-upstream origin (?<branch>[^\s]+)/;

// terminal extension point
export const terminalsExtPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint<ITerminalContributions>(terminalContributionsDescriptor);
Expand Down Expand Up @@ -39,6 +41,19 @@ export class TerminalContributionService implements ITerminalContributionService
}) || [];
}));
this._quickFixes = flatten(contributions.map(c => c.value.quickFixes ? c.value.quickFixes.map(fix => { return { ...fix, extensionIdentifier: c.description.identifier.value }; }) : []));
this._quickFixes.push({
id: 'Git Push Set Upstream',
commandLineMatcher: GitPushCommandLineRegex,
outputMatcher: {
lineMatcher: GitPushOutputRegex,
anchor: 'bottom',
offset: 0,
length: 5
},
exitStatus: false,
extensionIdentifier: 'Git',
commandToRun: 'git push --set-upstream origin {branch}'
});
});
}
}
Expand Down

0 comments on commit 0d97708

Please sign in to comment.