diff --git a/src/vs/workbench/api/node/extHostTerminalService.ts b/src/vs/workbench/api/node/extHostTerminalService.ts index d89750cfdf1..a8452cf27ee 100644 --- a/src/vs/workbench/api/node/extHostTerminalService.ts +++ b/src/vs/workbench/api/node/extHostTerminalService.ts @@ -156,7 +156,7 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { } const activeWorkspaceRootUri = URI.revive(activeWorkspaceRootUriComponents); - let lastActiveWorkspace: IWorkspaceFolder | null = null; + let lastActiveWorkspace: IWorkspaceFolder | undefined; if (activeWorkspaceRootUriComponents && activeWorkspaceRootUri) { // Get the environment const apiLastActiveWorkspace = await this._extHostWorkspace.getWorkspaceFolder(activeWorkspaceRootUri); @@ -175,7 +175,7 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { // Get the initial cwd const terminalConfig = configProvider.getConfiguration('terminal.integrated'); - const initialCwd = terminalEnvironment.getCwd(shellLaunchConfig, os.homedir(), lastActiveWorkspace ? lastActiveWorkspace : undefined, this._variableResolver, activeWorkspaceRootUri, terminalConfig.cwd, this._logService); + const initialCwd = terminalEnvironment.getCwd(shellLaunchConfig, os.homedir(), lastActiveWorkspace, this._variableResolver, activeWorkspaceRootUri, terminalConfig.cwd, this._logService); shellLaunchConfig.cwd = initialCwd; const envFromConfig = this._apiInspectConfigToPlain(configProvider.getConfiguration('terminal.integrated').inspect(`env.${platformKey}`)); diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index f5e97f7d320..4fe0fa28274 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -22,6 +22,7 @@ import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/ import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { Disposable } from 'vs/base/common/lifecycle'; +import { withNullAsUndefined } from 'vs/base/common/types'; /** The amount of time to consider terminal errors to be related to the launch */ const LAUNCHING_DURATION = 500; @@ -201,22 +202,22 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce ): Promise { const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file); const platformKey = platform.isWindows ? 'windows' : (platform.isMacintosh ? 'osx' : 'linux'); - const lastActiveWorkspace = activeWorkspaceRootUri ? this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri) : null; + const lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; if (!shellLaunchConfig.executable) { const defaultConfig = await this._terminalInstanceService.getDefaultShellAndArgs(false); shellLaunchConfig.executable = defaultConfig.shell; shellLaunchConfig.args = defaultConfig.args; } else { - shellLaunchConfig.executable = this._configurationResolverService.resolve(lastActiveWorkspace === null ? undefined : lastActiveWorkspace, shellLaunchConfig.executable); + shellLaunchConfig.executable = this._configurationResolverService.resolve(lastActiveWorkspace, shellLaunchConfig.executable); if (shellLaunchConfig.args) { if (Array.isArray(shellLaunchConfig.args)) { const resolvedArgs: string[] = []; for (const arg of shellLaunchConfig.args) { - resolvedArgs.push(this._configurationResolverService.resolve(lastActiveWorkspace === null ? undefined : lastActiveWorkspace, arg)); + resolvedArgs.push(this._configurationResolverService.resolve(lastActiveWorkspace, arg)); } shellLaunchConfig.args = resolvedArgs; } else { - shellLaunchConfig.args = this._configurationResolverService.resolve(lastActiveWorkspace === null ? undefined : lastActiveWorkspace, shellLaunchConfig.args); + shellLaunchConfig.args = this._configurationResolverService.resolve(lastActiveWorkspace, shellLaunchConfig.args); } } } @@ -224,7 +225,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce const initialCwd = terminalEnvironment.getCwd( shellLaunchConfig, this._environmentService.userHome, - lastActiveWorkspace ? lastActiveWorkspace : undefined, + lastActiveWorkspace, this._configurationResolverService, activeWorkspaceRootUri, this._configHelper.config.cwd, diff --git a/src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts b/src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts index ae02eb5e0c7..cdf56ae60a2 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts @@ -11,7 +11,6 @@ import { IShellLaunchConfig, ITerminalEnvironment } from 'vs/workbench/contrib/t import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { sanitizeProcessEnvironment } from 'vs/base/common/processes'; import { ILogService } from 'vs/platform/log/common/log'; -import { withNullAsUndefined } from 'vs/base/common/types'; /** * This module contains utility functions related to the environment, cwd and paths. @@ -75,12 +74,12 @@ function mergeNonNullKeys(env: platform.IProcessEnvironment, other: ITerminalEnv } } -function resolveConfigurationVariables(configurationResolverService: IConfigurationResolverService, env: ITerminalEnvironment, lastActiveWorkspaceRoot: IWorkspaceFolder | null): ITerminalEnvironment { +function resolveConfigurationVariables(configurationResolverService: IConfigurationResolverService, env: ITerminalEnvironment, lastActiveWorkspaceRoot: IWorkspaceFolder | undefined): ITerminalEnvironment { Object.keys(env).forEach((key) => { const value = env[key]; if (typeof value === 'string') { try { - env[key] = configurationResolverService.resolve(withNullAsUndefined(lastActiveWorkspaceRoot), value); + env[key] = configurationResolverService.resolve(lastActiveWorkspaceRoot, value); } catch (e) { env[key] = value; } @@ -339,7 +338,7 @@ function getShellSetting( export function createTerminalEnvironment( shellLaunchConfig: IShellLaunchConfig, - lastActiveWorkspace: IWorkspaceFolder | null, + lastActiveWorkspace: IWorkspaceFolder | undefined, envFromConfig: { user: ITerminalEnvironment | undefined, value: ITerminalEnvironment | undefined, default: ITerminalEnvironment | undefined }, configurationResolverService: IConfigurationResolverService | undefined, isWorkspaceShellAllowed: boolean,