Skip to content

Commit

Permalink
Work in progress for PATH prefix/suffix in si
Browse files Browse the repository at this point in the history
Part of #99878
  • Loading branch information
Tyriar committed Jan 10, 2023
1 parent 5fe77b7 commit 98809b2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
47 changes: 46 additions & 1 deletion src/vs/platform/terminal/node/terminalEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import * as pfs from 'vs/base/node/pfs';
import { ILogService } from 'vs/platform/log/common/log';
import { IProductService } from 'vs/platform/product/common/productService';
import { IShellLaunchConfig, ITerminalEnvironment, ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal';
import { EnvironmentVariableMutatorType, IEnvironmentVariableCollection, IEnvironmentVariableMutator } from 'vs/workbench/contrib/terminal/common/environmentVariable';
// TODO: Fix import
import { deserializeEnvironmentVariableCollections } from 'vs/workbench/contrib/terminal/common/environmentVariableShared';
import { MergedEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariableCollection';

export function getWindowsBuildNumber(): number {
const osVersion = (/(\d+)\.(\d+)\.(\d+)/g).exec(os.release());
Expand Down Expand Up @@ -104,7 +108,7 @@ export interface IShellIntegrationConfigInjection {
*/
export function getShellIntegrationInjection(
shellLaunchConfig: IShellLaunchConfig,
options: Pick<ITerminalProcessOptions, 'shellIntegration' | 'windowsEnableConpty'>,
options: ITerminalProcessOptions,
env: ITerminalEnvironment | undefined,
logService: ILogService,
productService: IProductService
Expand All @@ -125,6 +129,47 @@ export function getShellIntegrationInjection(
'VSCODE_INJECTION': '1'
};

// TODO: Only do this on macOS
if (options.environmentVariableCollections) {
// Deserialize and merge
const deserialized = deserializeEnvironmentVariableCollections(options.environmentVariableCollections);

// TODO: Remove test data
const map: Map<string, IEnvironmentVariableMutator> = new Map();
map.set('PATH', { value: 'before:', type: EnvironmentVariableMutatorType.Prepend });
deserialized.set('some.ext', { map });
const map2: Map<string, IEnvironmentVariableMutator> = new Map();
map2.set('PATH', { value: 'before for ext2:', type: EnvironmentVariableMutatorType.Prepend });
deserialized.set('some.ext2', { map: map2 });
const map3: Map<string, IEnvironmentVariableMutator> = new Map();
map3.set('PATH', { value: ':after', type: EnvironmentVariableMutatorType.Append });
deserialized.set('some.ext3', { map: map3 });
logService.info('deserialized', deserialized);

const merged = new MergedEnvironmentVariableCollection(deserialized);

// Get all append and prepend PATH entries
const pathEntry = merged.map.get('PATH');
const appendToPath: string[] = [];
const prependToPath: string[] = [];
if (pathEntry) {
for (const mutator of pathEntry) {
switch (mutator.type) {
case EnvironmentVariableMutatorType.Append: appendToPath.push(mutator.value); break;
case EnvironmentVariableMutatorType.Prepend: prependToPath.push(mutator.value); break;
}
}
}

// Add to the environment mixin to be applied in the shell integration script
if (appendToPath.length > 0) {
envMixin['VSCODE_PATH_SUFFIX'] = appendToPath.join('');
}
if (prependToPath.length > 0) {
envMixin['VSCODE_PATH_PREFIX'] = appendToPath.join('');
}
}

// Windows
if (isWindows) {
if (shell === 'pwsh.exe' || shell === 'powershell.exe') {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/terminal/node/terminalProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess

let injection: IShellIntegrationConfigInjection | undefined;
if (this._options.shellIntegration.enabled) {
injection = getShellIntegrationInjection(this.shellLaunchConfig, { shellIntegration: this._options.shellIntegration, windowsEnableConpty: this._options.windowsEnableConpty }, this._ptyOptions.env, this._logService, this._productService);
injection = getShellIntegrationInjection(this.shellLaunchConfig, this._options, this._ptyOptions.env, this._logService, this._productService);
if (injection) {
this._onDidChangeProperty.fire({ type: ProcessPropertyType.UsedShellIntegrationInjection, value: true });
if (injection.envMixin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal';
import { getShellIntegrationInjection, IShellIntegrationConfigInjection } from 'vs/platform/terminal/node/terminalEnvironment';

const enabledProcessOptions: Pick<ITerminalProcessOptions, 'shellIntegration' | 'windowsEnableConpty'> = { shellIntegration: { enabled: true }, windowsEnableConpty: true };
const disabledProcessOptions: Pick<ITerminalProcessOptions, 'shellIntegration' | 'windowsEnableConpty'> = { shellIntegration: { enabled: false }, windowsEnableConpty: true };
const winptyProcessOptions: Pick<ITerminalProcessOptions, 'shellIntegration' | 'windowsEnableConpty'> = { shellIntegration: { enabled: true }, windowsEnableConpty: false };
// TODO: Fix
const enabledProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: true }, windowsEnableConpty: true } as any;
const disabledProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: false }, windowsEnableConpty: true } as any;
const winptyProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: true }, windowsEnableConpty: false } as any;
const pwshExe = process.platform === 'win32' ? 'pwsh.exe' : 'pwsh';
const repoRoot = process.platform === 'win32' ? process.cwd()[0].toLowerCase() + process.cwd().substring(1) : process.cwd();
const logService = new NullLogService();
Expand Down

0 comments on commit 98809b2

Please sign in to comment.