Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to specify shellArgs for the automationShell #131099

Merged
merged 2 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const enum TerminalSettingId {
AutomationShellLinux = 'terminal.integrated.automationShell.linux',
AutomationShellMacOs = 'terminal.integrated.automationShell.osx',
AutomationShellWindows = 'terminal.integrated.automationShell.windows',
AutomationProfileLinux = 'terminal.integrated.automationProfile.linux',
AutomationProfileMacOs = 'terminal.integrated.automationProfile.osx',
AutomationProfileWindows = 'terminal.integrated.automationProfile.windows',
ShellArgsLinux = 'terminal.integrated.shellArgs.linux',
ShellArgsMacOs = 'terminal.integrated.shellArgs.osx',
ShellArgsWindows = 'terminal.integrated.shellArgs.windows',
Expand Down
42 changes: 39 additions & 3 deletions src/vs/platform/terminal/common/terminalPlatformConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const terminalProfileSchema: IJSONSchema = {
const shellDeprecationMessageLinux = localize('terminal.integrated.shell.linux.deprecation', "This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile in {0} and setting its profile name as the default in {1}. This will currently take priority over the new profiles settings but that will change in the future.", '`#terminal.integrated.profiles.linux#`', '`#terminal.integrated.defaultProfile.linux#`');
const shellDeprecationMessageOsx = localize('terminal.integrated.shell.osx.deprecation', "This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile in {0} and setting its profile name as the default in {1}. This will currently take priority over the new profiles settings but that will change in the future.", '`#terminal.integrated.profiles.osx#`', '`#terminal.integrated.defaultProfile.osx#`');
const shellDeprecationMessageWindows = localize('terminal.integrated.shell.windows.deprecation', "This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile in {0} and setting its profile name as the default in {1}. This will currently take priority over the new profiles settings but that will change in the future.", '`#terminal.integrated.profiles.windows#`', '`#terminal.integrated.defaultProfile.windows#`');
const automationShellDeprecationMessageLinux = localize('terminal.integrated.automationShell.linux.deprecation', "This is deprecated, the new recommended way to configure your automation shell is by creating a terminal automation profile with {0}. This will currently take priority over the new automation profile settings but that will change in the future.", '`#terminal.integrated.automationProfile.linux#`');
const automationShellDeprecationMessageOsx = localize('terminal.integrated.automationShell.osx.deprecation', "This is deprecated, the new recommended way to configure your automation shell is by creating a terminal automation profile with {0}. This will currently take priority over the new automation profile settings but that will change in the future.", '`#terminal.integrated.automationProfile.osx#`');
const automationShellDeprecationMessageWindows = localize('terminal.integrated.automationShell.windows.deprecation', "This is deprecated, the new recommended way to configure your automation shell is by creating a terminal automation profile with {0}. This will currently take priority over the new automation profile settings but that will change in the future.", '`#terminal.integrated.automationProfile.windows#`');

const terminalPlatformConfiguration: IConfigurationNode = {
id: 'terminal',
Expand All @@ -87,7 +90,8 @@ const terminalPlatformConfiguration: IConfigurationNode = {
comment: ['{0} and {1} are the `shell` and `shellArgs` settings keys']
}, "A path that when set will override {0} and ignore {1} values for automation-related terminal usage like tasks and debug.", '`terminal.integrated.shell.linux`', '`shellArgs`'),
type: ['string', 'null'],
default: null
default: null,
markdownDeprecationMessage: automationShellDeprecationMessageLinux
},
[TerminalSettingId.AutomationShellMacOs]: {
restricted: true,
Expand All @@ -96,7 +100,8 @@ const terminalPlatformConfiguration: IConfigurationNode = {
comment: ['{0} and {1} are the `shell` and `shellArgs` settings keys']
}, "A path that when set will override {0} and ignore {1} values for automation-related terminal usage like tasks and debug.", '`terminal.integrated.shell.osx`', '`shellArgs`'),
type: ['string', 'null'],
default: null
default: null,
markdownDeprecationMessage: automationShellDeprecationMessageOsx
},
[TerminalSettingId.AutomationShellWindows]: {
restricted: true,
Expand All @@ -105,7 +110,38 @@ const terminalPlatformConfiguration: IConfigurationNode = {
comment: ['{0} and {1} are the `shell` and `shellArgs` settings keys']
}, "A path that when set will override {0} and ignore {1} values for automation-related terminal usage like tasks and debug.", '`terminal.integrated.shell.windows`', '`shellArgs`'),
type: ['string', 'null'],
default: null
default: null,
markdownDeprecationMessage: automationShellDeprecationMessageWindows
},
[TerminalSettingId.AutomationProfileLinux]: {
alexr00 marked this conversation as resolved.
Show resolved Hide resolved
restricted: true,
markdownDescription: localize('terminal.integrated.automationProfile.linux', "The terminal profile to use on Linux for automation-related terminal usage like tasks and debug. This setting will currently be ignored if {0} is set.", '#terminal.integrated.automationShell.linux#'),
type: ['object', 'null'],
default: null,
'anyOf': [
{ type: 'null' },
terminalProfileSchema
]
},
[TerminalSettingId.AutomationProfileMacOs]: {
restricted: true,
description: localize('terminal.integrated.automationProfile.osx', "The terminal profile to use on macOS for automation-related terminal usage like tasks and debug. This setting will currently be ignored if {0} is set.", '#terminal.integrated.automationShell.osx#'),
type: ['object', 'null'],
default: null,
'anyOf': [
{ type: 'null' },
terminalProfileSchema
]
},
[TerminalSettingId.AutomationProfileWindows]: {
restricted: true,
description: localize('terminal.integrated.automationProfile.windows', "The terminal profile to use for automation-related terminal usage like tasks and debug. This setting will currently be ignored if {0} is set.", '#terminal.integrated.automationShell.windows#'),
type: ['object', 'null'],
default: null,
'anyOf': [
{ type: 'null' },
terminalProfileSchema
]
},
[TerminalSettingId.ShellLinux]: {
restricted: true,
Expand Down
22 changes: 14 additions & 8 deletions src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,11 +1059,16 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
os,
remoteAuthority: this.environmentService.remoteAuthority
});
const defaultConfig = {
shell: defaultProfile.path,
args: defaultProfile.args
shellLaunchConfig = {
name: terminalName,
description,
executable: defaultProfile.path,
args: defaultProfile.args,
icon: defaultProfile.icon,
env: { ...defaultProfile.env },
color: defaultProfile.color,
waitOnExit
};
shellLaunchConfig = { name: terminalName, description, executable: defaultConfig.shell, args: defaultConfig.args, waitOnExit };
let shellSpecified: boolean = false;
let shellOptions: ShellConfiguration | undefined = task.command.options && task.command.options.shell;
if (shellOptions) {
Expand Down Expand Up @@ -1189,7 +1194,11 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
shellLaunchConfig.cwd = isUNC(cwd) ? cwd : resources.toLocalResource(URI.from({ scheme: Schemas.file, path: cwd }), this.environmentService.remoteAuthority, this.pathService.defaultUriScheme);
}
if (options.env) {
shellLaunchConfig.env = options.env;
if (shellLaunchConfig.env) {
shellLaunchConfig.env = { ...shellLaunchConfig.env, ...options.env };
} else {
shellLaunchConfig.env = options.env;
}
}
shellLaunchConfig.isFeatureTerminal = true;
shellLaunchConfig.useShellEnvironment = true;
Expand Down Expand Up @@ -1244,9 +1253,6 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
return [undefined, undefined, new TaskError(Severity.Error, nls.localize('TerminalTaskSystem', 'Can\'t execute a shell command on an UNC drive using cmd.exe.'), TaskErrors.UnknownError)];
}
}
if (this.currentTask.shellLaunchConfig) {
this.currentTask.shellLaunchConfig.icon = { id: 'tools' };
}

