Skip to content

Commit e1d8493

Browse files
committed
Implement creating a razzle terminal with approved API changes
1 parent 14ce518 commit e1d8493

File tree

6 files changed

+53
-25
lines changed

6 files changed

+53
-25
lines changed

src/vs/vscode.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -6843,6 +6843,16 @@ declare module 'vscode' {
68436843
* Object with environment variables that will be added to the VS Code process.
68446844
*/
68456845
env?: { [key: string]: string | null };
6846+
6847+
/**
6848+
* Whether the terminal process environment should be exactly as provided in
6849+
* `TerminalOptions.env`. When this is false (default), the environment will be based on the
6850+
* window's environment and also apply configured platform settings like
6851+
* `terminal.integrated.windows.env` on top.
6852+
* When this is true, the complete environment must be provided as nothing will be inherited from the process
6853+
* or any configuration.
6854+
*/
6855+
strictEnv?: boolean;
68466856
}
68476857

68486858
/**

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
5555
// when the extension host process goes down ?
5656
}
5757

58-
public $createTerminal(name?: string, shellPath?: string, shellArgs?: string[], cwd?: string, env?: { [key: string]: string }, waitOnExit?: boolean): Promise<{ id: number, name: string }> {
58+
public $createTerminal(name?: string, shellPath?: string, shellArgs?: string[], cwd?: string, env?: { [key: string]: string }, waitOnExit?: boolean, strictEnv?: boolean): Promise<{ id: number, name: string }> {
5959
const shellLaunchConfig: IShellLaunchConfig = {
6060
name,
6161
executable: shellPath,
6262
args: shellArgs,
6363
cwd,
6464
waitOnExit,
6565
ignoreConfigurationCwd: true,
66-
env
66+
env,
67+
strictEnv
6768
};
6869
const terminal = this.terminalService.createTerminal(shellLaunchConfig);
6970
return Promise.resolve({

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export interface MainThreadProgressShape extends IDisposable {
344344
}
345345

346346
export interface MainThreadTerminalServiceShape extends IDisposable {
347-
$createTerminal(name?: string, shellPath?: string, shellArgs?: string[], cwd?: string | URI, env?: { [key: string]: string }, waitOnExit?: boolean): Promise<{ id: number, name: string }>;
347+
$createTerminal(name?: string, shellPath?: string, shellArgs?: string[], cwd?: string | URI, env?: { [key: string]: string }, waitOnExit?: boolean, strictEnv?: boolean): Promise<{ id: number, name: string }>;
348348
$createTerminalRenderer(name: string): Promise<number>;
349349
$dispose(terminalId: number): void;
350350
$hide(terminalId: number): void;

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ export class ExtHostTerminal extends BaseExtHostTerminal implements vscode.Termi
104104
shellArgs?: string[],
105105
cwd?: string | URI,
106106
env?: { [key: string]: string },
107-
waitOnExit?: boolean
107+
waitOnExit?: boolean,
108+
strictEnv?: boolean
108109
): void {
109-
this._proxy.$createTerminal(this._name, shellPath, shellArgs, cwd, env, waitOnExit).then(terminal => {
110+
this._proxy.$createTerminal(this._name, shellPath, shellArgs, cwd, env, waitOnExit, strictEnv).then(terminal => {
110111
this._name = terminal.name;
111112
this._runQueuedRequests(terminal.id);
112113
});
@@ -269,7 +270,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
269270

270271
public createTerminalFromOptions(options: vscode.TerminalOptions): vscode.Terminal {
271272
const terminal = new ExtHostTerminal(this._proxy, options.name);
272-
terminal.create(options.shellPath, options.shellArgs, options.cwd, options.env /*, options.waitOnExit*/);
273+
terminal.create(options.shellPath, options.shellArgs, options.cwd, options.env, /*options.waitOnExit*/ undefined, options.strictEnv);
273274
this._terminals.push(terminal);
274275
return terminal;
275276
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ export interface IShellLaunchConfig {
181181
* extensions full control over the terminal.
182182
*/
183183
isRendererOnly?: boolean;
184+
185+
/**
186+
* Whether the terminal process environment should be exactly as provided in
187+
* `TerminalOptions.env`. When this is false (default), the environment will be based on the
188+
* window's environment and also apply configured platform settings like
189+
* `terminal.integrated.windows.env` on top.
190+
*/
191+
strictEnv?: boolean;
184192
}
185193

