Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down