未验证 提交 43db454a 编写于 作者: R Ramya Rao 提交者: GitHub

Run configurationResolver on terminal env vars (#40059)

* Run configurationResolver on terminal env vars

* Run configurationResolver on terminal env vars from api

* Refactor per review comment

* Resolve variables in their own function
上级 b1d931fe
......@@ -35,6 +35,8 @@ import { IHistoryService } from 'vs/workbench/services/history/common/history';
import pkg from 'vs/platform/node/package';
import { ansiColorIdentifiers, TERMINAL_BACKGROUND_COLOR, TERMINAL_FOREGROUND_COLOR, TERMINAL_CURSOR_FOREGROUND_COLOR, TERMINAL_CURSOR_BACKGROUND_COLOR, TERMINAL_SELECTION_BACKGROUND_COLOR } from 'vs/workbench/parts/terminal/electron-browser/terminalColorRegistry';
import { PANEL_BACKGROUND } from 'vs/workbench/common/theme';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
/** The amount of time to consider terminal errors to be related to the launch */
const LAUNCHING_DURATION = 500;
......@@ -123,7 +125,9 @@ export class TerminalInstance implements ITerminalInstance {
@IInstantiationService private _instantiationService: IInstantiationService,
@IClipboardService private _clipboardService: IClipboardService,
@IHistoryService private _historyService: IHistoryService,
@IThemeService private _themeService: IThemeService
@IThemeService private _themeService: IThemeService,
@IConfigurationResolverService private _configurationResolverService: IConfigurationResolverService,
@IWorkspaceContextService private _workspaceContextService: IWorkspaceContextService
) {
this._instanceDisposables = [];
this._processDisposables = [];
......@@ -585,16 +589,24 @@ export class TerminalInstance implements ITerminalInstance {
if (!this._shellLaunchConfig.executable) {
this._configHelper.mergeDefaultShellPathAndArgs(this._shellLaunchConfig);
}
this._initialCwd = this._getCwd(this._shellLaunchConfig, this._historyService.getLastActiveWorkspaceRoot('file'));
const lastActiveWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot('file');
this._initialCwd = this._getCwd(this._shellLaunchConfig, lastActiveWorkspaceRootUri);
// Resolve env vars from config and shell
const lastActiveWorkspaceRoot = this._workspaceContextService.getWorkspaceFolder(lastActiveWorkspaceRootUri);
const platformKey = platform.isWindows ? 'windows' : (platform.isMacintosh ? 'osx' : 'linux');
const envFromConfig = TerminalInstance.resolveConfigurationVariables(this._configurationResolverService, { ...this._configHelper.config.env[platformKey] }, lastActiveWorkspaceRoot);
const envFromShell = TerminalInstance.resolveConfigurationVariables(this._configurationResolverService, { ...this._shellLaunchConfig.env }, lastActiveWorkspaceRoot);
this._shellLaunchConfig.env = envFromShell;
// Merge process env with the env from config
const envFromConfig = { ...process.env };
const envSettingKey = platform.isWindows ? 'windows' : (platform.isMacintosh ? 'osx' : 'linux');
TerminalInstance.mergeEnvironments(envFromConfig, this._configHelper.config.env[envSettingKey]);
const parentEnv = { ...process.env };
TerminalInstance.mergeEnvironments(parentEnv, envFromConfig);
// Continue env initialization, merging in the env from the launch
// config and adding keys that are needed to create the process
const env = TerminalInstance.createTerminalEnv(envFromConfig, this._shellLaunchConfig, this._initialCwd, locale, this._cols, this._rows);
const env = TerminalInstance.createTerminalEnv(parentEnv, this._shellLaunchConfig, this._initialCwd, locale, this._cols, this._rows);
this._process = cp.fork(Uri.parse(require.toUrl('bootstrap')).fsPath, ['--type=terminal'], {
env,
cwd: Uri.parse(path.dirname(require.toUrl('../node/terminalProcess'))).fsPath
......@@ -636,6 +648,16 @@ export class TerminalInstance implements ITerminalInstance {
}, LAUNCHING_DURATION);
}
// TODO: Should be protected
private static resolveConfigurationVariables(configurationResolverService: IConfigurationResolverService, env: IStringDictionary<string>, lastActiveWorkspaceRoot: IWorkspaceFolder): IStringDictionary<string> {
Object.keys(env).forEach((key) => {
if (typeof env[key] === 'string') {
env[key] = configurationResolverService.resolve(lastActiveWorkspaceRoot, env[key]);
}
});
return env;
}
private _sendPtyDataToXterm(message: { type: string, content: string }): void {
if (message.type === 'data') {
if (this._widgetManager) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册