Skip to content

Commit

Permalink
vscode: Support TerminalOptions.strictEnv (#11641)
Browse files Browse the repository at this point in the history
Fixes #11143
Contributed on behalf of STMicroelectronics.

Change-Id: Iabeb2c9a9dac27891e43a011db86b5e37e8a3120
  • Loading branch information
planger authored Sep 15, 2022
1 parent 9142e6d commit 4b43c7c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/plugin-ext/src/main/browser/terminal-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, Disposable
shellArgs: options.shellArgs,
cwd: new URI(options.cwd),
env: options.env,
strictEnv: options.strictEnv,
destroyTermOnClose: true,
useServerTitle: false,
attributes: options.attributes,
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,15 @@ export module '@theia/plugin' {
*/
env?: { [key: string]: string | null };

/**
* Whether the terminal process environment should be exactly as provided in
* `TerminalOptions.env`. When this is false (default), the environment will be based on the
* window's environment and also apply configured platform settings like
* `terminal.integrated.windows.env` on top. When this is true, the complete environment
* must be provided as nothing will be inherited from the process or any configuration.
*/
strictEnv?: boolean;

/**
* A message to write to the terminal on first launch. Note that this is not sent to the
* process, but rather written directly to the terminal. This supports escape sequences such
Expand Down
5 changes: 5 additions & 0 deletions packages/terminal/src/browser/base/terminal-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export interface TerminalWidgetOptions {
*/
readonly env?: { [key: string]: string | null };

/**
* Whether the terminal process environment should be exactly as provided in `env`.
*/
readonly strictEnv?: boolean;

/**
* In case `destroyTermOnClose` is true - terminal process will be destroyed on close terminal widget, otherwise will be kept
* alive.
Expand Down
1 change: 1 addition & 0 deletions packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
shell: this.options.shellPath,
args: this.options.shellArgs,
env: this.options.env,
strictEnv: this.options.strictEnv,
isPseudo: this.options.isPseudoTerminal,
rootURI,
cols,
Expand Down
3 changes: 2 additions & 1 deletion packages/terminal/src/common/shell-terminal-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export interface IShellTerminalServerOptions extends IBaseTerminalServerOptions
rootURI?: string,
cols?: number,
rows?: number,
env?: { [key: string]: string | null };
env?: { [key: string]: string | null },
strictEnv?: boolean,
isPseudo?: boolean,
}

Expand Down
3 changes: 2 additions & 1 deletion packages/terminal/src/node/shell-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface ShellProcessOptions {
cols?: number,
rows?: number,
env?: { [key: string]: string | null },
strictEnv?: boolean,
isPseudo?: boolean,
}

Expand Down Expand Up @@ -70,7 +71,7 @@ export class ShellProcess extends TerminalProcess {
cols: options.cols || ShellProcess.defaultCols,
rows: options.rows || ShellProcess.defaultRows,
cwd: getRootPath(options.rootURI),
env: environmentUtils.mergeProcessEnv(options.env),
env: options.strictEnv !== true ? environmentUtils.mergeProcessEnv(options.env) : options.env,
},
isPseudo: options.isPseudo,
}, processManager, ringBuffer, logger);
Expand Down
6 changes: 4 additions & 2 deletions packages/terminal/src/node/shell-terminal-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export class ShellTerminalServer extends BaseTerminalServer {

async create(options: IShellTerminalServerOptions): Promise<number> {
try {
options.env = this.environmentUtils.mergeProcessEnv(options.env);
this.mergedCollection.applyToProcessEnvironment(options.env);
if (options.strictEnv !== true) {
options.env = this.environmentUtils.mergeProcessEnv(options.env);
this.mergedCollection.applyToProcessEnvironment(options.env);
}
const term = this.shellFactory(options);
this.postCreate(term);
return term.id;
Expand Down

0 comments on commit 4b43c7c

Please sign in to comment.