diff --git a/src/session.ts b/src/session.ts index a65484ecc1..ec2f3c0730 100644 --- a/src/session.ts +++ b/src/session.ts @@ -126,6 +126,8 @@ export class SessionManager implements Middleware { this.promptPowerShellExeSettingsCleanup(); + this.migrateWhitespaceAroundPipeSetting(); + try { let powerShellExeDetails; if (this.sessionSettings.powerShellDefaultVersion) { @@ -320,6 +322,18 @@ export class SessionManager implements Middleware { return resolvedCodeLens; } + // During preview, populate a new setting value but not remove the old value. + // TODO: When the next stable extension releases, then the old value can be safely removed. Tracked in this issue: https://github.com/PowerShell/vscode-powershell/issues/2693 + private async migrateWhitespaceAroundPipeSetting() { + const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId); + const deprecatedSetting = 'codeFormatting.whitespaceAroundPipe' + if (configuration.has(deprecatedSetting) && !configuration.has('codeFormatting.addWhitespaceAroundPipe')) { + const configurationTarget = await Settings.getEffectiveConfigurationTarget(deprecatedSetting); + const value = configuration.get(deprecatedSetting, configurationTarget) + await Settings.change('codeFormatting.addWhitespaceAroundPipe', value, configurationTarget); + } + } + private async promptPowerShellExeSettingsCleanup() { if (this.sessionSettings.powerShellExePath) { let warningMessage = "The 'powerShell.powerShellExePath' setting is no longer used. "; diff --git a/src/settings.ts b/src/settings.ts index a5f4cbd51e..5ed9fb6fdb 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -245,12 +245,32 @@ export function load(): ISettings { }; } -export async function change(settingName: string, newValue: any, global: boolean = false): Promise { - const configuration: vscode.WorkspaceConfiguration = - vscode.workspace.getConfiguration( - utils.PowerShellLanguageId); +// Get the ConfigurationTarget (read: scope) of where the *effective* setting value comes from +export async function getEffectiveConfigurationTarget(settingName: string): Promise { + const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId); + + const detail = configuration.inspect(settingName); + let configurationTarget = null; + if (typeof detail.workspaceFolderValue !== "undefined") { + configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder; + } + else if (typeof detail.workspaceValue !== "undefined") { + configurationTarget = vscode.ConfigurationTarget.Workspace; + } + else if (typeof detail.globalValue !== "undefined") { + configurationTarget = vscode.ConfigurationTarget.Global; + } + return configurationTarget; +} + +export async function change( + settingName: string, + newValue: any, + configurationTarget?: vscode.ConfigurationTarget | boolean): Promise { + + const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId); - await configuration.update(settingName, newValue, global); + await configuration.update(settingName, newValue, configurationTarget); } function getWorkspaceSettingsWithDefaults(