Skip to content

Commit

Permalink
Support env in terminal profiles
Browse files Browse the repository at this point in the history
Fixes #120366
  • Loading branch information
Tyriar committed Apr 7, 2021
1 parent 2829879 commit 95c63b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ export class TerminalService implements ITerminalService {
return {
executable: profile.path,
args: profile.args,
env: profile.env,
icon: profile.icon,
name: profile.overrideName ? profile.profileName : undefined
};
Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { OperatingSystem } from 'vs/base/common/platform';
import { IExtensionPointDescriptor } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { IProcessDataEvent, IShellLaunchConfig, ITerminalDimensions, ITerminalDimensionsOverride, ITerminalLaunchError, TerminalShellType } from 'vs/platform/terminal/common/terminal';
import { IProcessDataEvent, IShellLaunchConfig, ITerminalDimensions, ITerminalDimensionsOverride, ITerminalEnvironment, ITerminalLaunchError, TerminalShellType } from 'vs/platform/terminal/common/terminal';
import { IEnvironmentVariableInfo } from 'vs/workbench/contrib/terminal/common/environmentVariable';

export const TERMINAL_VIEW_ID = 'terminal';
Expand Down Expand Up @@ -237,6 +237,7 @@ export interface ITerminalProfile {
isAutoDetected?: boolean;
isWorkspaceProfile?: boolean;
args?: string | string[] | undefined;
env?: ITerminalEnvironment;
overrideName?: boolean;
icon?: string;
}
Expand All @@ -252,6 +253,7 @@ export interface ITerminalExecutable {
isAutoDetected?: boolean;
overrideName?: boolean;
icon?: string;
env?: ITerminalEnvironment;
}

export interface ITerminalProfileSource {
Expand All @@ -260,6 +262,7 @@ export interface ITerminalProfileSource {
overrideName?: boolean;
args?: string | string[] | undefined;
icon?: string;
env?: ITerminalEnvironment;
}

export type ITerminalProfileObject = ITerminalExecutable | ITerminalProfileSource | null;
Expand Down
16 changes: 16 additions & 0 deletions src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const terminalProfileSchema: IJSONSchema = {
icon: {
description: localize('terminalProfile.icon', 'A codicon ID to associate with this terminal.'),
type: 'string'
},
env: {
markdownDescription: localize('terminalProfile.env', "An object with environment variables that will be added to the terminal profile process. Set to `null` to delete environment variables from the base environment."),
type: 'object',
additionalProperties: {
type: ['string', 'null']
},
default: {}
}
}
};
Expand Down Expand Up @@ -153,6 +161,14 @@ export const terminalConfiguration: IConfigurationNode = {
icon: {
description: localize('terminalProfile.icon', 'A codicon ID to associate with this terminal.'),
type: 'string'
},
env: {
markdownDescription: localize('terminalProfile.env', "An object with environment variables that will be added to the terminal profile process. Set to `null` to delete environment variables from the base environment."),
type: 'object',
additionalProperties: {
type: ['string', 'null']
},
default: {}
}
}
},
Expand Down
11 changes: 6 additions & 5 deletions src/vs/workbench/contrib/terminal/node/terminalProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ExtHostVariableResolverService } from 'vs/workbench/api/common/extHostD
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { ILogService } from 'vs/platform/log/common/log';
import * as pfs from 'vs/base/node/pfs';
import { ITerminalEnvironment } from 'vs/platform/terminal/common/terminal';

let profileSources: Map<string, IPotentialTerminalProfile> | undefined;

Expand Down Expand Up @@ -113,7 +114,7 @@ async function transformToTerminalProfiles(entries: IterableIterator<[string, IT
for (let i = 0; i < paths.length; i++) {
paths[i] = await variableResolver?.resolveAsync(workspaceFolder, paths[i]) || paths[i];
}
const validatedProfile = await validateProfilePaths(profileName, paths, fsProvider, args, profile.overrideName, profile.isAutoDetected, logService);
const validatedProfile = await validateProfilePaths(profileName, paths, fsProvider, args, profile.env, profile.overrideName, profile.isAutoDetected, logService);
if (validatedProfile) {
validatedProfile.isAutoDetected = profile.isAutoDetected;
validatedProfile.icon = icon;
Expand Down Expand Up @@ -258,16 +259,16 @@ function applyConfigProfilesToMap(configProfiles: { [key: string]: ITerminalProf
}
}

async function validateProfilePaths(profileName: string, potentialPaths: string[], fsProvider: IFsProvider, args?: string[] | string, overrideName?: boolean, isAutoDetected?: boolean, logService?: ILogService): Promise<ITerminalProfile | undefined> {
async function validateProfilePaths(profileName: string, potentialPaths: string[], fsProvider: IFsProvider, args?: string[] | string, env?: ITerminalEnvironment, overrideName?: boolean, isAutoDetected?: boolean, logService?: ILogService): Promise<ITerminalProfile | undefined> {
if (potentialPaths.length === 0) {
return Promise.resolve(undefined);
}
const path = potentialPaths.shift()!;
if (path === '') {
return validateProfilePaths(profileName, potentialPaths, fsProvider, args, overrideName, isAutoDetected);
return validateProfilePaths(profileName, potentialPaths, fsProvider, args, env, overrideName, isAutoDetected);
}

const profile = { profileName, path, args, overrideName, isAutoDetected };
const profile: ITerminalProfile = { profileName, path, args, env, overrideName, isAutoDetected };

// For non-absolute paths, check if it's available on $PATH
if (basename(path) === path) {
Expand All @@ -285,7 +286,7 @@ async function validateProfilePaths(profileName: string, potentialPaths: string[
return profile;
}

return validateProfilePaths(profileName, potentialPaths, fsProvider, args, overrideName, isAutoDetected);
return validateProfilePaths(profileName, potentialPaths, fsProvider, args, env, overrideName, isAutoDetected);
}

export interface IFsProvider {
Expand Down

0 comments on commit 95c63b6

Please sign in to comment.