let prefersSameTerminal = presentationOptions.panel === PanelKind.Dedicated;
let allowsSharedTerminal = presentationOptions.panel === PanelKind.Shared;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { debounce } from 'vs/base/common/decorators';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { URI, UriComponents } from 'vs/base/common/uri';
import { equals } from 'vs/base/common/arrays';
import { deepClone } from 'vs/base/common/objects';

export interface IProfileContextProvider {
getDefaultSystemShell: (remoteAuthority: string | undefined, os: OperatingSystem) => Promise<string>;
Expand Down Expand Up @@ -179,6 +180,15 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro
typeof (<any>thing).scheme === 'string';
}

private _setIconForAutomation(options: IShellLaunchConfigResolveOptions, profile: ITerminalProfile): ITerminalProfile {
if (options.allowAutomationShell) {
const profileClone = deepClone(profile);
profileClone.icon = Codicon.tools;
return profileClone;
}
return profile;
}
Comment on lines +183 to +190
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just set the icon explicitly inside tasks? Automation profiles are also used by debug and it's not that nice with all these icon special cases. Would this work?

icon: defaultProfile.icon || Codicon.tools,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with that, but the default profile often already has an icon so the tools icon will never get used.


private async _getUnresolvedDefaultProfile(options: IShellLaunchConfigResolveOptions): Promise<ITerminalProfile> {
// If automation shell is allowed, prefer that
if (options.allowAutomationShell) {
Expand All @@ -192,20 +202,20 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro
// allow users to migrate, see https://github.com/microsoft/vscode/issues/123171
const shellSettingProfile = await this._getUnresolvedShellSettingDefaultProfile(options);
if (shellSettingProfile) {
return shellSettingProfile;
return this._setIconForAutomation(options, shellSettingProfile);
}

// Return the real default profile if it exists and is valid, wait for profiles to be ready
// if the window just opened
await this._terminalService.profilesReady;
const defaultProfile = this._getUnresolvedRealDefaultProfile(options.os);
if (defaultProfile) {
return defaultProfile;
return this._setIconForAutomation(options, defaultProfile);
}

// If there is no real default profile, create a fallback default profile based on the shell
// and shellArgs settings in addition to the current environment.
return this._getUnresolvedFallbackDefaultProfile(options);
return this._setIconForAutomation(options, await this._getUnresolvedFallbackDefaultProfile(options));
}

private _getUnresolvedRealDefaultProfile(os: OperatingSystem): ITerminalProfile | undefined {
Expand Down Expand Up @@ -260,8 +270,12 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro
const executable = await this._context.getDefaultSystemShell(options.remoteAuthority, options.os);

// Try select an existing profile to fallback to, based on the default system shell
const existingProfile = this._terminalService.availableProfiles.find(e => path.parse(e.path).name === path.parse(executable).name);
let existingProfile = this._terminalService.availableProfiles.find(e => path.parse(e.path).name === path.parse(executable).name);
if (existingProfile) {
if (options.allowAutomationShell) {
existingProfile = deepClone(existingProfile);
existingProfile.icon = Codicon.tools;
}
return existingProfile;
}

Expand All @@ -288,14 +302,23 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro

private _getUnresolvedAutomationShellProfile(options: IShellLaunchConfigResolveOptions): ITerminalProfile | undefined {
const automationShell = this._configurationService.getValue(`terminal.integrated.automationShell.${this._getOsKey(options.os)}`);
if (!automationShell || typeof automationShell !== 'string') {
return undefined;
if (automationShell && typeof automationShell === 'string') {
return {
path: automationShell,
profileName: generatedProfileName,
isDefault: false,
icon: Codicon.tools
};
}
return {
path: automationShell,
profileName: generatedProfileName,
isDefault: false
};

// Use automationProfile second
const automationProfile = this._configurationService.getValue(`terminal.integrated.automationProfile.${this._getOsKey(options.os)}`);
if (this._isValidAutomationProfile(automationProfile, options.os)) {
automationProfile.icon = automationProfile.icon ?? Codicon.tools;
return automationProfile;
}

return undefined;
}

private async _resolveProfile(profile: ITerminalProfile, options: IShellLaunchConfigResolveOptions): Promise<ITerminalProfile> {
Expand Down Expand Up @@ -422,6 +445,16 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro
return createdProfile;
}

private _isValidAutomationProfile(profile: unknown, os: OperatingSystem): profile is ITerminalProfile {
if (!profile === undefined || typeof profile !== 'object' || profile === null) {
return false;
}
if ('path' in profile && typeof (profile as { path: unknown }).path === 'string') {
return true;
}
return false;
}

private _argsMatch(args1: string | string[] | undefined, args2: string | string[] | undefined): boolean {
if (!args1 && !args2) {
return true;
Expand Down