From fc3cc5b1c6eb2f56a8ff194cef8844da393652cf Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:02:45 +0800 Subject: [PATCH] Fix custom task shell doesn't work without manually passing in "run command" arg/flag (#181760) --- .../tasks/browser/terminalTaskSystem.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index 045a9e63b4416..45a7b5d022ce6 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -1111,7 +1111,6 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { color: task.configurationProperties.icon?.color || undefined, waitOnExit }; - let shellSpecified: boolean = false; const shellOptions: IShellConfiguration | undefined = task.command.options && task.command.options.shell; if (shellOptions) { if (shellOptions.executable) { @@ -1120,12 +1119,12 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { shellLaunchConfig.args = undefined; } shellLaunchConfig.executable = await this._resolveVariable(variableResolver, shellOptions.executable); - shellSpecified = true; } if (shellOptions.args) { shellLaunchConfig.args = await this._resolveVariables(variableResolver, shellOptions.args.slice()); } } + const shellArgsSpecified: boolean = shellLaunchConfig.args !== undefined; if (shellLaunchConfig.args === undefined) { shellLaunchConfig.args = []; } @@ -1138,29 +1137,29 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { windowsShellArgs = true; // If we don't have a cwd, then the terminal uses the home dir. const userHome = await this._pathService.userHome(); - if (basename === 'cmd.exe' && ((options.cwd && isUNC(options.cwd)) || (!options.cwd && isUNC(userHome.fsPath)))) { - return undefined; - } - if ((basename === 'powershell.exe') || (basename === 'pwsh.exe')) { - if (!shellSpecified) { + if (basename === 'cmd.exe') { + if ((options.cwd && isUNC(options.cwd)) || (!options.cwd && isUNC(userHome.fsPath))) { + return undefined; + } + if (!shellArgsSpecified) { + toAdd.push('/d', '/c'); + } + } else if ((basename === 'powershell.exe') || (basename === 'pwsh.exe')) { + if (!shellArgsSpecified) { toAdd.push('-Command'); } } else if ((basename === 'bash.exe') || (basename === 'zsh.exe')) { windowsShellArgs = false; - if (!shellSpecified) { + if (!shellArgsSpecified) { toAdd.push('-c'); } } else if (basename === 'wsl.exe') { - if (!shellSpecified) { + if (!shellArgsSpecified) { toAdd.push('-e'); } - } else { - if (!shellSpecified) { - toAdd.push('/d', '/c'); - } } } else { - if (!shellSpecified) { + if (!shellArgsSpecified) { // Under Mac remove -l to not start it as a login shell. if (platform === Platform.Platform.Mac) { // Background on -l on osx https://github.com/microsoft/vscode/issues/107563 @@ -1267,11 +1266,12 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { const combinedShellArgs: string[] = Objects.deepClone(configuredShellArgs); shellCommandArgs.forEach(element => { const shouldAddShellCommandArg = configuredShellArgs.every((arg, index) => { - if ((arg.toLowerCase() === element) && (configuredShellArgs.length > index + 1)) { + const isDuplicated = arg.toLowerCase() === element.toLowerCase(); + if (isDuplicated && (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; + return !isDuplicated; } }); if (shouldAddShellCommandArg) {