From 328937e7b642e56e62ba6bce91376bc2e0035268 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 16 Apr 2021 07:00:13 -0700 Subject: [PATCH] Use OperatingSystem over Platform in terminal This prevents the invalid 'web' from possibly being used --- src/vs/base/node/shell.ts | 24 ++++----- src/vs/platform/environment/node/shellEnv.ts | 4 +- src/vs/platform/terminal/common/terminal.ts | 6 +-- .../platform/terminal/node/ptyHostService.ts | 6 +-- src/vs/platform/terminal/node/ptyService.ts | 6 +-- .../api/node/extHostTerminalService.ts | 4 +- .../tasks/browser/terminalTaskSystem.ts | 2 +- .../terminal/browser/remoteTerminalService.ts | 6 +-- .../terminal/browser/terminalInstance.ts | 3 +- .../browser/terminalProcessManager.ts | 12 +---- .../browser/terminalProfileResolverService.ts | 53 +++++++++---------- .../terminal/common/remoteTerminalChannel.ts | 6 +-- .../contrib/terminal/common/terminal.ts | 8 ++- .../terminal/common/terminalConfiguration.ts | 10 ++-- .../electron-browser/terminal.contribution.ts | 4 +- .../electron-sandbox/localTerminalService.ts | 6 +-- .../test/browser/workbenchTestServices.ts | 4 +- 17 files changed, 77 insertions(+), 87 deletions(-) diff --git a/src/vs/base/node/shell.ts b/src/vs/base/node/shell.ts index ae28f291d8f..3df529ecafa 100644 --- a/src/vs/base/node/shell.ts +++ b/src/vs/base/node/shell.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as os from 'os'; +import { release, userInfo } from 'os'; import * as platform from 'vs/base/common/platform'; import { getFirstAvailablePowerShellInstallation } from 'vs/base/node/powershell'; import * as processes from 'vs/base/node/processes'; @@ -11,10 +11,10 @@ import * as processes from 'vs/base/node/processes'; /** * Gets the detected default shell for the _system_, not to be confused with VS Code's _default_ * shell that the terminal uses by default. - * @param p The platform to detect the shell of. + * @param os The platform to detect the shell of. */ -export async function getSystemShell(p: platform.Platform, env: platform.IProcessEnvironment): Promise { - if (p === platform.Platform.Windows) { +export async function getSystemShell(os: platform.OperatingSystem, env: platform.IProcessEnvironment): Promise { + if (os === platform.OperatingSystem.Windows) { if (platform.isWindows) { return getSystemShellWindows(); } @@ -22,11 +22,11 @@ export async function getSystemShell(p: platform.Platform, env: platform.IProces return processes.getWindowsShell(env); } - return getSystemShellUnixLike(p, env); + return getSystemShellUnixLike(os, env); } -export function getSystemShellSync(p: platform.Platform, env: platform.IProcessEnvironment): string { - if (p === platform.Platform.Windows) { +export function getSystemShellSync(os: platform.OperatingSystem, env: platform.IProcessEnvironment): string { + if (os === platform.OperatingSystem.Windows) { if (platform.isWindows) { return getSystemShellWindowsSync(env); } @@ -34,13 +34,13 @@ export function getSystemShellSync(p: platform.Platform, env: platform.IProcessE return processes.getWindowsShell(env); } - return getSystemShellUnixLike(p, env); + return getSystemShellUnixLike(os, env); } let _TERMINAL_DEFAULT_SHELL_UNIX_LIKE: string | null = null; -function getSystemShellUnixLike(p: platform.Platform, env: platform.IProcessEnvironment): string { +function getSystemShellUnixLike(os: platform.OperatingSystem, env: platform.IProcessEnvironment): string { // Only use $SHELL for the current OS - if (platform.isLinux && p === platform.Platform.Mac || platform.isMacintosh && p === platform.Platform.Linux) { + if (platform.isLinux && os === platform.OperatingSystem.Macintosh || platform.isMacintosh && os === platform.OperatingSystem.Linux) { return '/bin/bash'; } @@ -55,7 +55,7 @@ function getSystemShellUnixLike(p: platform.Platform, env: platform.IProcessEnvi try { // It's possible for $SHELL to be unset, this API reads /etc/passwd. See https://github.com/github/codespaces/issues/1639 // Node docs: "Throws a SystemError if a user has no username or homedir." - unixLikeTerminal = os.userInfo().shell; + unixLikeTerminal = userInfo().shell; } catch (err) { } } @@ -86,7 +86,7 @@ function getSystemShellWindowsSync(env: platform.IProcessEnvironment): string { return _TERMINAL_DEFAULT_SHELL_WINDOWS; } - const isAtLeastWindows10 = platform.isWindows && parseFloat(os.release()) >= 10; + const isAtLeastWindows10 = platform.isWindows && parseFloat(release()) >= 10; const is32ProcessOn64Windows = env.hasOwnProperty('PROCESSOR_ARCHITEW6432'); const powerShellPath = `${env['windir']}\\${is32ProcessOn64Windows ? 'Sysnative' : 'System32'}\\WindowsPowerShell\\v1.0\\powershell.exe`; return isAtLeastWindows10 ? powerShellPath : processes.getWindowsShell(env); diff --git a/src/vs/platform/environment/node/shellEnv.ts b/src/vs/platform/environment/node/shellEnv.ts index 113ec039ece..8125c0baa50 100644 --- a/src/vs/platform/environment/node/shellEnv.ts +++ b/src/vs/platform/environment/node/shellEnv.ts @@ -6,7 +6,7 @@ import * as path from 'path'; import { spawn } from 'child_process'; import { generateUuid } from 'vs/base/common/uuid'; -import { IProcessEnvironment, isWindows, platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, isWindows, OS } from 'vs/base/common/platform'; import { ILogService } from 'vs/platform/log/common/log'; import { NativeParsedArgs } from 'vs/platform/environment/common/argv'; import { isLaunchedFromCli } from 'vs/platform/environment/node/argvHelper'; @@ -77,7 +77,7 @@ async function doResolveUnixShellEnv(logService: ILogService): Promise; listProcesses(): Promise; - getDefaultSystemShell(platformOverride?: Platform): Promise; + getDefaultSystemShell(osOverride?: OperatingSystem): Promise; getShellEnvironment(): Promise; setTerminalLayoutInfo(layoutInfo?: ITerminalsLayoutInfoById): Promise; getTerminalLayoutInfo(): Promise; @@ -161,7 +161,7 @@ export interface IPtyService { /** Confirm the process is _not_ an orphan. */ orphanQuestionReply(id: number): Promise; - getDefaultSystemShell(platformOverride?: Platform): Promise; + getDefaultSystemShell(osOverride?: OperatingSystem): Promise; getShellEnvironment(): Promise; setTerminalLayoutInfo(args: ISetTerminalLayoutInfoArgs): Promise; getTerminalLayoutInfo(args: IGetTerminalLayoutInfoArgs): Promise; diff --git a/src/vs/platform/terminal/node/ptyHostService.ts b/src/vs/platform/terminal/node/ptyHostService.ts index 1c9071c7afd..6b1740731e9 100644 --- a/src/vs/platform/terminal/node/ptyHostService.ts +++ b/src/vs/platform/terminal/node/ptyHostService.ts @@ -9,7 +9,7 @@ import { IPtyService, IProcessDataEvent, IShellLaunchConfig, ITerminalDimensions import { Client } from 'vs/base/parts/ipc/node/ipc.cp'; import { FileAccess } from 'vs/base/common/network'; import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; -import { IProcessEnvironment, Platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; import { Emitter } from 'vs/base/common/event'; import { LogLevelChannelClient } from 'vs/platform/log/common/logIpc'; import { IGetTerminalLayoutInfoArgs, IProcessDetails, IPtyHostProcessReplayEvent, ISetTerminalLayoutInfoArgs } from 'vs/platform/terminal/common/terminalProcess'; @@ -192,8 +192,8 @@ export class PtyHostService extends Disposable implements IPtyService { return this._proxy.orphanQuestionReply(id); } - getDefaultSystemShell(platformOverride?: Platform): Promise { - return this._proxy.getDefaultSystemShell(platformOverride); + getDefaultSystemShell(osOverride?: OperatingSystem): Promise { + return this._proxy.getDefaultSystemShell(osOverride); } getShellEnvironment(): Promise { return this._proxy.getShellEnvironment(); diff --git a/src/vs/platform/terminal/node/ptyService.ts b/src/vs/platform/terminal/node/ptyService.ts index ceee5d1efe3..12f014b477b 100644 --- a/src/vs/platform/terminal/node/ptyService.ts +++ b/src/vs/platform/terminal/node/ptyService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Disposable, toDisposable } from 'vs/base/common/lifecycle'; -import { IProcessEnvironment, platform, Platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, OperatingSystem, OS } from 'vs/base/common/platform'; import { IPtyService, IProcessDataEvent, IShellLaunchConfig, ITerminalDimensionsOverride, ITerminalLaunchError, LocalReconnectConstants, ITerminalsLayoutInfo, IRawTerminalInstanceLayoutInfo, ITerminalTabLayoutInfoById, ITerminalInstanceLayoutInfoById, TerminalShellType } from 'vs/platform/terminal/common/terminal'; import { AutoOpenBarrier, Queue, RunOnceScheduler } from 'vs/base/common/async'; import { Emitter } from 'vs/base/common/event'; @@ -164,8 +164,8 @@ export class PtyService extends Disposable implements IPtyService { return this._throwIfNoPty(id).orphanQuestionReply(); } - async getDefaultSystemShell(platformOverride: Platform = platform): Promise { - return getSystemShell(platformOverride, process.env); + async getDefaultSystemShell(osOverride: OperatingSystem = OS): Promise { + return getSystemShell(osOverride, process.env); } async getShellEnvironment(): Promise { diff --git a/src/vs/workbench/api/node/extHostTerminalService.ts b/src/vs/workbench/api/node/extHostTerminalService.ts index b3d7108569b..66b252be651 100644 --- a/src/vs/workbench/api/node/extHostTerminalService.ts +++ b/src/vs/workbench/api/node/extHostTerminalService.ts @@ -41,7 +41,7 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { // Getting the SystemShell is an async operation, however, the ExtHost terminal service is mostly synchronous // and the API `vscode.env.shell` is also synchronous. The default shell _should_ be set when extensions are // starting up but if not, we run getSystemShellSync below which gets a sane default. - getSystemShell(platform.platform, process.env as platform.IProcessEnvironment).then(s => this._defaultShell = s); + getSystemShell(platform.OS, process.env as platform.IProcessEnvironment).then(s => this._defaultShell = s); this._updateLastActiveWorkspace(); this._variableResolverPromise = this._updateVariableResolver(); @@ -83,7 +83,7 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { return terminalEnvironment.getDefaultShell( fetchSetting, - this._defaultShell ?? getSystemShellSync(platform.platform, process.env as platform.IProcessEnvironment), + this._defaultShell ?? getSystemShellSync(platform.OS, process.env as platform.IProcessEnvironment), process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'), process.env.windir, terminalEnvironment.createVariableResolver(this._lastActiveWorkspace, this._variableResolver), diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index c4fa38d5796..2cf87022efe 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -1016,7 +1016,7 @@ export class TerminalTaskSystem implements ITaskSystem { } else { const defaultProfile = await this.terminalProfileResolverService.getDefaultProfile({ allowAutomationShell: true, - platform, + os: Platform.OS, remoteAuthority: this.environmentService.remoteAuthority }); defaultConfig = { diff --git a/src/vs/workbench/contrib/terminal/browser/remoteTerminalService.ts b/src/vs/workbench/contrib/terminal/browser/remoteTerminalService.ts index 87d2a921d2f..a5ffba224e5 100644 --- a/src/vs/workbench/contrib/terminal/browser/remoteTerminalService.ts +++ b/src/vs/workbench/contrib/terminal/browser/remoteTerminalService.ts @@ -6,7 +6,7 @@ import { Emitter } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import { revive } from 'vs/base/common/marshalling'; -import { IProcessEnvironment, Platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; import { URI } from 'vs/base/common/uri'; import { localize } from 'vs/nls'; import { ICommandService } from 'vs/platform/commands/common/commands'; @@ -189,8 +189,8 @@ export class RemoteTerminalService extends Disposable implements IRemoteTerminal }); } - public async getDefaultSystemShell(platformOverride?: Platform): Promise { - return this._remoteTerminalChannel?.getDefaultSystemShell(platformOverride) || ''; + public async getDefaultSystemShell(osOverride?: OperatingSystem): Promise { + return this._remoteTerminalChannel?.getDefaultSystemShell(osOverride) || ''; } public async getShellEnvironment(): Promise { diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index 63304945b57..cc7840c4732 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -250,7 +250,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { // Resolve just the icon ahead of time so that it shows up immediately in the tabs if (!this.shellLaunchConfig.executable) { - this._terminalProfileResolverService.resolveIcon(this._shellLaunchConfig); + // TODO: This will pass in the wrong OS for the remote case + this._terminalProfileResolverService.resolveIcon(this._shellLaunchConfig, platform.OS); } this._initDimensions(); diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 421fdec3d5b..21b62f95a4e 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -232,7 +232,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce } else { await this._terminalProfileResolverService.resolveShellLaunchConfig(shellLaunchConfig, { remoteAuthority: this.remoteAuthority, - platform: this._osToPlatform(this.os) + os: this.os }); newProcess = await this._remoteTerminalService.createProcess(shellLaunchConfig, activeWorkspaceRootUri, cols, rows, shouldPersist, this._configHelper); } @@ -371,7 +371,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce ): Promise { await this._terminalProfileResolverService.resolveShellLaunchConfig(shellLaunchConfig, { remoteAuthority: undefined, - platform: platform.platform + os: platform.OS }); const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file); @@ -547,14 +547,6 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._instanceId); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); } - - private _osToPlatform(os: platform.OperatingSystem) { - switch (os) { - case platform.OperatingSystem.Linux: return platform.Platform.Linux; - case platform.OperatingSystem.Macintosh: return platform.Platform.Mac; - case platform.OperatingSystem.Windows: return platform.Platform.Windows; - } - } } class AckDataBufferer { diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts b/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts index 22336d233d3..e652fbd3b67 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts @@ -12,14 +12,14 @@ import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspac import { IRemoteTerminalService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; -import { IProcessEnvironment, platform, Platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; import { IShellLaunchConfig } from 'vs/platform/terminal/common/terminal'; import { IShellLaunchConfigResolveOptions, ITerminalProfile, ITerminalProfileResolverService } from 'vs/workbench/contrib/terminal/common/terminal'; import * as path from 'vs/base/common/path'; import { Codicon } from 'vs/base/common/codicons'; export interface IProfileContextProvider { - getDefaultSystemShell: (remoteAuthority: string | undefined, platform: Platform) => Promise; + getDefaultSystemShell: (remoteAuthority: string | undefined, os: OperatingSystem) => Promise; getShellEnvironment: (remoteAuthority: string | undefined) => Promise; } @@ -39,12 +39,12 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro ) { } - resolveIcon(shellLaunchConfig: IShellLaunchConfig): void { + resolveIcon(shellLaunchConfig: IShellLaunchConfig, os: OperatingSystem): void { if (shellLaunchConfig.executable) { return; } - const defaultProfile = this._getRealDefaultProfile(true, platform); + const defaultProfile = this._getRealDefaultProfile(true, os); if (defaultProfile) { shellLaunchConfig.icon = defaultProfile.icon; } @@ -93,7 +93,7 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro } // Return the real default profile if it exists and is valid - const defaultProfile = await this._getRealDefaultProfile(false, options.platform); + const defaultProfile = await this._getRealDefaultProfile(false, options.os); if (defaultProfile) { return defaultProfile; } @@ -103,10 +103,10 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro return this._getFallbackDefaultProfile(options); } - private _getRealDefaultProfile(sync: true, platform: Platform): ITerminalProfile | undefined; - private _getRealDefaultProfile(sync: false, platform: Platform): Promise; - private _getRealDefaultProfile(sync: boolean, platform: Platform): ITerminalProfile | undefined | Promise { - const defaultProfileName = this._configurationService.getValue(`terminal.integrated.defaultProfile.${this._getPlatformKey(platform)}`); + private _getRealDefaultProfile(sync: true, os: OperatingSystem): ITerminalProfile | undefined; + private _getRealDefaultProfile(sync: false, os: OperatingSystem): Promise; + private _getRealDefaultProfile(sync: boolean, os: OperatingSystem): ITerminalProfile | undefined | Promise { + const defaultProfileName = this._configurationService.getValue(`terminal.integrated.defaultProfile.${this._getOsKey(os)}`); if (defaultProfileName && typeof defaultProfileName === 'string') { if (sync) { const profiles = this._terminalService.getAvailableProfiles(); @@ -123,15 +123,15 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro private async _getFallbackDefaultProfile(options: IShellLaunchConfigResolveOptions): Promise { let executable: string; let args: string | string[] | undefined; - const shellSetting = this._configurationService.getValue(`terminal.integrated.shell.${this._getPlatformKey(options.platform)}`); + const shellSetting = this._configurationService.getValue(`terminal.integrated.shell.${this._getOsKey(options.os)}`); if (this._isValidShell(shellSetting)) { executable = shellSetting; - const shellArgsSetting = this._configurationService.getValue(`terminal.integrated.shellArgs.${this._getPlatformKey(options.platform)}`); - if (this._isValidShellArgs(shellArgsSetting, options.platform)) { + const shellArgsSetting = this._configurationService.getValue(`terminal.integrated.shellArgs.${this._getOsKey(options.os)}`); + if (this._isValidShellArgs(shellArgsSetting, options.os)) { args = shellArgsSetting || []; } } else { - executable = await this._context.getDefaultSystemShell(options.remoteAuthority, options.platform); + executable = await this._context.getDefaultSystemShell(options.remoteAuthority, options.os); } const icon = this._guessProfileIcon(executable); @@ -145,7 +145,7 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro } private _getAutomationShellProfile(options: IShellLaunchConfigResolveOptions): ITerminalProfile | undefined { - const automationShell = this._configurationService.getValue(`terminal.integrated.automationShell.${this._getPlatformKey(options.platform)}`); + const automationShell = this._configurationService.getValue(`terminal.integrated.automationShell.${this._getOsKey(options.os)}`); if (!automationShell || typeof automationShell !== 'string') { return undefined; } @@ -156,7 +156,7 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro } private async _resolveProfile(profile: ITerminalProfile, options: IShellLaunchConfigResolveOptions): Promise { - if (options.platform === Platform.Windows) { + if (options.os === OperatingSystem.Windows) { // Change Sysnative to System32 if the OS is Windows but NOT WoW64. It's // safe to assume that this was used by accident as Sysnative does not // exist and will break the terminal in non-WoW64 environments. @@ -171,7 +171,7 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro } // Convert / to \ on Windows for convenience - if (profile.path && options.platform === Platform.Windows) { + if (profile.path) { profile.path = profile.path.replace(/\//g, '\\'); } } @@ -205,12 +205,11 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro return value; } - private _getPlatformKey(platform: Platform): string { - switch (platform) { - case Platform.Linux: return 'linux'; - case Platform.Mac: return 'osx'; - case Platform.Windows: return 'windows'; - default: return ''; + private _getOsKey(os: OperatingSystem): string { + switch (os) { + case OperatingSystem.Linux: return 'linux'; + case OperatingSystem.Macintosh: return 'osx'; + case OperatingSystem.Windows: return 'windows'; } } @@ -236,11 +235,11 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro return typeof shell === 'string'; } - private _isValidShellArgs(shellArgs: unknown, platform: Platform): shellArgs is string | string[] | undefined { + private _isValidShellArgs(shellArgs: unknown, os: OperatingSystem): shellArgs is string | string[] | undefined { if (shellArgs === undefined) { return true; } - if (platform === Platform.Windows && typeof shellArgs === 'string') { + if (os === OperatingSystem.Windows && typeof shellArgs === 'string') { return true; } if (Array.isArray(shellArgs) && shellArgs.every(e => typeof e === 'string')) { @@ -263,12 +262,12 @@ export class BrowserTerminalProfileResolverService extends BaseTerminalProfileRe ) { super( { - getDefaultSystemShell: async (remoteAuthority, platform) => { + getDefaultSystemShell: async (remoteAuthority, os) => { if (!remoteAuthority) { // Just return basic values, this is only for serverless web and wouldn't be used - return platform === Platform.Windows ? 'pwsh' : 'bash'; + return os === OperatingSystem.Windows ? 'pwsh' : 'bash'; } - return remoteTerminalService.getDefaultSystemShell(platform); + return remoteTerminalService.getDefaultSystemShell(os); }, getShellEnvironment: async (remoteAuthority) => { if (!remoteAuthority) { diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index bb2a0741586..445128aa58d 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -21,7 +21,7 @@ import { IEnvironmentVariableService, ISerializableEnvironmentVariableCollection import { IProcessDataEvent, IShellLaunchConfig, IShellLaunchConfigDto, ITerminalDimensionsOverride, ITerminalEnvironment, ITerminalLaunchError, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, TerminalShellType } from 'vs/platform/terminal/common/terminal'; import { ITerminalConfiguration, TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal'; import { IGetTerminalLayoutInfoArgs, IProcessDetails, IPtyHostProcessReplayEvent, ISetTerminalLayoutInfoArgs } from 'vs/platform/terminal/common/terminalProcess'; -import { IProcessEnvironment, Platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; export const REMOTE_TERMINAL_CHANNEL_NAME = 'remoteterminal'; @@ -256,8 +256,8 @@ export class RemoteTerminalChannelClient { return this._channel.call('$sendCommandResult', [reqId, isError, payload]); } - public getDefaultSystemShell(platformOverride?: Platform): Promise { - return this._channel.call('$getDefaultSystemShell', [platformOverride]); + public getDefaultSystemShell(osOverride?: OperatingSystem): Promise { + return this._channel.call('$getDefaultSystemShell', [osOverride]); } public getShellEnvironment(): Promise { diff --git a/src/vs/workbench/contrib/terminal/common/terminal.ts b/src/vs/workbench/contrib/terminal/common/terminal.ts index 916f74c29e4..e5b239ddd1f 100644 --- a/src/vs/workbench/contrib/terminal/common/terminal.ts +++ b/src/vs/workbench/contrib/terminal/common/terminal.ts @@ -7,7 +7,7 @@ import * as nls from 'vs/nls'; import { Event } from 'vs/base/common/event'; import { IDisposable } from 'vs/base/common/lifecycle'; import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; -import { IProcessEnvironment, OperatingSystem, Platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; import { IExtensionPointDescriptor } from 'vs/workbench/services/extensions/common/extensionsRegistry'; import { IProcessDataEvent, IShellLaunchConfig, ITerminalDimensions, ITerminalDimensionsOverride, ITerminalEnvironment, ITerminalLaunchError, TerminalShellType } from 'vs/platform/terminal/common/terminal'; import { IEnvironmentVariableInfo } from 'vs/workbench/contrib/terminal/common/environmentVariable'; @@ -83,7 +83,7 @@ export interface ITerminalProfileResolverService { /** * Resolves the icon of a shell launch config if this will use the default profile */ - resolveIcon(shellLaunchConfig: IShellLaunchConfig): void; + resolveIcon(shellLaunchConfig: IShellLaunchConfig, os: OperatingSystem): void; resolveShellLaunchConfig(shellLaunchConfig: IShellLaunchConfig, options: IShellLaunchConfigResolveOptions): Promise; getDefaultProfile(options: IShellLaunchConfigResolveOptions): Promise; getDefaultShell(options: IShellLaunchConfigResolveOptions): Promise; @@ -93,9 +93,7 @@ export interface ITerminalProfileResolverService { export interface IShellLaunchConfigResolveOptions { remoteAuthority: string | undefined; - // TODO: Pass remote authority in so that local and remote terminals can be resolved correctly - // TODO: Consider converting to OperatingSystem such that it's not possible to pass Platform.web in - platform: Platform; + os: OperatingSystem; allowAutomationShell?: boolean; } diff --git a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts index 5974df8135f..4f811b81b4a 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts @@ -7,7 +7,7 @@ import { ConfigurationScope, IConfigurationNode } from 'vs/platform/configuratio import { localize } from 'vs/nls'; import { EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions'; import { DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, TerminalCursorStyle, DEFAULT_COMMANDS_TO_SKIP_SHELL, SUGGESTIONS_FONT_WEIGHT, MINIMUM_FONT_WEIGHT, MAXIMUM_FONT_WEIGHT, DEFAULT_LOCAL_ECHO_EXCLUDE } from 'vs/workbench/contrib/terminal/common/terminal'; -import { isMacintosh, isWindows, Platform } from 'vs/base/common/platform'; +import { isMacintosh, isWindows, OperatingSystem } from 'vs/base/common/platform'; import { IJSONSchema } from 'vs/base/common/jsonSchema'; const terminalProfileSchema: IJSONSchema = { @@ -684,9 +684,9 @@ export function getNoDefaultTerminalShellConfiguration(): IConfigurationNode { localize('terminal.integrated.shell.windows.noDefault', "The path of the shell that the terminal uses on Windows. [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration).")); } -export async function getTerminalShellConfiguration(getSystemShell: (p: Platform) => Promise): Promise { +export async function getTerminalShellConfiguration(getSystemShell: (os: OperatingSystem) => Promise): Promise { return getTerminalShellConfigurationStub( - localize('terminal.integrated.shell.linux', "The path of the shell that the terminal uses on Linux (default: {0}). [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration).", await getSystemShell(Platform.Linux)), - localize('terminal.integrated.shell.osx', "The path of the shell that the terminal uses on macOS (default: {0}). [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration).", await getSystemShell(Platform.Mac)), - localize('terminal.integrated.shell.windows', "The path of the shell that the terminal uses on Windows (default: {0}). [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration).", await getSystemShell(Platform.Windows))); + localize('terminal.integrated.shell.linux', "The path of the shell that the terminal uses on Linux (default: {0}). [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration).", await getSystemShell(OperatingSystem.Linux)), + localize('terminal.integrated.shell.osx', "The path of the shell that the terminal uses on macOS (default: {0}). [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration).", await getSystemShell(OperatingSystem.Macintosh)), + localize('terminal.integrated.shell.windows', "The path of the shell that the terminal uses on Windows (default: {0}). [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration).", await getSystemShell(OperatingSystem.Windows))); } diff --git a/src/vs/workbench/contrib/terminal/electron-browser/terminal.contribution.ts b/src/vs/workbench/contrib/terminal/electron-browser/terminal.contribution.ts index ff7bf01fcdf..6f6943b6e23 100644 --- a/src/vs/workbench/contrib/terminal/electron-browser/terminal.contribution.ts +++ b/src/vs/workbench/contrib/terminal/electron-browser/terminal.contribution.ts @@ -14,7 +14,7 @@ import { getTerminalShellConfiguration } from 'vs/workbench/contrib/terminal/com import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { getSystemShell } from 'vs/base/node/shell'; import { process } from 'vs/base/parts/sandbox/electron-sandbox/globals'; -import { Platform } from 'vs/base/common/platform'; +import { OperatingSystem } from 'vs/base/common/platform'; import { ElectronTerminalProfileResolverService } from 'vs/workbench/contrib/terminal/electron-sandbox/terminalProfileResolverService'; import { ITerminalProfileResolverService } from 'vs/workbench/contrib/terminal/common/terminal'; @@ -30,5 +30,5 @@ workbenchRegistry.registerWorkbenchContribution(TerminalNativeContribution, Life // Register configurations const configurationRegistry = Registry.as(Extensions.Configuration); -const systemShell = async (p: Platform) => getSystemShell(p, await process.shellEnv()); +const systemShell = async (os: OperatingSystem) => getSystemShell(os, await process.shellEnv()); getTerminalShellConfiguration(systemShell).then(config => configurationRegistry.registerConfiguration(config)); diff --git a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalService.ts b/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalService.ts index f9c23662751..42c740c4772 100644 --- a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalService.ts +++ b/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalService.ts @@ -5,7 +5,7 @@ import { Emitter } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; -import { IProcessEnvironment, Platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; import { localize } from 'vs/nls'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ILabelService } from 'vs/platform/label/common/label'; @@ -126,8 +126,8 @@ export class LocalTerminalService extends Disposable implements ILocalTerminalSe this._localPtyService.reduceConnectionGraceTime(); } - public async getDefaultSystemShell(platformOverride?: Platform): Promise { - return this._localPtyService.getDefaultSystemShell(platformOverride); + public async getDefaultSystemShell(osOverride?: OperatingSystem): Promise { + return this._localPtyService.getDefaultSystemShell(osOverride); } public async getShellEnvironment(): Promise { diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index 25603df9a72..8463b31a728 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -62,7 +62,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { ViewletDescriptor, Viewlet } from 'vs/workbench/browser/viewlet'; import { IViewlet } from 'vs/workbench/common/viewlet'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; -import { IProcessEnvironment, isLinux, isWindows, Platform } from 'vs/base/common/platform'; +import { IProcessEnvironment, isLinux, isWindows, OperatingSystem } from 'vs/base/common/platform'; import { LabelService } from 'vs/workbench/services/label/common/labelService'; import { Part } from 'vs/workbench/browser/part'; import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; @@ -1555,7 +1555,7 @@ export class TestLocalTerminalService implements ILocalTerminalService { } async attachToProcess(id: number): Promise { throw new Error('Method not implemented.'); } async listProcesses(): Promise { throw new Error('Method not implemented.'); } - getDefaultSystemShell(platformOverride?: Platform): Promise { throw new Error('Method not implemented.'); } + getDefaultSystemShell(osOverride?: OperatingSystem): Promise { throw new Error('Method not implemented.'); } getShellEnvironment(): Promise { throw new Error('Method not implemented.'); } async setTerminalLayoutInfo(argsOrLayout?: ISetTerminalLayoutInfoArgs | ITerminalsLayoutInfoById) { throw new Error('Method not implemented.'); } async getTerminalLayoutInfo(): Promise { throw new Error('Method not implemented.'); }