Skip to content

Commit

Permalink
Align check for env var collection on remote
Browse files Browse the repository at this point in the history
Checked all causes before applyToProcessEnvironment was used.

Fixes #197187
  • Loading branch information
Tyriar committed Feb 29, 2024
1 parent 9e95b2a commit ec2ef28
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/vs/platform/terminal/common/terminalEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { OperatingSystem, OS } from 'vs/base/common/platform';
import type { IShellLaunchConfig } from 'vs/platform/terminal/common/terminal';

/**
* Aggressively escape non-windows paths to prepare for being sent to a shell. This will do some
Expand Down Expand Up @@ -59,3 +60,11 @@ export function sanitizeCwd(cwd: string): string {
}
return cwd;
}

/**
* Determines whether the given shell launch config should use the environment variable collection.
* @param slc The shell launch config to check.
*/
export function shouldUseEnvironmentVariableCollection(slc: IShellLaunchConfig): boolean {
return !slc.strictEnv && !slc.hideFromUser;
}
3 changes: 2 additions & 1 deletion src/vs/server/node/remoteTerminalChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { IExtensionManagementService } from 'vs/platform/extensionManagement/com
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
import { promiseWithResolvers } from 'vs/base/common/async';
import { shouldUseEnvironmentVariableCollection } from 'vs/platform/terminal/common/terminalEnvironment';

class CustomVariableResolver extends AbstractVariableResolverService {
constructor(
Expand Down Expand Up @@ -235,7 +236,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
);

// Apply extension environment variable collections to the environment
if (!shellLaunchConfig.strictEnv) {
if (shouldUseEnvironmentVariableCollection(shellLaunchConfig)) {
const entries: [string, IEnvironmentVariableCollection][] = [];
for (const [k, v, d] of args.envVariableCollections) {
entries.push([k, { map: deserializeEnvironmentVariableCollection(v), descriptionMap: deserializeEnvironmentDescriptionMap(d) }]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { IEnvironmentVariableCollection, IMergedEnvironmentVariableCollection }
import { generateUuid } from 'vs/base/common/uuid';
import { getActiveWindow, runWhenWindowIdle } from 'vs/base/browser/dom';
import { mainWindow } from 'vs/base/browser/window';
import { shouldUseEnvironmentVariableCollection } from 'vs/platform/terminal/common/terminalEnvironment';

const enum ProcessConstants {
/**
Expand Down Expand Up @@ -436,7 +437,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
baseEnv = await this._terminalProfileResolverService.getEnvironment(this.remoteAuthority);
}
const env = await terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, variableResolver, this._productService.version, this._configHelper.config.detectLocale, baseEnv);
if (!this._isDisposed && !shellLaunchConfig.strictEnv && !shellLaunchConfig.hideFromUser) {
if (!this._isDisposed && shouldUseEnvironmentVariableCollection(shellLaunchConfig)) {
this._extEnvironmentVariableCollection = this._environmentVariableService.mergedCollection;

this._register(this._environmentVariableService.onDidChangeCollections(newCollection => this._onEnvironmentVariableCollectionChange(newCollection)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { IStatusbarService } from 'vs/workbench/services/statusbar/browser/statu
import { memoize } from 'vs/base/common/decorators';
import { StopWatch } from 'vs/base/common/stopwatch';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { shouldUseEnvironmentVariableCollection } from 'vs/platform/terminal/common/terminalEnvironment';

export class LocalTerminalBackendContribution implements IWorkbenchContribution {

Expand Down Expand Up @@ -373,7 +374,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
const envFromConfigValue = this._configurationService.getValue<ITerminalEnvironment | undefined>(`terminal.integrated.env.${platformKey}`);
const baseEnv = await (shellLaunchConfig.useShellEnvironment ? this.getShellEnvironment() : this.getEnvironment());
const env = await terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, variableResolver, this._productService.version, this._configurationService.getValue(TerminalSettingId.DetectLocale), baseEnv);
if (!shellLaunchConfig.strictEnv && !shellLaunchConfig.hideFromUser) {
if (shouldUseEnvironmentVariableCollection(shellLaunchConfig)) {
const workspaceFolder = terminalEnvironment.getWorkspaceForTerminal(shellLaunchConfig.cwd, this._workspaceContextService, this._historyService);
await this._environmentVariableService.mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver);
}
Expand Down

0 comments on commit ec2ef28

Please sign in to comment.