Skip to content

Commit fd06e2f

Browse files
authored
Various terminal quick fix fixes (microsoft#162083)
1 parent 7d99677 commit fd06e2f

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,23 +660,20 @@ export function getOutputMatchForCommand(executedMarker: IMarker | undefined, en
660660
if (outputMatcher?.length && (endLine - startLine) < outputMatcher.length) {
661661
return undefined;
662662
}
663-
let output = '';
664663
let line: string | undefined;
665664
if (outputMatcher?.anchor === 'bottom') {
666665
for (let i = endLine - (outputMatcher.offset || 0); i >= startLine; i--) {
667666
line = getXtermLineContent(buffer, i, i, cols);
668-
output = line + output;
669-
const match = output.match(outputMatcher.lineMatcher);
667+
const match = line.match(outputMatcher.lineMatcher);
670668
if (match) {
671669
return match;
672670
}
673671
}
674672
} else {
675673
for (let i = startLine + (outputMatcher?.offset || 0); i < endLine; i++) {
676674
line = getXtermLineContent(buffer, i, i, cols);
677-
output += line;
678675
if (outputMatcher) {
679-
const match = output.match(outputMatcher.lineMatcher);
676+
const match = line.match(outputMatcher.lineMatcher);
680677
if (match) {
681678
return match;
682679
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,12 @@ export interface ITerminalInstance {
920920
}
921921

922922
export interface ITerminalQuickFixOptions {
923-
quickFixLabel: string | DynamicQuickFixLabel;
924923
commandLineMatcher: string | RegExp;
925924
outputMatcher?: ITerminalOutputMatcher;
926925
getQuickFixes: QuickFixCallback;
927926
exitStatus?: boolean;
928927
}
929928
export type QuickFixMatchResult = { commandLineMatch: RegExpMatchArray; outputMatch?: RegExpMatchArray | null };
930-
export type DynamicQuickFixLabel = (matchResult: QuickFixMatchResult) => string;
931929
export type QuickFixCallback = (matchResult: QuickFixMatchResult, command: ITerminalCommand) => ITerminalQuickFixAction[] | undefined;
932930

933931
export interface ITerminalQuickFixAction extends IAction {

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ export const AnyCommandLineRegex = /.+/;
1515
export const GitSimilarOutputRegex = /most similar command is\s*([^\s]{3,})/;
1616
export const FreePortOutputRegex = /address already in use \d+\.\d+\.\d+\.\d+:(\d{4,5})|Unable to bind [^ ]*:(\d{4,5})|can't listen on port (\d{4,5})|listen EADDRINUSE [^ ]*:(\d{4,5})/;
1717
export const GitPushOutputRegex = /git push --set-upstream origin ([^\s]+)/;
18-
export const GitCreatePrOutputRegex = /Create a pull request for \'([^\s]+)\' on GitHub by visiting:\s*remote:\s*(https:.+pull.+)/;
18+
// The previous line starts with "Create a pull request for \'([^\s]+)\' on GitHub by visiting:\s*",
19+
// it's safe to assume it's a github pull request if the URL includes `/pull/`
20+
export const GitCreatePrOutputRegex = /remote:\s*(https:\/\/github\.com\/.+\/.+\/pull\/new\/.+)/;
1921

2022
export function gitSimilarCommand(): ITerminalQuickFixOptions {
2123
return {
2224
commandLineMatcher: GitCommandLineRegex,
23-
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Run git ${matchResult.outputMatch[1]}` : ``,
2425
outputMatcher: {
2526
lineMatcher: GitSimilarOutputRegex,
2627
anchor: 'bottom',
@@ -34,10 +35,11 @@ export function gitSimilarCommand(): ITerminalQuickFixOptions {
3435
if (!fixedCommand) {
3536
return;
3637
}
37-
const label = localize("terminal.gitSimilarCommand", "Run git {0}", fixedCommand);
38+
const commandToRunInTerminal = `git ${fixedCommand}`;
39+
const label = localize("terminal.runCommand", "Run: {0}", commandToRunInTerminal);
3840
actions.push({
3941
class: undefined, tooltip: label, id: 'terminal.gitSimilarCommand', label, enabled: true,
40-
commandToRunInTerminal: `git ${fixedCommand}`,
42+
commandToRunInTerminal,
4143
addNewLine: true,
4244
run: () => { }
4345
});
@@ -47,7 +49,6 @@ export function gitSimilarCommand(): ITerminalQuickFixOptions {
4749
}
4850
export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITerminalQuickFixOptions {
4951
return {
50-
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Free port ${matchResult.outputMatch[1]}` : '',
5152
commandLineMatcher: AnyCommandLineRegex,
5253
outputMatcher: {
5354
lineMatcher: FreePortOutputRegex,
@@ -77,7 +78,6 @@ export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITermin
7778
}
7879
export function gitPushSetUpstream(): ITerminalQuickFixOptions {
7980
return {
80-
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Git push ${matchResult.outputMatch[1]}` : '',
8181
commandLineMatcher: GitPushCommandLineRegex,
8282
outputMatcher: {
8383
lineMatcher: GitPushOutputRegex,
@@ -92,11 +92,11 @@ export function gitPushSetUpstream(): ITerminalQuickFixOptions {
9292
return;
9393
}
9494
const actions: ITerminalQuickFixAction[] = [];
95-
const label = localize("terminal.gitPush", "Git push {0}", branch);
96-
command.command = `git push --set-upstream origin ${branch}`;
95+
const commandToRunInTerminal = `git push --set-upstream origin ${branch}`;
96+
const label = localize("terminal.runCommand", "Run: {0}", commandToRunInTerminal);
9797
actions.push({
9898
class: undefined, tooltip: label, id: 'terminal.gitPush', label, enabled: true,
99-
commandToRunInTerminal: command.command,
99+
commandToRunInTerminal,
100100
addNewLine: true,
101101
run: () => { }
102102
});
@@ -107,7 +107,6 @@ export function gitPushSetUpstream(): ITerminalQuickFixOptions {
107107

108108
export function gitCreatePr(openerService: IOpenerService): ITerminalQuickFixOptions {
109109
return {
110-
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Create PR for ${matchResult.outputMatch[1]}` : '',
111110
commandLineMatcher: GitPushCommandLineRegex,
112111
outputMatcher: {
113112
lineMatcher: GitCreatePrOutputRegex,
@@ -120,13 +119,12 @@ export function gitCreatePr(openerService: IOpenerService): ITerminalQuickFixOpt
120119
if (!command) {
121120
return;
122121
}
123-
const branch = matchResult?.outputMatch?.[1];
124-
const link = matchResult?.outputMatch?.[2];
125-
if (!branch || !link) {
122+
const link = matchResult?.outputMatch?.[1];
123+
if (!link) {
126124
return;
127125
}
128126
const actions: IAction[] = [];
129-
const label = localize("terminal.gitCreatePr", "Create PR");
127+
const label = localize("terminal.openLink", "Open link: {0}", link);
130128
actions.push({
131129
class: undefined, tooltip: label, id: 'terminal.gitCreatePr', label, enabled: true,
132130
run: () => openerService.open(link)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ suite('QuickFixAddon', () => {
5656
const actions = [
5757
{
5858
id: 'terminal.gitSimilarCommand',
59-
label: 'Run git status',
59+
label: 'Run: git status',
6060
run: true,
61-
tooltip: 'Run git status',
61+
tooltip: 'Run: git status',
6262
enabled: true
6363
}
6464
];
@@ -136,9 +136,9 @@ suite('QuickFixAddon', () => {
136136
const actions = [
137137
{
138138
id: 'terminal.gitPush',
139-
label: 'Git push test22',
139+
label: 'Run: git push --set-upstream origin test22',
140140
run: true,
141-
tooltip: 'Git push test22',
141+
tooltip: 'Run: git push --set-upstream origin test22',
142142
enabled: true
143143
}
144144
];
@@ -179,9 +179,9 @@ suite('QuickFixAddon', () => {
179179
const actions = [
180180
{
181181
id: 'terminal.gitCreatePr',
182-
label: 'Create PR',
182+
label: 'Open link: https://github.com/meganrogge/xterm.js/pull/new/test22',
183183
run: true,
184-
tooltip: 'Create PR',
184+
tooltip: 'Open link: https://github.com/meganrogge/xterm.js/pull/new/test22',
185185
enabled: true
186186
}
187187
];
@@ -219,9 +219,9 @@ suite('QuickFixAddon', () => {
219219
const actions = [
220220
{
221221
id: 'terminal.gitPush',
222-
label: 'Git push test22',
222+
label: 'Run: git push --set-upstream origin test22',
223223
run: true,
224-
tooltip: 'Git push test22',
224+
tooltip: 'Run: git push --set-upstream origin test22',
225225
enabled: true
226226
}
227227
];

0 commit comments

Comments
 (0)