Skip to content

Commit e035f69

Browse files
backport: fix change session by moving to async/await promise (PowerShell#1927)
1 parent 0127ee2 commit e035f69

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/settings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ export function load(): ISettings {
186186
};
187187
}
188188

189-
export function change(settingName: string, newValue: any, global: boolean = false): Thenable<void> {
189+
export async function change(settingName: string, newValue: any, global: boolean = false): Promise<void> {
190190
const configuration: vscode.WorkspaceConfiguration =
191191
vscode.workspace.getConfiguration(
192192
utils.PowerShellLanguageId);
193193

194-
return configuration.update(settingName, newValue, global);
194+
await configuration.update(settingName, newValue, global);
195195
}
196196

197197
function getWorkspaceSettingsWithDefaults<TSettings>(

test/settings.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
import * as assert from "assert";
6+
import Settings = require("../src/settings");
7+
8+
suite("Settings module", () => {
9+
test("Settings load without error", () => {
10+
assert.doesNotThrow(Settings.load);
11+
});
12+
13+
test("Settings update correctly", async () => {
14+
// then syntax
15+
Settings.change("powerShellExePath", "dummypath1", false).then(() =>
16+
assert.strictEqual(Settings.load().powerShellExePath, "dummypath1"));
17+
18+
// async/await syntax
19+
await Settings.change("powerShellExePath", "dummypath2", false);
20+
assert.strictEqual(Settings.load().powerShellExePath, "dummypath2");
21+
});
22+
});

0 commit comments

Comments
 (0)