Skip to content

Commit

Permalink
#156144 Fix gaps in updating the profile
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jul 17, 2023
1 parent 31f7511 commit 024a83d
Show file tree
Hide file tree
Showing 22 changed files with 294 additions and 287 deletions.
2 changes: 1 addition & 1 deletion src/vs/platform/userDataProfile/common/userDataProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf
throw new Error(`Profile '${profileToUpdate.name}' does not exist`);
}

profile = toUserDataProfile(profile.id, options.name ?? profile.name, profile.location, this.profilesCacheHome, { shortName: options.shortName ?? profile.shortName, transient: options.transient ?? profile.isTransient, useDefaultFlags: options.useDefaultFlags ?? profile.useDefaultFlags });
profile = toUserDataProfile(profile.id, options.name ?? profile.name, profile.location, this.profilesCacheHome, { shortName: options.shortName ?? profile.shortName, transient: options.transient ?? profile.isTransient, useDefaultFlags: options.useDefaultFlags ?? profile.useDefaultFlags }, this.defaultProfile);
this.updateProfiles([], [], [profile]);

return profile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,13 @@ suite('UserDataProfileService (Common)', () => {
assert.strictEqual(profile.extensionsResource.toString(), testObject.defaultProfile.extensionsResource.toString());
});

test('update profile using default profile for keybindings', async () => {
let profile = await testObject.createNamedProfile('name');
profile = await testObject.updateProfile(profile, { useDefaultFlags: { keybindings: true } });

assert.strictEqual(profile.isDefault, false);
assert.deepStrictEqual(profile.useDefaultFlags, { keybindings: true });
assert.strictEqual(profile.keybindingsResource.toString(), testObject.defaultProfile.keybindingsResource.toString());
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
import { equals } from 'vs/base/common/objects';
import { IUserDataProfile, UseDefaultProfileFlags } from 'vs/platform/userDataProfile/common/userDataProfile';
import { ISyncUserDataProfile } from 'vs/platform/userDataSync/common/userDataSync';

interface IRelaxedMergeResult {
Expand All @@ -17,6 +18,7 @@ interface IUserDataProfileInfo {
readonly id: string;
readonly name: string;
readonly shortName?: string;
readonly useDefaultFlags?: UseDefaultProfileFlags;
}

export function merge(local: IUserDataProfile[], remote: ISyncUserDataProfile[] | null, lastSync: ISyncUserDataProfile[] | null, ignored: string[]): IMergeResult {
Expand Down Expand Up @@ -117,14 +119,15 @@ function compare(from: IUserDataProfileInfo[] | null, to: IUserDataProfileInfo[]
const removed = fromKeys.filter(key => !toKeys.includes(key));
const updated: string[] = [];

for (const { id, name, shortName } of from) {
for (const { id, name, shortName, useDefaultFlags } of from) {
if (removed.includes(id)) {
continue;
}
const toProfile = to.find(p => p.id === id);
if (!toProfile
|| toProfile.name !== name
|| toProfile.shortName !== shortName
|| !equals(toProfile.useDefaultFlags, useDefaultFlags)
) {
updated.push(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i
if (localProfile) {
promises.push((async () => {
this.logService.trace(`${this.syncResourceLogLabel}: Updating '${profile.name}' profile...`);
await this.userDataProfilesService.updateProfile(localProfile, { name: profile.name, shortName: profile.shortName });
await this.userDataProfilesService.updateProfile(localProfile, { name: profile.name, shortName: profile.shortName, useDefaultFlags: profile.useDefaultFlags });
this.logService.info(`${this.syncResourceLogLabel}: Updated profile '${profile.name}'.`);
})());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ suite('UserDataProfilesManifestMerge', () => {
toUserDataProfile('5', '5', URI.file('5'), URI.file('cache')),
toUserDataProfile('6', '6', URI.file('6'), URI.file('cache')),
toUserDataProfile('8', '8', URI.file('8'), URI.file('cache')),
toUserDataProfile('10', '10', URI.file('8'), URI.file('cache'), { useDefaultFlags: { tasks: true } }),
toUserDataProfile('11', '11', URI.file('1'), URI.file('cache'), { useDefaultFlags: { keybindings: true } }),
];
const base: ISyncUserDataProfile[] = [
{ id: '1', name: '1', collection: '1' },
Expand All @@ -79,6 +81,8 @@ suite('UserDataProfilesManifestMerge', () => {
{ id: '4', name: '4', collection: '4' },
{ id: '5', name: '5', collection: '5' },
{ id: '6', name: '6', collection: '6' },
{ id: '10', name: '10', collection: '10', useDefaultFlags: { tasks: true } },
{ id: '11', name: '11', collection: '11' },
];
const remoteProfiles: ISyncUserDataProfile[] = [
{ id: '1', name: '1', collection: '1' },
Expand All @@ -87,15 +91,18 @@ suite('UserDataProfilesManifestMerge', () => {
{ id: '4', name: 'changed remote', collection: '4' },
{ id: '5', name: '5', collection: '5' },
{ id: '7', name: '7', collection: '7' },
{ id: '9', name: '9', collection: '9', useDefaultFlags: { snippets: true } },
{ id: '10', name: '10', collection: '10' },
{ id: '11', name: '11', collection: '11' },
];

const actual = merge(localProfiles, remoteProfiles, base, []);

assert.deepStrictEqual(actual.local.added, [remoteProfiles[5]]);
assert.deepStrictEqual(actual.local.added, [remoteProfiles[5], remoteProfiles[6]]);
assert.deepStrictEqual(actual.local.removed, [localProfiles[4]]);
assert.deepStrictEqual(actual.local.updated, [remoteProfiles[2], remoteProfiles[3]]);
assert.deepStrictEqual(actual.local.updated, [remoteProfiles[2], remoteProfiles[3], remoteProfiles[7]]);
assert.deepStrictEqual(actual.remote?.added, [localProfiles[5]]);
assert.deepStrictEqual(actual.remote?.updated, [localProfiles[0]]);
assert.deepStrictEqual(actual.remote?.updated, [localProfiles[0], localProfiles[7]]);
assert.deepStrictEqual(actual.remote?.removed, [remoteProfiles[1]]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,47 @@ suite('UserDataProfilesManifestSync', () => {
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
});

test('sync profile when the profile is updated to use default profile locally', async () => {
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
await client2.sync();

await testObject.sync(await testClient.getResourceManifest());

const profile = testClient.instantiationService.get(IUserDataProfilesService).profiles.find(p => p.id === '1')!;
testClient.instantiationService.get(IUserDataProfilesService).updateProfile(profile, { useDefaultFlags: { keybindings: true } });

await testObject.sync(await testClient.getResourceManifest());
assert.strictEqual(testObject.status, SyncStatus.Idle);
assert.deepStrictEqual(testObject.conflicts.conflicts, []);

const { content } = await testClient.read(testObject.resource);
assert.ok(content !== null);
const actual = parseRemoteProfiles(content!);
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', useDefaultFlags: { keybindings: true } }]);
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
});

test('sync profile when the profile is updated to use default profile remotely', async () => {
const profile = await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
await client2.sync();

await testObject.sync(await testClient.getResourceManifest());

client2.instantiationService.get(IUserDataProfilesService).updateProfile(profile, { useDefaultFlags: { keybindings: true } });
await client2.sync();

await testObject.sync(await testClient.getResourceManifest());
assert.strictEqual(testObject.status, SyncStatus.Idle);
assert.deepStrictEqual(testObject.conflicts.conflicts, []);

const { content } = await testClient.read(testObject.resource);
assert.ok(content !== null);
const actual = parseRemoteProfiles(content!);
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', useDefaultFlags: { keybindings: true } }]);

assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
});

function parseRemoteProfiles(content: string): ISyncUserDataProfile[] {
const syncData: ISyncData = JSON.parse(content);
return JSON.parse(syncData.content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { EventType, addDisposableListener, EventHelper, append, $, clearNode, hi
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';
import { Action, IAction, Separator, SubmenuAction, toAction } from 'vs/base/common/actions';
import { Event } from 'vs/base/common/event';
import { KeyCode } from 'vs/base/common/keyCodes';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { IMenuService, MenuId, IMenu, registerAction2, Action2, IAction2Options } from 'vs/platform/actions/common/actions';
Expand Down Expand Up @@ -485,7 +484,7 @@ export class GlobalActivityActionViewItem extends MenuActivityActionViewItem {
@IKeybindingService keybindingService: IKeybindingService,
) {
super(MenuId.GlobalActivity, action, contextMenuActionsProvider, true, colors, activityHoverOptions, themeService, hoverService, menuService, contextMenuService, contextKeyService, configurationService, environmentService, keybindingService);
this._register(Event.any(this.userDataProfileService.onDidUpdateCurrentProfile, this.userDataProfileService.onDidChangeCurrentProfile)(() => this.updateProfileBadge()));
this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => this.updateProfileBadge()));
}

override render(container: HTMLElement): void {
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/browser/parts/titlebar/windowTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export class WindowTitle extends Disposable {
this._register(this.contextService.onDidChangeWorkspaceName(() => this.titleUpdater.schedule()));
this._register(this.labelService.onDidChangeFormatters(() => this.titleUpdater.schedule()));
this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => this.titleUpdater.schedule()));
this._register(this.userDataProfileService.onDidUpdateCurrentProfile(() => this.titleUpdater.schedule()));
}

private onConfigurationChanged(event: IConfigurationChangeEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import { IStringDictionary } from 'vs/base/common/collections';
import { CONTEXT_KEYBINDINGS_EDITOR } from 'vs/workbench/contrib/preferences/common/preferences';
import { DeprecatedExtensionsChecker } from 'vs/workbench/contrib/extensions/browser/deprecatedExtensionsChecker';
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';

// Singletons
registerSingleton(IExtensionsWorkbenchService, ExtensionsWorkbenchService, InstantiationType.Eager /* Auto updates extensions */);
Expand Down Expand Up @@ -473,7 +472,6 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IDialogService private readonly dialogService: IDialogService,
@ICommandService private readonly commandService: ICommandService,
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
) {
super();
const hasGalleryContext = CONTEXT_HAS_GALLERY.bindTo(contextKeyService);
Expand Down Expand Up @@ -517,31 +515,22 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi

// Global actions
private registerGlobalActions(): void {
const getTitle = (title: string) => !this.userDataProfileService.currentProfile.isDefault && this.userDataProfileService.currentProfile.useDefaultFlags?.extensions
? `${title} (${localize('default profile', "Default Profile")})`
: title;
const registerOpenExtensionsActionDisposables = this._register(new DisposableStore());
const registerOpenExtensionsAction = () => {
registerOpenExtensionsActionDisposables.clear();
registerOpenExtensionsActionDisposables.add(MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {
command: {
id: VIEWLET_ID,
title: getTitle(localize({ key: 'miPreferencesExtensions', comment: ['&& denotes a mnemonic'] }, "&&Extensions"))
},
group: '2_configuration',
order: 3
}));
registerOpenExtensionsActionDisposables.add(MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
command: {
id: VIEWLET_ID,
title: getTitle(localize('showExtensions', "Extensions"))
},
group: '2_configuration',
order: 3
}));
};
registerOpenExtensionsAction();
this._register(Event.any(this.userDataProfileService.onDidChangeCurrentProfile, this.userDataProfileService.onDidUpdateCurrentProfile)(() => registerOpenExtensionsAction()));
this._register(MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {
command: {
id: VIEWLET_ID,
title: localize({ key: 'miPreferencesExtensions', comment: ['&& denotes a mnemonic'] }, "&&Extensions")
},
group: '2_configuration',
order: 3
}));
this._register(MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
command: {
id: VIEWLET_ID,
title: localize('showExtensions', "Extensions")
},
group: '2_configuration',
order: 3
}));

this.registerExtensionAction({
id: 'workbench.extensions.action.installExtensions',
Expand Down
Loading

0 comments on commit 024a83d

Please sign in to comment.