mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Various terminal quick fix fixes (#162083)
This commit is contained in:
parent
7d9967760d
commit
fd06e2ffd9
|
@ -660,13 +660,11 @@ export function getOutputMatchForCommand(executedMarker: IMarker | undefined, en
|
|||
if (outputMatcher?.length && (endLine - startLine) < outputMatcher.length) {
|
||||
return undefined;
|
||||
}
|
||||
let output = '';
|
||||
let line: string | undefined;
|
||||
if (outputMatcher?.anchor === 'bottom') {
|
||||
for (let i = endLine - (outputMatcher.offset || 0); i >= startLine; i--) {
|
||||
line = getXtermLineContent(buffer, i, i, cols);
|
||||
output = line + output;
|
||||
const match = output.match(outputMatcher.lineMatcher);
|
||||
const match = line.match(outputMatcher.lineMatcher);
|
||||
if (match) {
|
||||
return match;
|
||||
}
|
||||
|
@ -674,9 +672,8 @@ export function getOutputMatchForCommand(executedMarker: IMarker | undefined, en
|
|||
} else {
|
||||
for (let i = startLine + (outputMatcher?.offset || 0); i < endLine; i++) {
|
||||
line = getXtermLineContent(buffer, i, i, cols);
|
||||
output += line;
|
||||
if (outputMatcher) {
|
||||
const match = output.match(outputMatcher.lineMatcher);
|
||||
const match = line.match(outputMatcher.lineMatcher);
|
||||
if (match) {
|
||||
return match;
|
||||
}
|
||||
|
|
|
@ -920,14 +920,12 @@ export interface ITerminalInstance {
|
|||
}
|
||||
|
||||
export interface ITerminalQuickFixOptions {
|
||||
quickFixLabel: string | DynamicQuickFixLabel;
|
||||
commandLineMatcher: string | RegExp;
|
||||
outputMatcher?: ITerminalOutputMatcher;
|
||||
getQuickFixes: QuickFixCallback;
|
||||
exitStatus?: boolean;
|
||||
}
|
||||
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 ITerminalQuickFixAction extends IAction {
|
||||
|
|
|
@ -15,12 +15,13 @@ export const AnyCommandLineRegex = /.+/;
|
|||
export const GitSimilarOutputRegex = /most similar command is\s*([^\s]{3,})/;
|
||||
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})/;
|
||||
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.+)/;
|
||||
// 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\/.+)/;
|
||||
|
||||
export function gitSimilarCommand(): ITerminalQuickFixOptions {
|
||||
return {
|
||||
commandLineMatcher: GitCommandLineRegex,
|
||||
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Run git ${matchResult.outputMatch[1]}` : ``,
|
||||
outputMatcher: {
|
||||
lineMatcher: GitSimilarOutputRegex,
|
||||
anchor: 'bottom',
|
||||
|
@ -34,10 +35,11 @@ export function gitSimilarCommand(): ITerminalQuickFixOptions {
|
|||
if (!fixedCommand) {
|
||||
return;
|
||||
}
|
||||
const label = localize("terminal.gitSimilarCommand", "Run git {0}", fixedCommand);
|
||||
const commandToRunInTerminal = `git ${fixedCommand}`;
|
||||
const label = localize("terminal.runCommand", "Run: {0}", commandToRunInTerminal);
|
||||
actions.push({
|
||||
class: undefined, tooltip: label, id: 'terminal.gitSimilarCommand', label, enabled: true,
|
||||
commandToRunInTerminal: `git ${fixedCommand}`,
|
||||
commandToRunInTerminal,
|
||||
addNewLine: true,
|
||||
run: () => { }
|
||||
});
|
||||
|
@ -47,7 +49,6 @@ export function gitSimilarCommand(): ITerminalQuickFixOptions {
|
|||
}
|
||||
export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITerminalQuickFixOptions {
|
||||
return {
|
||||
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Free port ${matchResult.outputMatch[1]}` : '',
|
||||
commandLineMatcher: AnyCommandLineRegex,
|
||||
outputMatcher: {
|
||||
lineMatcher: FreePortOutputRegex,
|
||||
|
@ -77,7 +78,6 @@ export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITermin
|
|||
}
|
||||
export function gitPushSetUpstream(): ITerminalQuickFixOptions {
|
||||
return {
|
||||
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Git push ${matchResult.outputMatch[1]}` : '',
|
||||
commandLineMatcher: GitPushCommandLineRegex,
|
||||
outputMatcher: {
|
||||
lineMatcher: GitPushOutputRegex,
|
||||
|
@ -92,11 +92,11 @@ export function gitPushSetUpstream(): ITerminalQuickFixOptions {
|
|||
return;
|
||||
}
|
||||
const actions: ITerminalQuickFixAction[] = [];
|
||||
const label = localize("terminal.gitPush", "Git push {0}", branch);
|
||||
command.command = `git push --set-upstream origin ${branch}`;
|
||||
const commandToRunInTerminal = `git push --set-upstream origin ${branch}`;
|
||||
const label = localize("terminal.runCommand", "Run: {0}", commandToRunInTerminal);
|
||||
actions.push({
|
||||
class: undefined, tooltip: label, id: 'terminal.gitPush', label, enabled: true,
|
||||
commandToRunInTerminal: command.command,
|
||||
commandToRunInTerminal,
|
||||
addNewLine: true,
|
||||
run: () => { }
|
||||
});
|
||||
|
@ -107,7 +107,6 @@ export function gitPushSetUpstream(): ITerminalQuickFixOptions {
|
|||
|
||||
export function gitCreatePr(openerService: IOpenerService): ITerminalQuickFixOptions {
|
||||
return {
|
||||
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Create PR for ${matchResult.outputMatch[1]}` : '',
|
||||
commandLineMatcher: GitPushCommandLineRegex,
|
||||
outputMatcher: {
|
||||
lineMatcher: GitCreatePrOutputRegex,
|
||||
|
@ -120,13 +119,12 @@ export function gitCreatePr(openerService: IOpenerService): ITerminalQuickFixOpt
|
|||
if (!command) {
|
||||
return;
|
||||
}
|
||||
const branch = matchResult?.outputMatch?.[1];
|
||||
const link = matchResult?.outputMatch?.[2];
|
||||
if (!branch || !link) {
|
||||
const link = matchResult?.outputMatch?.[1];
|
||||
if (!link) {
|
||||
return;
|
||||
}
|
||||
const actions: IAction[] = [];
|
||||
const label = localize("terminal.gitCreatePr", "Create PR");
|
||||
const label = localize("terminal.openLink", "Open link: {0}", link);
|
||||
actions.push({
|
||||
class: undefined, tooltip: label, id: 'terminal.gitCreatePr', label, enabled: true,
|
||||
run: () => openerService.open(link)
|
||||
|
|
|
@ -56,9 +56,9 @@ suite('QuickFixAddon', () => {
|
|||
const actions = [
|
||||
{
|
||||
id: 'terminal.gitSimilarCommand',
|
||||
label: 'Run git status',
|
||||
label: 'Run: git status',
|
||||
run: true,
|
||||
tooltip: 'Run git status',
|
||||
tooltip: 'Run: git status',
|
||||
enabled: true
|
||||
}
|
||||
];
|
||||
|
@ -136,9 +136,9 @@ suite('QuickFixAddon', () => {
|
|||
const actions = [
|
||||
{
|
||||
id: 'terminal.gitPush',
|
||||
label: 'Git push test22',
|
||||
label: 'Run: git push --set-upstream origin test22',
|
||||
run: true,
|
||||
tooltip: 'Git push test22',
|
||||
tooltip: 'Run: git push --set-upstream origin test22',
|
||||
enabled: true
|
||||
}
|
||||
];
|
||||
|
@ -179,9 +179,9 @@ suite('QuickFixAddon', () => {
|
|||
const actions = [
|
||||
{
|
||||
id: 'terminal.gitCreatePr',
|
||||
label: 'Create PR',
|
||||
label: 'Open link: https://github.com/meganrogge/xterm.js/pull/new/test22',
|
||||
run: true,
|
||||
tooltip: 'Create PR',
|
||||
tooltip: 'Open link: https://github.com/meganrogge/xterm.js/pull/new/test22',
|
||||
enabled: true
|
||||
}
|
||||
];
|
||||
|
@ -219,9 +219,9 @@ suite('QuickFixAddon', () => {
|
|||
const actions = [
|
||||
{
|
||||
id: 'terminal.gitPush',
|
||||
label: 'Git push test22',
|
||||
label: 'Run: git push --set-upstream origin test22',
|
||||
run: true,
|
||||
tooltip: 'Git push test22',
|
||||
tooltip: 'Run: git push --set-upstream origin test22',
|
||||
enabled: true
|
||||
}
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue