Skip to content

Commit c43b97e

Browse files
committed
Remove terminal task dependency on getDefaultShell
Part of microsoft#69113
1 parent 03394ab commit c43b97e

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/wor
9191
import { RunAutomaticTasks, AllowAutomaticTaskRunning, DisallowAutomaticTaskRunning } from 'vs/workbench/contrib/tasks/electron-browser/runAutomaticTasks';
9292

9393
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
94+
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
9495

9596
let tasksCategory = nls.localize('tasksCategory', "Tasks");
9697

@@ -355,7 +356,8 @@ class TaskService extends Disposable implements ITaskService {
355356
@INotificationService private readonly notificationService: INotificationService,
356357
@IContextKeyService contextKeyService: IContextKeyService,
357358
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
358-
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService
359+
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
360+
@ITerminalInstanceService private readonly terminalInstanceService: ITerminalInstanceService,
359361
) {
360362
super();
361363

@@ -1235,7 +1237,7 @@ class TaskService extends Disposable implements ITaskService {
12351237
this.terminalService, this.outputService, this.panelService, this.markerService,
12361238
this.modelService, this.configurationResolverService, this.telemetryService,
12371239
this.contextService, this.environmentService,
1238-
TaskService.OutputChannelId, this.fileService,
1240+
TaskService.OutputChannelId, this.fileService, this.terminalInstanceService,
12391241
(workspaceFolder: IWorkspaceFolder) => {
12401242
if (!workspaceFolder) {
12411243
return undefined;

src/vs/workbench/contrib/tasks/electron-browser/terminalTaskSystem.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
4242
import { URI } from 'vs/base/common/uri';
4343
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
4444
import { Schemas } from 'vs/base/common/network';
45-
import { getDefaultShell } from 'vs/workbench/contrib/terminal/node/terminal';
4645
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
46+
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
4747

4848
interface TerminalData {
4949
terminal: ITerminalInstance;
@@ -172,6 +172,7 @@ export class TerminalTaskSystem implements ITaskSystem {
172172
private environmentService: IWorkbenchEnvironmentService,
173173
private outputChannelId: string,
174174
private fileService: IFileService,
175+
private terminalInstanceService: ITerminalInstanceService,
175176
taskSystemInfoResolver: TaskSystemInfoResolver,
176177
) {
177178

@@ -751,6 +752,25 @@ export class TerminalTaskSystem implements ITaskSystem {
751752
return nls.localize('TerminalTaskSystem.terminalName', 'Task - {0}', needsFolderQualification ? task.getQualifiedLabel() : task.configurationProperties.name);
752753
}
753754

755+
private getDefaultShell(platform: Platform.Platform): string {
756+
let defaultShell: string | undefined = undefined;
757+
try {
758+
defaultShell = this.terminalInstanceService.getDefaultShell(platform);
759+
} catch {
760+
// Do nothing
761+
}
762+
if (!defaultShell) {
763+
// Make up a guess for the default shell.
764+
if (platform === Platform.Platform.Windows) {
765+
defaultShell = 'cmd.exe';
766+
} else {
767+
defaultShell = 'bash.exe';
768+
}
769+
console.warn('Cannot get the default shell.');
770+
}
771+
return defaultShell;
772+
}
773+
754774
private createShellLaunchConfig(task: CustomTask | ContributedTask, variableResolver: VariableResolver, platform: Platform.Platform, options: CommandOptions, command: CommandString, args: CommandString[], waitOnExit: boolean | string): IShellLaunchConfig | undefined {
755775
let shellLaunchConfig: IShellLaunchConfig;
756776
let isShellCommand = task.command.runtime === RuntimeType.Shell;
@@ -759,7 +779,7 @@ export class TerminalTaskSystem implements ITaskSystem {
759779
let originalCommand = task.command.name;
760780
if (isShellCommand) {
761781
shellLaunchConfig = { name: terminalName, executable: undefined, args: undefined, waitOnExit };
762-
this.terminalService.configHelper.mergeDefaultShellPathAndArgs(shellLaunchConfig, getDefaultShell(platform), platform);
782+
this.terminalService.configHelper.mergeDefaultShellPathAndArgs(shellLaunchConfig, this.getDefaultShell(platform), platform);
763783
let shellSpecified: boolean = false;
764784
let shellOptions: ShellConfiguration | undefined = task.command.options && task.command.options.shell;
765785
if (shellOptions) {

0 commit comments

Comments
 (0)