186194
export interface ITerminalService {

src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts

+27-19
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,34 @@ export class TerminalProcessManager implements ITerminalProcessManager {
111111
const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file);
112112
this.initialCwd = terminalEnvironment.getCwd(shellLaunchConfig, activeWorkspaceRootUri, this._configHelper.config.cwd);
113113

114-
// Resolve env vars from config and shell
115-
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri) : null;
116-
const platformKey = platform.isWindows ? 'windows' : (platform.isMacintosh ? 'osx' : 'linux');
117-
const envFromConfig = terminalEnvironment.resolveConfigurationVariables(this._configurationResolverService, { ...this._configHelper.config.env[platformKey] }, lastActiveWorkspaceRoot);
118-
const envFromShell = terminalEnvironment.resolveConfigurationVariables(this._configurationResolverService, { ...shellLaunchConfig.env }, lastActiveWorkspaceRoot);
119-
shellLaunchConfig.env = envFromShell;
120-
121114
// Compell type system as process.env should not have any undefined entries
122-
const env: platform.IProcessEnvironment = { ...process.env } as any;
123-
124-
// Merge process env with the env from config and from shellLaunchConfig
125-
terminalEnvironment.mergeEnvironments(env, envFromConfig);
126-
terminalEnvironment.mergeEnvironments(env, shellLaunchConfig.env);
127-
128-
// Sanitize the environment, removing any undesirable VS Code and Electron environment
129-
// variables
130-
terminalEnvironment.sanitizeEnvironment(env);
131-
132-
// Adding other env keys necessary to create the process
133-
terminalEnvironment.addTerminalEnvironmentKeys(env, platform.locale, this._configHelper.config.setLocaleVariables);
115+
let env: platform.IProcessEnvironment = {};
116+
117+
// When this is true, the caller must provide the complete environment as nothing will be inherited from the process
118+
// or any configuration.
119+
if (shellLaunchConfig.strictEnv) {
120+
env = { ...shellLaunchConfig.env } as any;
121+
} else {
122+
// Merge process env with the env from config and from shellLaunchConfig
123+
env = { ...process.env } as any;
124+
125+
// Resolve env vars from config and shell
126+
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri) : null;
127+
const platformKey = platform.isWindows ? 'windows' : (platform.isMacintosh ? 'osx' : 'linux');
128+
const envFromConfig = terminalEnvironment.resolveConfigurationVariables(this._configurationResolverService, { ...this._configHelper.config.env[platformKey] }, lastActiveWorkspaceRoot);
129+
const envFromShell = terminalEnvironment.resolveConfigurationVariables(this._configurationResolverService, { ...shellLaunchConfig.env }, lastActiveWorkspaceRoot);
130+
shellLaunchConfig.env = envFromShell;
131+
132+
terminalEnvironment.mergeEnvironments(env, envFromConfig);
133+
terminalEnvironment.mergeEnvironments(env, shellLaunchConfig.env);
134+
135+
// Sanitize the environment, removing any undesirable VS Code and Electron environment
136+
// variables
137+
terminalEnvironment.sanitizeEnvironment(env);
138+
139+
// Adding other env keys necessary to create the process
140+
terminalEnvironment.addTerminalEnvironmentKeys(env, platform.locale, this._configHelper.config.setLocaleVariables);
141+
}
134142

135143
this._logService.debug(`Terminal process launching`, shellLaunchConfig, this.initialCwd, cols, rows, env);
136144
this._process = new TerminalProcess(shellLaunchConfig, this.initialCwd, cols, rows, env, this._configHelper.config.windowsEnableConpty);

0 commit comments

Comments
 (0)