Skip to content

Commit 0aab08e

Browse files
committed
Add getDefaultShellAndArgs
Also differentiate default from system shell
1 parent 87e1650 commit 0aab08e

14 files changed

Lines changed: 98 additions & 36 deletions

File tree

src/vs/workbench/api/browser/mainThreadTerminalService.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
7-
import { ITerminalService, ITerminalInstance, IShellLaunchConfig, ITerminalProcessExtHostProxy, ITerminalProcessExtHostRequest, ITerminalDimensions, EXT_HOST_CREATION_DELAY, IShellDefinition } from 'vs/workbench/contrib/terminal/common/terminal';
7+
import { ITerminalService, ITerminalInstance, IShellLaunchConfig, ITerminalProcessExtHostProxy, ITerminalProcessExtHostRequest, ITerminalDimensions, EXT_HOST_CREATION_DELAY } from 'vs/workbench/contrib/terminal/common/terminal';
88
import { ExtHostContext, ExtHostTerminalServiceShape, MainThreadTerminalServiceShape, MainContext, IExtHostContext, ShellLaunchConfigDto } from 'vs/workbench/api/common/extHost.protocol';
99
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
1010
import { UriComponents, URI } from 'vs/base/common/uri';
@@ -46,11 +46,14 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
4646
this._toDispose.push(_terminalService.onActiveInstanceChanged(instance => this._onActiveTerminalChanged(instance ? instance.id : null)));
4747
this._toDispose.push(_terminalService.onInstanceTitleChanged(instance => this._onTitleChanged(instance.id, instance.title)));
4848
this._toDispose.push(_terminalService.configHelper.onWorkspacePermissionsChanged(isAllowed => this._onWorkspacePermissionsChanged(isAllowed)));
49-
this._toDispose.push(_terminalService.onRequestAvailableShells(r => this._onRequestAvailableShells(r)));
49+
this._toDispose.push(_terminalService.onRequestAvailableShells(r => this._proxy.$requestAvailableShells().then(e => r(e))));
5050

5151
// ITerminalInstanceService listeners
5252
if (terminalInstanceService.onRequestDefaultShell) {
53-
this._toDispose.push(terminalInstanceService.onRequestDefaultShell(r => this._onRequestDefaultShell(r)));
53+
this._toDispose.push(terminalInstanceService.onRequestDefaultShell(r => this._proxy.$requestDefaultShell().then(e => r(e))));
54+
}
55+
if (terminalInstanceService.onRequestDefaultShellAndArgs) {
56+
this._toDispose.push(terminalInstanceService.onRequestDefaultShellAndArgs(r => this._proxy.$requestDefaultShellAndArgs().then(e => r(e.shell, e.args))));
5457
}
5558

5659
// Set initial ext host state
@@ -285,12 +288,4 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
285288
}
286289
this._terminalProcesses[terminalId].emitLatency(sum / COUNT);
287290
}
288-
289-
private _onRequestAvailableShells(resolve: (shells: IShellDefinition[]) => void): void {
290-
this._proxy.$requestAvailableShells().then(e => resolve(e));
291-
}
292-
293-
private _onRequestDefaultShell(resolve: (defaultShell: string) => void): void {
294-
this._proxy.$requestDefaultShell().then(e => resolve(e));
295-
}
296291
}

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,11 @@ export interface IShellDefinitionDto {
11111111
path: string;
11121112
}
11131113

