diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index 28a4c9b649f..e7fbd010b37 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -439,5 +439,3 @@ export interface ITerminalDimensionsOverride extends Readonly(key: string) => T | undefined; diff --git a/src/vs/workbench/api/node/extHostTerminalService.ts b/src/vs/workbench/api/node/extHostTerminalService.ts index 87218189147..710a3dd1833 100644 --- a/src/vs/workbench/api/node/extHostTerminalService.ts +++ b/src/vs/workbench/api/node/extHostTerminalService.ts @@ -8,7 +8,6 @@ import { withNullAsUndefined } from 'vs/base/common/types'; import { generateUuid } from 'vs/base/common/uuid'; import { getSystemShell, getSystemShellSync } from 'vs/base/node/shell'; import { ILogService } from 'vs/platform/log/common/log'; -import { SafeConfigProvider } from 'vs/platform/terminal/common/terminal'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IShellAndArgsDto } from 'vs/workbench/api/common/extHost.protocol'; import { ExtHostConfigProvider, ExtHostConfiguration, IExtHostConfiguration } from 'vs/workbench/api/common/extHostConfiguration'; @@ -17,7 +16,7 @@ import { ExtHostDocumentsAndEditors, IExtHostDocumentsAndEditors } from 'vs/work import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; import { BaseExtHostTerminalService, ExtHostTerminal } from 'vs/workbench/api/common/extHostTerminalService'; import { ExtHostWorkspace, IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace'; -import { ITerminalProfile } from 'vs/workbench/contrib/terminal/common/terminal'; +import { ITerminalConfiguration, ITerminalProfile } from 'vs/workbench/contrib/terminal/common/terminal'; import * as terminalEnvironment from 'vs/workbench/contrib/terminal/common/terminalEnvironment'; import { detectAvailableProfiles } from 'vs/workbench/contrib/terminal/node/terminalProfiles'; import type * as vscode from 'vscode'; @@ -76,8 +75,14 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { } public getDefaultShell(useAutomationShell: boolean, configProvider: ExtHostConfigProvider): string { + const fetchSetting = (key: string): string | undefined => { + return configProvider + .getConfiguration(key.substr(0, key.lastIndexOf('.'))) + .get(key.substr(key.lastIndexOf('.') + 1)); + }; + return terminalEnvironment.getDefaultShell( - this._buildSafeConfigProvider(configProvider), + fetchSetting, this._defaultShell ?? getSystemShellSync(platform.OS, process.env as platform.IProcessEnvironment), process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'), process.env.windir, @@ -88,12 +93,13 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { } public getDefaultShellArgs(useAutomationShell: boolean, configProvider: ExtHostConfigProvider): string[] | string { - return terminalEnvironment.getDefaultShellArgs( - this._buildSafeConfigProvider(configProvider), - useAutomationShell, - terminalEnvironment.createVariableResolver(this._lastActiveWorkspace, process.env, this._variableResolver), - this._logService - ); + const fetchSetting = (key: string): string | string[] | undefined => { + return configProvider + .getConfiguration(key.substr(0, key.lastIndexOf('.'))) + .get(key.substr(key.lastIndexOf('.') + 1)); + }; + + return terminalEnvironment.getDefaultShellArgs(fetchSetting, useAutomationShell, terminalEnvironment.createVariableResolver(this._lastActiveWorkspace, process.env, this._variableResolver), this._logService); } private _registerListeners(): void { @@ -118,8 +124,8 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { } public async $getAvailableProfiles(configuredProfilesOnly: boolean): Promise { - const safeConfigProvider = this._buildSafeConfigProvider(await this._extHostConfiguration.getConfigProvider()); - return detectAvailableProfiles(configuredProfilesOnly, safeConfigProvider, undefined, this._logService, await this._variableResolverPromise, this._lastActiveWorkspace); + const config = await (await this._extHostConfiguration.getConfigProvider()).getConfiguration().get('terminal.integrated'); + return detectAvailableProfiles(configuredProfilesOnly, undefined, this._logService, config as ITerminalConfiguration, await this._variableResolverPromise, this._lastActiveWorkspace); } public async $getDefaultShellAndArgs(useAutomationShell: boolean): Promise { @@ -129,17 +135,4 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { args: this.getDefaultShellArgs(useAutomationShell, configProvider) }; } - - // TODO: Remove when workspace trust is enabled - private _buildSafeConfigProvider(configProvider: ExtHostConfigProvider): SafeConfigProvider { - const config = configProvider.getConfiguration(); - return (key: string) => { - const isWorkspaceConfigAllowed = config.get('terminal.integrated.allowWorkspaceConfiguration'); - if (isWorkspaceConfigAllowed) { - return config.get(key) as any; - } - const inspected = config.inspect(key); - return inspected?.globalValue || inspected?.defaultValue; - }; - } } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index d3ca7436df2..d6abf0bc370 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -16,6 +16,7 @@ import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IProductService } from 'vs/platform/product/common/productService'; import { IRemoteTerminalService, ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { Disposable, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { withNullAsUndefined } from 'vs/base/common/types'; @@ -26,7 +27,7 @@ import { IProcessDataEvent, IShellLaunchConfig, ITerminalChildProcess, ITerminal import { TerminalRecorder } from 'vs/platform/terminal/common/terminalRecorder'; import { localize } from 'vs/nls'; import { formatMessageForTerminal } from 'vs/workbench/contrib/terminal/common/terminalStrings'; -import { IProcessEnvironment, OperatingSystem, OS } from 'vs/base/common/platform'; +import { IProcessEnvironment, isMacintosh, isWindows, OperatingSystem, OS } from 'vs/base/common/platform'; /** The amount of time to consider terminal errors to be related to the launch */ const LAUNCHING_DURATION = 500; @@ -116,6 +117,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce @ILogService private readonly _logService: ILogService, @IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService, @IConfigurationResolverService private readonly _configurationResolverService: IConfigurationResolverService, + @IConfigurationService private readonly _configurationService: IConfigurationService, @IWorkbenchEnvironmentService private readonly _workbenchEnvironmentService: IWorkbenchEnvironmentService, @IProductService private readonly _productService: IProductService, @ITerminalInstanceService private readonly _terminalInstanceService: ITerminalInstanceService, @@ -333,9 +335,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // Fetch any extension environment additions and apply them private async _setupEnvVariableInfo(variableResolver: terminalEnvironment.VariableResolver | undefined, shellLaunchConfig: IShellLaunchConfig): Promise { - // const platformKey = isWindows ? 'windows' : (isMacintosh ? 'osx' : 'linux'); - // this._configurationService.getValue(`terminal.integrated.env.${platformKey}`); - const envFromConfigValue = this._terminalProfileResolverService.getSafeConfigValue('env', OS) as ITerminalEnvironment | undefined; + const platformKey = isWindows ? 'windows' : (isMacintosh ? 'osx' : 'linux'); + const envFromConfigValue = this._configurationService.getValue(`terminal.integrated.env.${platformKey}`); this._configHelper.showRecommendations(shellLaunchConfig); const baseEnv = await (this._configHelper.config.inheritEnv ? this._terminalProfileResolverService.getShellEnvironment(this.remoteAuthority) diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts b/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts index fcedae4ecc8..9cb5a6e6175 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts @@ -123,7 +123,7 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro private _getRealDefaultProfile(sync: true, os: OperatingSystem): ITerminalProfile | undefined; private _getRealDefaultProfile(sync: false, os: OperatingSystem): Promise; private _getRealDefaultProfile(sync: boolean, os: OperatingSystem): ITerminalProfile | undefined | Promise { - const defaultProfileName = this.getSafeConfigValue('defaultProfile', os); + const defaultProfileName = this._configurationService.getValue(`terminal.integrated.defaultProfile.${this._getOsKey(os)}`); if (defaultProfileName && typeof defaultProfileName === 'string') { if (sync) { const profiles = this._terminalService.availableProfiles; @@ -138,10 +138,10 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro private async _getFallbackDefaultProfile(options: IShellLaunchConfigResolveOptions): Promise { let executable: string; let args: string | string[] | undefined; - const shellSetting = this.getSafeConfigValue('shell', options.os); + const shellSetting = this._configurationService.getValue(`terminal.integrated.shell.${this._getOsKey(options.os)}`); if (this._isValidShell(shellSetting)) { executable = shellSetting; - const shellArgsSetting = this.getSafeConfigValue('shellArgs', options.os); + const shellArgsSetting = this._configurationService.getValue(`terminal.integrated.shellArgs.${this._getOsKey(options.os)}`); if (this._isValidShellArgs(shellArgsSetting, options.os)) { args = shellArgsSetting; } @@ -170,7 +170,7 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro } private _getAutomationShellProfile(options: IShellLaunchConfigResolveOptions): ITerminalProfile | undefined { - const automationShell = this.getSafeConfigValue('automationShell', options.os); + const automationShell = this._configurationService.getValue(`terminal.integrated.automationShell.${this._getOsKey(options.os)}`); if (!automationShell || typeof automationShell !== 'string') { return undefined; } @@ -274,28 +274,6 @@ export abstract class BaseTerminalProfileResolverService implements ITerminalPro } return false; } - - // TODO: Remove when workspace trust is enabled - getSafeConfigValue(key: string, os: OperatingSystem): unknown | undefined { - return this.getSafeConfigValueFullKey(`terminal.integrated.${key}.${this._getOsKey(os)}`); - } - getSafeConfigValueFullKey(key: string): unknown | undefined { - const isWorkspaceConfigAllowed = this._configurationService.getValue('terminal.integrated.allowWorkspaceConfiguration'); - if (isWorkspaceConfigAllowed) { - return this._configurationService.getValue(key); - } else { - const config = this._configurationService.inspect(key); - const value = config.user?.value || config.default?.value; - // Clone if needed to allow extensibility - if (Array.isArray(value)) { - return value.slice(); - } - if (typeof value === 'object') { - return { ...value }; - } - return value; - } - } } export class BrowserTerminalProfileResolverService extends BaseTerminalProfileResolverService { diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index c9e3f95d139..49f5c69b10b 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -19,7 +19,7 @@ import { Schemas } from 'vs/base/common/network'; import { ILabelService } from 'vs/platform/label/common/label'; import { IEnvironmentVariableService, ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { IProcessDataEvent, IShellLaunchConfig, IShellLaunchConfigDto, ITerminalDimensionsOverride, ITerminalEnvironment, ITerminalLaunchError, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, TerminalShellType } from 'vs/platform/terminal/common/terminal'; -import { ITerminalConfiguration, ITerminalProfileResolverService, TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal'; +import { ITerminalConfiguration, TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal'; import { IGetTerminalLayoutInfoArgs, IProcessDetails, IPtyHostProcessReplayEvent, ISetTerminalLayoutInfoArgs } from 'vs/platform/terminal/common/terminalProcess'; import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; @@ -125,7 +125,6 @@ export class RemoteTerminalChannelClient { @IConfigurationResolverService private readonly _resolverService: IConfigurationResolverService, @IEnvironmentVariableService private readonly _environmentVariableService: IEnvironmentVariableService, @IRemoteAuthorityResolverService private readonly _remoteAuthorityResolverService: IRemoteAuthorityResolverService, - @ITerminalProfileResolverService private readonly _terminalProfileResolverService: ITerminalProfileResolverService, @ILogService private readonly _logService: ILogService, @IEditorService private readonly _editorService: IEditorService, @ILabelService private readonly _labelService: ILabelService, @@ -141,20 +140,20 @@ export class RemoteTerminalChannelClient { const terminalConfig = this._configurationService.getValue(TERMINAL_CONFIG_SECTION); const configuration: ICompleteTerminalConfiguration = { - 'terminal.integrated.automationShell.windows': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.automationShell.windows') as string, - 'terminal.integrated.automationShell.osx': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.automationShell.osx') as string, - 'terminal.integrated.automationShell.linux': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.automationShell.linux') as string, - 'terminal.integrated.shell.windows': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.shell.windows') as string, - 'terminal.integrated.shell.osx': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.shell.osx') as string, - 'terminal.integrated.shell.linux': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.shell.linux') as string, - 'terminal.integrated.shellArgs.windows': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.shellArgs.windows') as string | string[], - 'terminal.integrated.shellArgs.osx': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.shellArgs.osx') as string | string[], - 'terminal.integrated.shellArgs.linux': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.shellArgs.linux') as string | string[], - 'terminal.integrated.env.windows': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.env.windows') as ITerminalEnvironment, - 'terminal.integrated.env.osx': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.env.osx') as ITerminalEnvironment, - 'terminal.integrated.env.linux': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.env.linux') as ITerminalEnvironment, + 'terminal.integrated.automationShell.windows': this._configurationService.getValue('terminal.integrated.automationShell.windows'), + 'terminal.integrated.automationShell.osx': this._configurationService.getValue('terminal.integrated.automationShell.osx'), + 'terminal.integrated.automationShell.linux': this._configurationService.getValue('terminal.integrated.automationShell.linux'), + 'terminal.integrated.shell.windows': this._configurationService.getValue('terminal.integrated.shell.windows'), + 'terminal.integrated.shell.osx': this._configurationService.getValue('terminal.integrated.shell.osx'), + 'terminal.integrated.shell.linux': this._configurationService.getValue('terminal.integrated.shell.linux'), + 'terminal.integrated.shellArgs.windows': this._configurationService.getValue('terminal.integrated.shellArgs.windows'), + 'terminal.integrated.shellArgs.osx': this._configurationService.getValue('terminal.integrated.shellArgs.osx'), + 'terminal.integrated.shellArgs.linux': this._configurationService.getValue('terminal.integrated.shellArgs.linux'), + 'terminal.integrated.env.windows': this._configurationService.getValue('terminal.integrated.env.windows'), + 'terminal.integrated.env.osx': this._configurationService.getValue('terminal.integrated.env.osx'), + 'terminal.integrated.env.linux': this._configurationService.getValue('terminal.integrated.env.linux'), 'terminal.integrated.inheritEnv': terminalConfig.inheritEnv, - 'terminal.integrated.cwd': this._terminalProfileResolverService.getSafeConfigValueFullKey('terminal.integrated.cwd') as string, + 'terminal.integrated.cwd': terminalConfig.cwd, 'terminal.integrated.detectLocale': terminalConfig.detectLocale }; diff --git a/src/vs/workbench/contrib/terminal/common/terminal.ts b/src/vs/workbench/contrib/terminal/common/terminal.ts index 7825250c489..e8f07ecc063 100644 --- a/src/vs/workbench/contrib/terminal/common/terminal.ts +++ b/src/vs/workbench/contrib/terminal/common/terminal.ts @@ -100,10 +100,6 @@ export interface ITerminalProfileResolverService { getDefaultShell(options: IShellLaunchConfigResolveOptions): Promise; getDefaultShellArgs(options: IShellLaunchConfigResolveOptions): Promise; getShellEnvironment(remoteAuthority: string | undefined): Promise; - - // TODO: Remove when workspace trust is enabled - getSafeConfigValue(key: string, os: OperatingSystem): unknown | undefined; - getSafeConfigValueFullKey(key: string): unknown | undefined; } export interface IShellLaunchConfigResolveOptions { @@ -199,7 +195,6 @@ export interface ITerminalConfiguration { focusMode: 'singleClick' | 'doubleClick'; }, bellDuration: number; - allowWorkspaceConfiguration: boolean; } export const DEFAULT_LOCAL_ECHO_EXCLUDE: ReadonlyArray = ['vim', 'vi', 'nano', 'tmux']; diff --git a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts index a6761c90469..d6975045420 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts @@ -60,6 +60,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.automationShell.linux': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize({ key: 'terminal.integrated.automationShell.linux', comment: ['{0} and {1} are the `shell` and `shellArgs` settings keys'] @@ -69,6 +71,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.automationShell.osx': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize({ key: 'terminal.integrated.automationShell.osx', comment: ['{0} and {1} are the `shell` and `shellArgs` settings keys'] @@ -78,6 +82,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.automationShell.windows': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize({ key: 'terminal.integrated.automationShell.windows', comment: ['{0} and {1} are the `shell` and `shellArgs` settings keys'] @@ -87,6 +93,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.shellArgs.linux': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize('terminal.integrated.shellArgs.linux', "The command line arguments to use when on the Linux terminal. [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration)."), type: 'array', items: { @@ -97,6 +105,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.shellArgs.osx': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize('terminal.integrated.shellArgs.osx', "The command line arguments to use when on the macOS terminal. [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration)."), type: 'array', items: { @@ -110,6 +120,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.shellArgs.windows': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize('terminal.integrated.shellArgs.windows', "The command line arguments to use when on the Windows terminal. [Read more about configuring the shell](https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration)."), 'anyOf': [ { @@ -129,6 +141,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.profiles.windows': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize( { key: 'terminal.integrated.profiles.windows', @@ -189,6 +203,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.profiles.osx': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize( { key: 'terminal.integrated.profile.osx', @@ -226,6 +242,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.profiles.linux': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize( { key: 'terminal.integrated.profile.linux', @@ -493,7 +511,6 @@ export const terminalConfiguration: IConfigurationNode = { description: localize('terminal.integrated.rightClickBehavior', "Controls how terminal reacts to right click.") }, 'terminal.integrated.cwd': { - restricted: true, description: localize('terminal.integrated.cwd', "An explicit start path where the terminal will be launched, this is used as the current working directory (cwd) for the shell process. This may be particularly useful in workspace settings if the root directory is not a convenient cwd."), type: 'string', default: undefined @@ -533,6 +550,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.env.osx': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize('terminal.integrated.env.osx', "Object with environment variables that will be added to the VS Code process to be used by the terminal on macOS. Set to `null` to delete the environment variable."), type: 'object', additionalProperties: { @@ -542,6 +561,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.env.linux': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize('terminal.integrated.env.linux', "Object with environment variables that will be added to the VS Code process to be used by the terminal on Linux. Set to `null` to delete the environment variable."), type: 'object', additionalProperties: { @@ -551,6 +572,8 @@ export const terminalConfiguration: IConfigurationNode = { }, 'terminal.integrated.env.windows': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: localize('terminal.integrated.env.windows', "Object with environment variables that will be added to the VS Code process to be used by the terminal on Windows. Set to `null` to delete the environment variable."), type: 'object', additionalProperties: { @@ -660,12 +683,6 @@ export const terminalConfiguration: IConfigurationNode = { description: localize('terminal.integrated.enablePersistentSessions', "Persist terminal sessions for the workspace across window reloads."), type: 'boolean', default: true - }, - 'terminal.integrated.allowWorkspaceConfiguration': { - scope: ConfigurationScope.APPLICATION, - description: localize('terminal.integrated.allowWorkspaceConfiguration', "Allows shell and profile settings to be pick up from a workspace."), - type: 'boolean', - default: false } } }; @@ -679,6 +696,8 @@ function getTerminalShellConfigurationStub(linux: string, osx: string, windows: properties: { 'terminal.integrated.shell.linux': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: linux, type: ['string', 'null'], default: null, @@ -686,6 +705,8 @@ function getTerminalShellConfigurationStub(linux: string, osx: string, windows: }, 'terminal.integrated.shell.osx': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: osx, type: ['string', 'null'], default: null, @@ -693,6 +714,8 @@ function getTerminalShellConfigurationStub(linux: string, osx: string, windows: }, 'terminal.integrated.shell.windows': { restricted: true, + // TODO: Remove when workspace trust is enabled by default + scope: ConfigurationScope.APPLICATION, markdownDescription: windows, type: ['string', 'null'], default: null, diff --git a/src/vs/workbench/contrib/terminal/node/terminalProfiles.ts b/src/vs/workbench/contrib/terminal/node/terminalProfiles.ts index 305d5aaf67c..5bec5055648 100644 --- a/src/vs/workbench/contrib/terminal/node/terminalProfiles.ts +++ b/src/vs/workbench/contrib/terminal/node/terminalProfiles.ts @@ -7,43 +7,27 @@ import * as fs from 'fs'; import { normalize, basename, delimiter } from 'vs/base/common/path'; import { enumeratePowerShellInstallations } from 'vs/base/node/powershell'; import { findExecutable, getWindowsBuildNumber } from 'vs/platform/terminal/node/terminalEnvironment'; -import { ITerminalProfile, ITerminalProfileObject, ProfileSource } from 'vs/workbench/contrib/terminal/common/terminal'; +import { ITerminalConfiguration, ITerminalProfile, ITerminalProfileObject, ProfileSource } from 'vs/workbench/contrib/terminal/common/terminal'; import * as cp from 'child_process'; import { ExtHostVariableResolverService } from 'vs/workbench/api/common/extHostDebugService'; 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, SafeConfigProvider } from 'vs/platform/terminal/common/terminal'; +import { ITerminalEnvironment } from 'vs/platform/terminal/common/terminal'; import { Codicon } from 'vs/base/common/codicons'; import { isMacintosh, isWindows } from 'vs/base/common/platform'; let profileSources: Map | undefined; -export function detectAvailableProfiles(configuredProfilesOnly: boolean, safeConfigProvider: SafeConfigProvider, fsProvider?: IFsProvider, logService?: ILogService, variableResolver?: ExtHostVariableResolverService, workspaceFolder?: IWorkspaceFolder, testPaths?: string[]): Promise { +export function detectAvailableProfiles(configuredProfilesOnly: boolean, fsProvider?: IFsProvider, logService?: ILogService, config?: ITerminalConfiguration, variableResolver?: ExtHostVariableResolverService, workspaceFolder?: IWorkspaceFolder, testPaths?: string[]): Promise { fsProvider = fsProvider || { existsFile: pfs.SymlinkSupport.existsFile, readFile: fs.promises.readFile }; if (isWindows) { - return detectAvailableWindowsProfiles( - configuredProfilesOnly, - fsProvider, - logService, - safeConfigProvider('terminal.integrated.useWslProfiles') || true, - safeConfigProvider('terminal.integrated.profiles.windows'), - variableResolver, - workspaceFolder - ); + return detectAvailableWindowsProfiles(configuredProfilesOnly, fsProvider, logService, config?.useWslProfiles, config?.profiles.windows, variableResolver, workspaceFolder); } - return detectAvailableUnixProfiles( - fsProvider, - logService, - configuredProfilesOnly, - safeConfigProvider(`terminal.integrated.profiles.${isMacintosh ? 'osx' : 'linux'}`), - testPaths, - variableResolver, - workspaceFolder - ); + return detectAvailableUnixProfiles(fsProvider, logService, configuredProfilesOnly, isMacintosh ? config?.profiles.osx : config?.profiles.linux, testPaths, variableResolver, workspaceFolder); } async function detectAvailableWindowsProfiles(configuredProfilesOnly: boolean, fsProvider: IFsProvider, logService?: ILogService, useWslProfiles?: boolean, configProfiles?: { [key: string]: ITerminalProfileObject }, variableResolver?: ExtHostVariableResolverService, workspaceFolder?: IWorkspaceFolder): Promise { diff --git a/src/vs/workbench/contrib/terminal/test/node/terminalProfiles.test.ts b/src/vs/workbench/contrib/terminal/test/node/terminalProfiles.test.ts index c96b8295bc7..d6d34bf808d 100644 --- a/src/vs/workbench/contrib/terminal/test/node/terminalProfiles.test.ts +++ b/src/vs/workbench/contrib/terminal/test/node/terminalProfiles.test.ts @@ -5,7 +5,6 @@ import { deepStrictEqual, fail, ok, strictEqual } from 'assert'; import { isWindows } from 'vs/base/common/platform'; -import { SafeConfigProvider } from 'vs/platform/terminal/common/terminal'; import { ITerminalConfiguration, ITerminalProfile, ITerminalProfiles, ProfileSource } from 'vs/workbench/contrib/terminal/common/terminal'; import { detectAvailableProfiles, IFsProvider } from 'vs/workbench/contrib/terminal/node/terminalProfiles'; @@ -26,18 +25,6 @@ function profilesEqual(actualProfiles: ITerminalProfile[], expectedProfiles: ITe } } -function buildTestSafeConfigProvider(config: ITestTerminalConfig): SafeConfigProvider { - return (key: string) => { - switch (key) { - case 'terminal.integrated.profiles.linux': return config.profiles.linux as any; - case 'terminal.integrated.profiles.osx': return config.profiles.osx as any; - case 'terminal.integrated.profiles.windows': return config.profiles.windows as any; - case 'terminal.integrated.useWslProfiles': return config.useWslProfiles; - default: throw new Error('Unexpected config key'); - } - }; -} - suite('Workbench - TerminalProfiles', () => { suite('detectAvailableProfiles', () => { if (isWindows) { @@ -55,7 +42,7 @@ suite('Workbench - TerminalProfiles', () => { }, useWslProfiles: false }; - const profiles = await detectAvailableProfiles(true, buildTestSafeConfigProvider(config), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(true, fsProvider, undefined, config as ITerminalConfiguration, undefined, undefined); const expected = [ { profileName: 'Git Bash', path: 'C:\\Program Files\\Git\\bin\\bash.exe', args: ['--login'] } ]; @@ -75,7 +62,7 @@ suite('Workbench - TerminalProfiles', () => { }, useWslProfiles: false }; - const profiles = await detectAvailableProfiles(true, buildTestSafeConfigProvider(config), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(true, fsProvider, undefined, config as ITerminalConfiguration, undefined, undefined); const expected = [ { profileName: 'PowerShell NoProfile', path: 'C:\\Program Files\\PowerShell\\7\\pwsh.exe', overrideName: true, args: ['-NoProfile'] } ]; @@ -95,7 +82,7 @@ suite('Workbench - TerminalProfiles', () => { }, useWslProfiles: false }; - const profiles = await detectAvailableProfiles(true, buildTestSafeConfigProvider(config), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(true, fsProvider, undefined, config as ITerminalConfiguration, undefined, undefined); const expected = [{ profileName: 'Git Bash', path: 'C:\\Program Files\\Git\\bin\\bash.exe', args: [], isAutoDetected: undefined, overrideName: undefined }]; profilesEqual(profiles, expected); }); @@ -117,7 +104,7 @@ suite('Workbench - TerminalProfiles', () => { 'C:\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe', 'C:\\System32\\WindowsPowerShell\\v1.0\\powershell.exe' ]); - const profiles = await detectAvailableProfiles(true, buildTestSafeConfigProvider(pwshSourceConfig), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(true, fsProvider, undefined, pwshSourceConfig, undefined, undefined); const expected = [ { profileName: 'PowerShell', path: 'C:\\Program Files\\PowerShell\\7\\pwsh.exe' } ]; @@ -130,7 +117,7 @@ suite('Workbench - TerminalProfiles', () => { 'C:\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe', 'C:\\System32\\WindowsPowerShell\\v1.0\\powershell.exe' ]); - const profiles = await detectAvailableProfiles(true, buildTestSafeConfigProvider(pwshSourceConfig), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(true, fsProvider, undefined, pwshSourceConfig, undefined, undefined); const expected = [ { profileName: 'PowerShell', path: 'C:\\Program Files\\PowerShell\\7\\pwsh.exe' } ]; @@ -141,7 +128,7 @@ suite('Workbench - TerminalProfiles', () => { 'C:\\Windows\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe', 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe' ]); - const profiles = await detectAvailableProfiles(true, buildTestSafeConfigProvider(pwshSourceConfig), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(true, fsProvider, undefined, pwshSourceConfig, undefined, undefined); strictEqual(profiles.length, 1); strictEqual(profiles[0].profileName, 'PowerShell'); }); @@ -185,7 +172,7 @@ suite('Workbench - TerminalProfiles', () => { '/bin/fakeshell1', '/bin/fakeshell3' ]); - const profiles = await detectAvailableProfiles(true, buildTestSafeConfigProvider(absoluteConfig), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(true, fsProvider, undefined, absoluteConfig, undefined, undefined); const expected: ITerminalProfile[] = [ { profileName: 'fakeshell1', path: '/bin/fakeshell1' }, { profileName: 'fakeshell3', path: '/bin/fakeshell3' } @@ -197,7 +184,7 @@ suite('Workbench - TerminalProfiles', () => { '/bin/fakeshell1', '/bin/fakeshell3' ], '/bin/fakeshell1\n/bin/fakeshell3'); - const profiles = await detectAvailableProfiles(false, buildTestSafeConfigProvider(onPathConfig), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(false, fsProvider, undefined, onPathConfig, undefined, undefined); const expected: ITerminalProfile[] = [ { profileName: 'fakeshell1', path: 'fakeshell1' }, { profileName: 'fakeshell3', path: 'fakeshell3' } @@ -209,7 +196,7 @@ suite('Workbench - TerminalProfiles', () => { const fsProvider = createFsProvider([ '/bin/fakeshell1' ], '/bin/fakeshell1\n/bin/fakeshell3'); - const profiles = await detectAvailableProfiles(false, buildTestSafeConfigProvider(onPathConfig), fsProvider, undefined, undefined, undefined); + const profiles = await detectAvailableProfiles(false, fsProvider, undefined, onPathConfig, undefined, undefined); const expected: ITerminalProfile[] = [ { profileName: 'fakeshell1', path: 'fakeshell1' } ]; diff --git a/src/vs/workbench/electron-sandbox/sandbox.simpleservices.ts b/src/vs/workbench/electron-sandbox/sandbox.simpleservices.ts index fc7dbe32bfb..ae741b3f555 100644 --- a/src/vs/workbench/electron-sandbox/sandbox.simpleservices.ts +++ b/src/vs/workbench/electron-sandbox/sandbox.simpleservices.ts @@ -330,8 +330,6 @@ class SimpleTerminalProfileResolverService implements ITerminalProfileResolverSe getDefaultShell(options: IShellLaunchConfigResolveOptions): Promise { throw new Error('Method not implemented.'); } getDefaultShellArgs(options: IShellLaunchConfigResolveOptions): Promise { throw new Error('Method not implemented.'); } getShellEnvironment(remoteAuthority: string | undefined): Promise { throw new Error('Method not implemented.'); } - getSafeConfigValue(key: string, os: OperatingSystem): unknown | undefined { throw new Error('Method not implemented.'); } - getSafeConfigValueFullKey(key: string): unknown | undefined { throw new Error('Method not implemented.'); } } registerSingleton(ITerminalProfileResolverService, SimpleTerminalProfileResolverService); diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index 91a7205a7ca..f26fa23e99e 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -1570,8 +1570,6 @@ export class TestTerminalProfileResolverService implements ITerminalProfileResol async getDefaultShell(options: IShellLaunchConfigResolveOptions): Promise { return '/default'; } async getDefaultShellArgs(options: IShellLaunchConfigResolveOptions): Promise { return []; } async getShellEnvironment(): Promise { return process.env; } - getSafeConfigValue(key: string, os: OperatingSystem): unknown | undefined { return undefined; } - getSafeConfigValueFullKey(key: string): unknown | undefined { return undefined; } } export class TestLocalTerminalService implements ILocalTerminalService {