mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
* Fix #105177 get terminal environment variable to show up in remote container Co-authored-by: Daniel Imms <daimms@microsoft.com>
This commit is contained in:
parent
d8a3c5f61c
commit
2c19f7fb98
|
@ -26,6 +26,7 @@ import { withNullAsUndefined } from 'vs/base/common/types';
|
|||
import { IEnvironmentVariableService, IMergedEnvironmentVariableCollection, IEnvironmentVariableInfo } from 'vs/workbench/contrib/terminal/common/environmentVariable';
|
||||
import { EnvironmentVariableInfoStale, EnvironmentVariableInfoChangesActive } from 'vs/workbench/contrib/terminal/browser/environmentVariableInfo';
|
||||
import { IPathService } from 'vs/workbench/services/path/common/pathService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
/** The amount of time to consider terminal errors to be related to the launch */
|
||||
const LAUNCHING_DURATION = 500;
|
||||
|
@ -166,6 +167,10 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
|
|||
}
|
||||
|
||||
const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot();
|
||||
|
||||
// this is a copy of what the merged environment collection is on the remote side
|
||||
await this._setupEnvVariableInfo(activeWorkspaceRootUri, shellLaunchConfig);
|
||||
|
||||
const enableRemoteAgentTerminals = this._configHelper.config.serverSpawn;
|
||||
if (enableRemoteAgentTerminals) {
|
||||
this._process = await this._remoteTerminalService.createRemoteTerminalProcess(this._terminalId, shellLaunchConfig, activeWorkspaceRootUri, cols, rows, this._configHelper);
|
||||
|
@ -230,6 +235,33 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
|
|||
return undefined;
|
||||
}
|
||||
|
||||
// Fetch any extension environment additions and apply them
|
||||
private async _setupEnvVariableInfo(activeWorkspaceRootUri: URI | undefined, shellLaunchConfig: IShellLaunchConfig): Promise<void> {
|
||||
const platformKey = platform.isWindows ? 'windows' : (platform.isMacintosh ? 'osx' : 'linux');
|
||||
const lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
|
||||
const envFromConfigValue = this._workspaceConfigurationService.inspect<ITerminalEnvironment | undefined>(`terminal.integrated.env.${platformKey}`);
|
||||
const isWorkspaceShellAllowed = this._configHelper.checkWorkspaceShellPermissions();
|
||||
this._configHelper.showRecommendations(shellLaunchConfig);
|
||||
const baseEnv = this._configHelper.config.inheritEnv ? processEnv : await this._terminalInstanceService.getMainProcessParentEnv();
|
||||
const env = terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, terminalEnvironment.createVariableResolver(lastActiveWorkspace, this._configurationResolverService), isWorkspaceShellAllowed, this._productService.version, this._configHelper.config.detectLocale, baseEnv);
|
||||
|
||||
if (!shellLaunchConfig.strictEnv) {
|
||||
this._extEnvironmentVariableCollection = this._environmentVariableService.mergedCollection;
|
||||
this._register(this._environmentVariableService.onDidChangeCollections(newCollection => this._onEnvironmentVariableCollectionChange(newCollection)));
|
||||
// For remote terminals, this is a copy of the mergedEnvironmentCollection created on
|
||||
// the remote side. Since the environment collection is synced between the remote and
|
||||
// local sides immediately this is a fairly safe way of enabling the env var diffing and
|
||||
// info widget. While technically these could differ due to the slight change of a race
|
||||
// condition, the chance is minimal plus the impact on the user is also not that great
|
||||
// if it happens - it's not worth adding plumbing to sync back the resolved collection.
|
||||
this._extEnvironmentVariableCollection.applyToProcessEnvironment(env);
|
||||
if (this._extEnvironmentVariableCollection.map.size > 0) {
|
||||
this._environmentVariableInfo = new EnvironmentVariableInfoChangesActive(this._extEnvironmentVariableCollection);
|
||||
this._onEnvironmentVariableInfoChange.fire(this._environmentVariableInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async _launchLocalProcess(
|
||||
shellLaunchConfig: IShellLaunchConfig,
|
||||
cols: number,
|
||||
|
@ -238,7 +270,6 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
|
|||
isScreenReaderModeEnabled: boolean
|
||||
): Promise<ITerminalChildProcess> {
|
||||
const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file);
|
||||
const platformKey = platform.isWindows ? 'windows' : (platform.isMacintosh ? 'osx' : 'linux');
|
||||
const lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
|
||||
if (!shellLaunchConfig.executable) {
|
||||
const defaultConfig = await this._terminalInstanceService.getDefaultShellAndArgs(false);
|
||||
|
@ -267,22 +298,14 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
|
|||
this._configHelper.config.cwd,
|
||||
this._logService
|
||||
);
|
||||
|
||||
const platformKey = platform.isWindows ? 'windows' : (platform.isMacintosh ? 'osx' : 'linux');
|
||||
const envFromConfigValue = this._workspaceConfigurationService.inspect<ITerminalEnvironment | undefined>(`terminal.integrated.env.${platformKey}`);
|
||||
const isWorkspaceShellAllowed = this._configHelper.checkWorkspaceShellPermissions();
|
||||
this._configHelper.showRecommendations(shellLaunchConfig);
|
||||
const baseEnv = this._configHelper.config.inheritEnv ? processEnv : await this._terminalInstanceService.getMainProcessParentEnv();
|
||||
const env = terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, terminalEnvironment.createVariableResolver(lastActiveWorkspace, this._configurationResolverService), isWorkspaceShellAllowed, this._productService.version, this._configHelper.config.detectLocale, baseEnv);
|
||||
|
||||
// Fetch any extension environment additions and apply them
|
||||
if (!shellLaunchConfig.strictEnv) {
|
||||
this._extEnvironmentVariableCollection = this._environmentVariableService.mergedCollection;
|
||||
this._register(this._environmentVariableService.onDidChangeCollections(newCollection => this._onEnvironmentVariableCollectionChange(newCollection)));
|
||||
this._extEnvironmentVariableCollection.applyToProcessEnvironment(env);
|
||||
if (this._extEnvironmentVariableCollection.map.size > 0) {
|
||||
this._environmentVariableInfo = new EnvironmentVariableInfoChangesActive(this._extEnvironmentVariableCollection);
|
||||
this._onEnvironmentVariableInfoChange.fire(this._environmentVariableInfo);
|
||||
}
|
||||
}
|
||||
await this._setupEnvVariableInfo(activeWorkspaceRootUri, shellLaunchConfig);
|
||||
|
||||
const useConpty = this._configHelper.config.windowsEnableConpty && !isScreenReaderModeEnabled;
|
||||
return this._terminalInstanceService.createTerminalProcess(shellLaunchConfig, initialCwd, cols, rows, env, useConpty);
|
||||
|
|
Loading…
Reference in a new issue