Skip to content

Commit 4db9e34

Browse files
bergmeisterChristoph Bergmeister
and
Christoph Bergmeister
authored
🔧🚗 Migrate setting value of codeFormatting.whitespaceAroundPipe (if present) to new setting codeFormatting.addWhitespaceAroundPipe automatically. (#2689)
* Migrate setting value of codeFormatting.whitespaceAroundPipe to new setting codeFormatting.addWhitespaceAroundPipe automatically. * fix code analysis warnings * add comment to getConfigurationTarget and rename it to getEffectiveConfigurationTarget * try use quotes around undefined to see if it fixes codacy warning * Update src/session.ts Co-authored-by: Christoph Bergmeister <[email protected]>
1 parent 0a1dab2 commit 4db9e34

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

‎src/session.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export class SessionManager implements Middleware {
123123

124124
this.promptPowerShellExeSettingsCleanup();
125125

126+
this.migrateWhitespaceAroundPipeSetting();
127+
126128
try {
127129
let powerShellExeDetails;
128130
if (this.sessionSettings.powerShellDefaultVersion) {
@@ -317,6 +319,18 @@ export class SessionManager implements Middleware {
317319
return resolvedCodeLens;
318320
}
319321

322+
// During preview, populate a new setting value but not remove the old value.
323+
// 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
324+
private async migrateWhitespaceAroundPipeSetting() {
325+
const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId);
326+
const deprecatedSetting = 'codeFormatting.whitespaceAroundPipe'
327+
if (configuration.has(deprecatedSetting) && !configuration.has('codeFormatting.addWhitespaceAroundPipe')) {
328+
const configurationTarget = await Settings.getEffectiveConfigurationTarget(deprecatedSetting);
329+
const value = configuration.get(deprecatedSetting, configurationTarget)
330+
await Settings.change('codeFormatting.addWhitespaceAroundPipe', value, configurationTarget);
331+
}
332+
}
333+
320334
private async promptPowerShellExeSettingsCleanup() {
321335
if (this.sessionSettings.powerShellExePath) {
322336
let warningMessage = "The 'powerShell.powerShellExePath' setting is no longer used. ";

‎src/settings.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,32 @@ export function load(): ISettings {
245245
};
246246
}
247247

248-
export async function change(settingName: string, newValue: any, global: boolean = false): Promise<void> {
249-
const configuration: vscode.WorkspaceConfiguration =
250-
vscode.workspace.getConfiguration(
251-
utils.PowerShellLanguageId);
248+
// Get the ConfigurationTarget (read: scope) of where the *effective* setting value comes from
249+
export async function getEffectiveConfigurationTarget(settingName: string): Promise<vscode.ConfigurationTarget> {
250+
const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId);
251+
252+
const detail = configuration.inspect(settingName);
253+
let configurationTarget = null;
254+
if (typeof detail.workspaceFolderValue !== "undefined") {
255+
configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder;
256+
}
257+
else if (typeof detail.workspaceValue !== "undefined") {
258+
configurationTarget = vscode.ConfigurationTarget.Workspace;
259+
}
260+
else if (typeof detail.globalValue !== "undefined") {
261+
configurationTarget = vscode.ConfigurationTarget.Global;
262+
}
263+
return configurationTarget;
264+
}
265+
266+
export async function change(
267+
settingName: string,
268+
newValue: any,
269+
configurationTarget?: vscode.ConfigurationTarget | boolean): Promise<void> {
270+
271+
const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId);
252272

253-
await configuration.update(settingName, newValue, global);
273+
await configuration.update(settingName, newValue, configurationTarget);
254274
}
255275

256276
function getWorkspaceSettingsWithDefaults<TSettings>(

0 commit comments

Comments
 (0)