1114+
export interface IShellAndArgsDto {
1115+
shell: string;
1116+
args: string[] | string | undefined;
1117+
}
1118+
11141119
export interface ExtHostTerminalServiceShape {
11151120
$acceptTerminalClosed(id: number): void;
11161121
$acceptTerminalOpened(id: number, name: string): void;
@@ -1130,6 +1135,7 @@ export interface ExtHostTerminalServiceShape {
11301135
$acceptWorkspacePermissionsChanged(isAllowed: boolean): void;
11311136
$requestAvailableShells(): Promise<IShellDefinitionDto[]>;
11321137
$requestDefaultShell(): Promise<string>;
1138+
$requestDefaultShellAndArgs(): Promise<IShellAndArgsDto>;
11331139
}
11341140

11351141
export interface ExtHostSCMShape {

src/vs/workbench/api/node/extHostTerminalService.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
1010
import * as platform from 'vs/base/common/platform';
1111
import * as terminalEnvironment from 'vs/workbench/contrib/terminal/common/terminalEnvironment';
1212
import { Event, Emitter } from 'vs/base/common/event';
13-
import { ExtHostTerminalServiceShape, MainContext, MainThreadTerminalServiceShape, IMainContext, ShellLaunchConfigDto, IShellDefinitionDto } from 'vs/workbench/api/common/extHost.protocol';
13+
import { ExtHostTerminalServiceShape, MainContext, MainThreadTerminalServiceShape, IMainContext, ShellLaunchConfigDto, IShellDefinitionDto, IShellAndArgsDto } from 'vs/workbench/api/common/extHost.protocol';
1414
import { ExtHostConfiguration, ExtHostConfigProvider } from 'vs/workbench/api/common/extHostConfiguration';
1515
import { ILogService } from 'vs/platform/log/common/log';
1616
import { EXT_HOST_CREATION_DELAY, IShellLaunchConfig, ITerminalEnvironment } from 'vs/workbench/contrib/terminal/common/terminal';
@@ -20,7 +20,7 @@ import { ExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
2020
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
2121
import { ExtHostVariableResolverService } from 'vs/workbench/api/node/extHostDebugService';
2222
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
23-
import { getDefaultShell, detectAvailableShells } from 'vs/workbench/contrib/terminal/node/terminal';
23+
import { getSystemShell, detectAvailableShells } from 'vs/workbench/contrib/terminal/node/terminal';
2424

2525
const RENDERER_NO_PROCESS_ID = -1;
2626

@@ -338,12 +338,22 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
338338
return terminalEnvironment.getDefaultShell(
339339
fetchSetting,
340340
this._isWorkspaceShellAllowed,
341-
getDefaultShell(platform.platform),
341+
getSystemShell(platform.platform),
342342
process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'),
343343
process.env.windir
344344
);
345345
}
346346

347+
private _getDefaultShellArgs(configProvider: ExtHostConfigProvider): string[] | string | undefined {
348+
const fetchSetting = (key: string) => {
349+
const setting = configProvider
350+
.getConfiguration(key.substr(0, key.lastIndexOf('.')))
351+
.inspect<string | string[]>(key.substr(key.lastIndexOf('.') + 1));
352+
return this._apiInspectConfigToPlain<string | string[]>(setting);
353+
};
354+
return terminalEnvironment.getDefaultShellArgs(fetchSetting, this._isWorkspaceShellAllowed);
355+
}
356+
347357
public async resolveTerminalRenderer(id: number): Promise<vscode.TerminalRenderer> {
348358
// Check to see if the extension host already knows about this terminal.
349359
for (const terminalRenderer of this._terminalRenderers) {
@@ -495,7 +505,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
495505
shellLaunchConfig,
496506
fetchSetting,
497507
isWorkspaceShellAllowed || false,
498-
getDefaultShell(platform.platform),
508+
getSystemShell(platform.platform),
499509
process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'),
500510
process.env.windir
501511
);
@@ -579,8 +589,17 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
579589
return detectAvailableShells();
580590
}
581591

592+
// TODO: Remove this once requestDefaultShellAndArgs is working
582593
public $requestDefaultShell(): Promise<string> {
583-
return Promise.resolve(getDefaultShell(platform.platform));
594+
return Promise.resolve(getSystemShell(platform.platform));
595+
}
596+
597+
public async $requestDefaultShellAndArgs(): Promise<IShellAndArgsDto> {
598+
const configProvider = await this._extHostConfiguration.getConfigProvider();
599+
return Promise.resolve({
600+
shell: this.getDefaultShell(configProvider),
601+
args: this._getDefaultShellArgs(configProvider)
602+
});
584603
}
585604

586605
private _onProcessExit(id: number, exitCode: number): void {

src/vs/workbench/contrib/debug/node/terminals.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as pfs from 'vs/base/node/pfs';
1010
import { assign } from 'vs/base/common/objects';
1111
import { ITerminalLauncher, ITerminalSettings } from 'vs/workbench/contrib/debug/common/debug';
1212
import { getPathFromAmdModule } from 'vs/base/common/amd';
13-
import { getDefaultShell } from 'vs/workbench/contrib/terminal/node/terminal';
13+
import { getSystemShell } from 'vs/workbench/contrib/terminal/node/terminal';
1414

1515
const TERMINAL_TITLE = nls.localize('console.title', "VS Code Console");
1616

@@ -315,13 +315,13 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
315315
let shell: string;
316316
const shell_config = config.integrated.shell;
317317
if (env.isWindows) {
318-
shell = shell_config.windows || getDefaultShell(env.Platform.Windows);
318+
shell = shell_config.windows || getSystemShell(env.Platform.Windows);
319319
shellType = ShellType.cmd;
320320
} else if (env.isLinux) {
321-
shell = shell_config.linux || getDefaultShell(env.Platform.Linux);
321+
shell = shell_config.linux || getSystemShell(env.Platform.Linux);
322322
shellType = ShellType.bash;
323323
} else if (env.isMacintosh) {
324-
shell = shell_config.osx || getDefaultShell(env.Platform.Mac);
324+
shell = shell_config.osx || getSystemShell(env.Platform.Mac);
325325
shellType = ShellType.bash;
326326
} else {
327327
throw new Error('Unknown platform');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,8 @@ export class TerminalTaskSystem implements ITaskSystem {
778778
let terminalName = this.createTerminalName(task);
779779
let originalCommand = task.command.name;
780780
if (isShellCommand) {
781-
shellLaunchConfig = { name: terminalName, executable: undefined, args: undefined, waitOnExit };
782-
this.terminalInstanceService.mergeDefaultShellPathAndArgs(shellLaunchConfig, await this.terminalInstanceService.getDefaultShell(), this.terminalService.configHelper, platform);
781+
const defaultConfig = await this.terminalInstanceService.getDefaultShellAndArgs();
782+
shellLaunchConfig = { name: terminalName, executable: defaultConfig.shell, args: defaultConfig.args, waitOnExit };
783783
let shellSpecified: boolean = false;
784784
let shellOptions: ShellConfiguration | undefined = task.command.options && task.command.options.shell;
785785
if (shellOptions) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Terminal as XTermTerminal } from 'xterm';
77
import { WebLinksAddon as XTermWebLinksAddon } from 'xterm-addon-web-links';
88
import { SearchAddon as XTermSearchAddon } from 'xterm-addon-search';
9-
import { ITerminalInstance, IWindowsShellHelper, ITerminalConfigHelper, ITerminalChildProcess, IShellLaunchConfig } from 'vs/workbench/contrib/terminal/common/terminal';
9+
import { ITerminalInstance, IWindowsShellHelper, ITerminalConfigHelper, ITerminalChildProcess, IShellLaunchConfig, IDefaultShellAndArgsRequest } from 'vs/workbench/contrib/terminal/common/terminal';
1010
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1111
import { IProcessEnvironment, Platform } from 'vs/base/common/platform';
1212
import { Event } from 'vs/base/common/event';
@@ -22,6 +22,7 @@ export interface ITerminalInstanceService {
2222
_serviceBrand: any;
2323

2424
onRequestDefaultShell?: Event<(defaultShell: string) => void>;
25+
onRequestDefaultShellAndArgs?: Event<IDefaultShellAndArgsRequest>;
2526

2627
getXtermConstructor(): Promise<typeof XTermTerminal>;
2728
getXtermWebLinksConstructor(): Promise<typeof XTermWebLinksAddon>;
@@ -34,6 +35,7 @@ export interface ITerminalInstanceService {
3435
mergeDefaultShellPathAndArgs(shell: IShellLaunchConfig, defaultShell: string, configHelper: ITerminalConfigHelper, platformOverride?: Platform): void;
3536

3637
getDefaultShell(): Promise<string>;
38+
getDefaultShellAndArgs(): Promise<{ shell: string, args: string[] | string | undefined }>;
3739
getMainProcessParentEnv(): Promise<IProcessEnvironment>;
3840
}
3941

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
7-
import { IWindowsShellHelper, ITerminalChildProcess } from 'vs/workbench/contrib/terminal/common/terminal';
7+
import { IWindowsShellHelper, ITerminalChildProcess, IDefaultShellAndArgsRequest } from 'vs/workbench/contrib/terminal/common/terminal';
88
import { Terminal as XTermTerminal } from 'xterm';
99
import { WebLinksAddon as XTermWebLinksAddon } from 'xterm-addon-web-links';
1010
import { SearchAddon as XTermSearchAddon } from 'xterm-addon-search';
@@ -20,6 +20,8 @@ export class TerminalInstanceService implements ITerminalInstanceService {
2020

2121
private readonly _onRequestDefaultShell = new Emitter<(defaultShell: string) => void>();
2222
public get onRequestDefaultShell(): Event<(defaultShell: string) => void> { return this._onRequestDefaultShell.event; }
23+
private readonly _onRequestDefaultShellAndArgs = new Emitter<IDefaultShellAndArgsRequest>();
24+
public get onRequestDefaultShellAndArgs(): Event<IDefaultShellAndArgsRequest> { return this._onRequestDefaultShellAndArgs.event; }
2325

2426
constructor() { }
2527

@@ -56,6 +58,10 @@ export class TerminalInstanceService implements ITerminalInstanceService {
5658
return new Promise(r => this._onRequestDefaultShell.fire(r));
5759
}
5860

61+
public getDefaultShellAndArgs(): Promise<{ shell: string, args: string[] | string | undefined }> {
62+
return new Promise(r => this._onRequestDefaultShellAndArgs.fire((shell, args) => r({ shell, args })));
63+
}
64+
5965
public async getMainProcessParentEnv(): Promise<IProcessEnvironment> {
6066
return {};
6167
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ export class TerminalProcessManager implements ITerminalProcessManager {
163163

164164
private async _launchProcess(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number): Promise<ITerminalChildProcess> {
165165
if (!shellLaunchConfig.executable) {
166-
this._terminalInstanceService.mergeDefaultShellPathAndArgs(shellLaunchConfig, await this._terminalInstanceService.getDefaultShell(), this._configHelper);
166+
const defaultConfig = await this._terminalInstanceService.getDefaultShellAndArgs();
167+
shellLaunchConfig.executable = defaultConfig.shell;
168+
shellLaunchConfig.args = defaultConfig.args;
167169
}
168170

169171
const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,4 +789,8 @@ export interface ITerminalChildProcess {
789789
getInitialCwd(): Promise<string>;
790790
getCwd(): Promise<string>;
791791
getLatency(): Promise<number>;
792+
}
793+
794+
export interface IDefaultShellAndArgsRequest {
795+
(shell: string, args: string[] | string | undefined): void;
792796
}

src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function getDefaultShell(
192192
return executable;
193193
}
194194

195-
function getDefaultShellArgs(
195+
export function getDefaultShellArgs(
196196
fetchSetting: (key: string) => { user: string | string[] | undefined, value: string | string[] | undefined, default: string | string[] | undefined },
197197
isWorkspaceShellAllowed: boolean,
198198
platformOverride: platform.Platform = platform.platform
@@ -203,6 +203,7 @@ function getDefaultShellArgs(
203203
return args;
204204
}
205205

206+
// TODO: Remove this?
206207
export function mergeDefaultShellPathAndArgs(
207208
shell: IShellLaunchConfig,
208209
fetchSetting: (key: string) => { user: string | string[] | undefined, value: string | string[] | undefined, default: string | string[] | undefined },

0 commit comments

Comments
 (0)