From 4e6e6b9e44d0d15834726decbb7b71ba85d953bb Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 10 May 2020 14:58:34 +0100 Subject: [PATCH 1/5] Migrate setting value of codeFormatting.whitespaceAroundPipe to new setting codeFormatting.addWhitespaceAroundPipe automatically. --- src/session.ts | 14 ++++++++++++++ src/settings.ts | 28 +++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/session.ts b/src/session.ts index a65484ecc1..21f5c4a2b3 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. + // When the PowerShell extension releases the RTM version, then the old value can be safely removed. + 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.getConfigurationTarget(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..655e927354 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -245,12 +245,30 @@ 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); +export async function getConfigurationTarget(settingName: string): Promise { + const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId); + + const detail = configuration.inspect(settingName); + let configurationTarget = null; + if (detail.workspaceFolderValue !== undefined) { + configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder + } + else if (detail.workspaceValue !== undefined) { + configurationTarget = vscode.ConfigurationTarget.Workspace + } + else if (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( From 09dd00c77a3ad129c1cebb7ce91bcfd9b28b98db Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 10 May 2020 15:40:22 +0100 Subject: [PATCH 2/5] fix code analysis warnings --- src/settings.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/settings.ts b/src/settings.ts index 655e927354..08c910f6ba 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -250,14 +250,14 @@ export async function getConfigurationTarget(settingName: string): Promise Date: Sun, 10 May 2020 20:15:53 +0100 Subject: [PATCH 3/5] add comment to getConfigurationTarget and rename it to getEffectiveConfigurationTarget --- src/session.ts | 2 +- src/settings.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/session.ts b/src/session.ts index 21f5c4a2b3..a40015d17c 100644 --- a/src/session.ts +++ b/src/session.ts @@ -328,7 +328,7 @@ export class SessionManager implements Middleware { const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId); const deprecatedSetting = 'codeFormatting.whitespaceAroundPipe' if (configuration.has(deprecatedSetting) && !configuration.has('codeFormatting.addWhitespaceAroundPipe')) { - const configurationTarget = await Settings.getConfigurationTarget(deprecatedSetting); + const configurationTarget = await Settings.getEffectiveConfigurationTarget(deprecatedSetting); const value = configuration.get(deprecatedSetting, configurationTarget) await Settings.change('codeFormatting.addWhitespaceAroundPipe', value, configurationTarget); } diff --git a/src/settings.ts b/src/settings.ts index 08c910f6ba..58ad5c10b2 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -245,7 +245,8 @@ export function load(): ISettings { }; } -export async function getConfigurationTarget(settingName: string): Promise { +// 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); From c69d197d441f2fac7db4464dcf04578b4a7dde4f Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 10 May 2020 20:40:45 +0100 Subject: [PATCH 4/5] try use quotes around undefined to see if it fixes codacy warning --- src/settings.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/settings.ts b/src/settings.ts index 58ad5c10b2..5ed9fb6fdb 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -251,13 +251,13 @@ export async function getEffectiveConfigurationTarget(settingName: string): Prom const detail = configuration.inspect(settingName); let configurationTarget = null; - if (typeof detail.workspaceFolderValue !== undefined) { + if (typeof detail.workspaceFolderValue !== "undefined") { configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder; } - else if (typeof detail.workspaceValue !== undefined) { + else if (typeof detail.workspaceValue !== "undefined") { configurationTarget = vscode.ConfigurationTarget.Workspace; } - else if (typeof detail.globalValue !== undefined) { + else if (typeof detail.globalValue !== "undefined") { configurationTarget = vscode.ConfigurationTarget.Global; } return configurationTarget; @@ -265,7 +265,8 @@ export async function getEffectiveConfigurationTarget(settingName: string): Prom export async function change( settingName: string, - newValue: any, configurationTarget?: vscode.ConfigurationTarget | boolean): Promise { + newValue: any, + configurationTarget?: vscode.ConfigurationTarget | boolean): Promise { const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId); From 10185d2ad803f9ed34ddd809c3726d5fdd72c571 Mon Sep 17 00:00:00 2001 From: "Christoph Bergmeister [MVP]" Date: Tue, 12 May 2020 15:45:11 +0100 Subject: [PATCH 5/5] Update src/session.ts --- src/session.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/session.ts b/src/session.ts index a40015d17c..ec2f3c0730 100644 --- a/src/session.ts +++ b/src/session.ts @@ -323,7 +323,7 @@ export class SessionManager implements Middleware { } // During preview, populate a new setting value but not remove the old value. - // When the PowerShell extension releases the RTM version, then the old value can be safely removed. + // 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'