Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
Fixing problem where profile switcher settings were sync'ed across pr…
Browse files Browse the repository at this point in the history
…ofiles
  • Loading branch information
aaronpowell committed Jul 3, 2019
1 parent 4416d2e commit 313f078
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 15 deletions.
42 changes: 29 additions & 13 deletions src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,37 @@ class Config {
public setLiveShareProfile(profile: string) {
let config = this.getConfig();

return config.update(ConfigLiveShareProfileKey, profile, vscode.ConfigurationTarget.Global);
return config.update(
ConfigLiveShareProfileKey,
profile,
vscode.ConfigurationTarget.Global
);
}

public async setCurrentProfile(profile: string) {
if (this.context) {
const previousProfile = this.context.globalState.get<string>(ContextSettingCurrentProfile);
const previousProfile = this.context.globalState.get<string>(
ContextSettingCurrentProfile
);
this.setPreviousProfile(previousProfile);

await this.context.globalState.update(ContextSettingCurrentProfile, profile);
await this.context.globalState.update(
ContextSettingCurrentProfile,
profile
);
}
}

public getPreviousProfile(): string | undefined {
return this.context && this.context.globalState.get(ContextSettingPreviousProfile);
return (
this.context &&
this.context.globalState.get(ContextSettingPreviousProfile)
);
}

public setPreviousProfile(profile: string | undefined) {
this.context && this.context.globalState.update(ContextSettingPreviousProfile, profile);
this.context &&
this.context.globalState.update(ContextSettingPreviousProfile, profile);
}

public getProfiles() {
Expand Down Expand Up @@ -107,14 +120,17 @@ class Config {
}

public addProfileSettings(profile: string, settings: Settings) {
// We don't want to save profile info in the profile storage
if (settings[`${ConfigKey}:${ConfigProfilesKey}`]) {
delete settings[`${ConfigKey}:${ConfigProfilesKey}`];
}

if (settings[`${ConfigKey}:${ConfigStorageKey}`]) {
delete settings[`${ConfigKey}:${ConfigStorageKey}`];
}
const deleteSetting = (key: string) => {
if (`${ConfigKey}.${key}` in settings) {
delete settings[`${ConfigKey}.${key}`];
}
};

deleteSetting(ConfigProfilesKey);
deleteSetting(ConfigStorageKey);
deleteSetting(ConfigExtensionsKey);
deleteSetting(ConfigExtensionsIgnoreKey);
deleteSetting(ConfigLiveShareProfileKey);

let storage = this.getStorage();
storage[profile] = settings;
Expand Down
27 changes: 26 additions & 1 deletion src/test/saveProfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
ConfigKey,
ConfigProfilesKey,
ConfigStorageKey,
ConfigExtensionsKey
ConfigExtensionsKey,
ConfigLiveShareProfileKey
} from "../constants";
import Config from "../services/config";
import { ExtensionInfo } from "../services/extensions";
Expand Down Expand Up @@ -34,6 +35,13 @@ suite("save profile", () => {
suite("settings", () => {
const expectedProfileSettings = { foo: "bar" };
const expectedUpdatedProfileSettings = { foo: "baz", a: "b" };
const profileSwitcherSettings = {
[`${ConfigKey}.${ConfigProfilesKey}`]: [],
[`${ConfigKey}.${ConfigStorageKey}`]: {},
[`${ConfigKey}.${ConfigExtensionsKey}`]: {},
[`${ConfigKey}.${ConfigExtensionsKey}`]: [],
[`${ConfigKey}.${ConfigLiveShareProfileKey}`]: ""
};

teardown(async () => {
let config = vscode.workspace.getConfiguration(ConfigKey);
Expand Down Expand Up @@ -72,6 +80,23 @@ suite("save profile", () => {
let settings = config.getProfileSettings(expectedProfileName);
assert.deepEqual(settings, expectedUpdatedProfileSettings);
});

test("saving profile doesn't include profileSwitcher settings", async () => {
var config = new Config();

await config.addProfileSettings(
expectedProfileName,
Object.assign({}, expectedProfileSettings, profileSwitcherSettings)
);

let settings = config.getProfileSettings(expectedProfileName);
Object.keys(profileSwitcherSettings).forEach(key =>
assert.isUndefined(
settings[key],
`The key "${key}" should have been removed`
)
);
});
});

suite("extensions", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/selectProfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ suite("select profile", () => {
assert.deepEqual(settings, expectedProfileSettings);
});

test("storage contains the expected profile settings", () => {
test("storage contains the expected profile extensions", () => {
let config = new Config();

let extensions = config.getProfileExtensions(expectedProfileName);
Expand Down

0 comments on commit 313f078

Please # to comment.