Allow duplication of task shell args

Fixes #136459
This commit is contained in:
Alex Ross 2021-12-08 15:58:20 +01:00
parent 920fc15008
commit 327c71fdef
No known key found for this signature in database
GPG key ID: 89DDDBA66CBA7840

View file

@ -1128,13 +1128,9 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
toAdd.push('-c');
}
}
toAdd.forEach(element => {
if (!shellArgs.some(arg => arg.toLowerCase() === element)) {
shellArgs.push(element);
}
});
shellArgs.push(commandLine);
shellLaunchConfig.args = windowsShellArgs ? shellArgs.join(' ') : shellArgs;
const combinedShellArgs = this.addAllArgument(toAdd, shellArgs);
combinedShellArgs.push(commandLine);
shellLaunchConfig.args = windowsShellArgs ? combinedShellArgs.join(' ') : combinedShellArgs;
if (task.command.presentation && task.command.presentation.echo) {
if (needsFolderQualification && workspaceFolder) {
shellLaunchConfig.initialText = `\x1b[1m> Executing task in folder ${workspaceFolder.name}: ${commandLine} <\x1b[0m\n`;
@ -1196,6 +1192,24 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
return shellLaunchConfig;
}
private addAllArgument(shellCommandArgs: string[], configuredShellArgs: string[]): string[] {
const combinedShellArgs: string[] = Objects.deepClone(configuredShellArgs);
shellCommandArgs.forEach(element => {
const shouldAddShellCommandArg = configuredShellArgs.every((arg, index) => {
if ((arg.toLowerCase() === element) && (configuredShellArgs.length > index + 1)) {
// We can still add the argument, but only if not all of the following arguments begin with "-".
return !configuredShellArgs.slice(index + 1).every(testArg => testArg.startsWith('-'));
} else {
return arg.toLowerCase() !== element;
}
});
if (shouldAddShellCommandArg) {
combinedShellArgs.push(element);
}
});
return combinedShellArgs;
}
private async doCreateTerminal(group: string | undefined, launchConfigs: IShellLaunchConfig): Promise<ITerminalInstance> {
if (group) {
// Try to find an existing terminal to split.