Skip to content

Commit a201c73

Browse files
authored
cleanup: remove unused code (microsoft#185938)
1 parent a572746 commit a201c73

File tree

16 files changed

+63
-123
lines changed

16 files changed

+63
-123
lines changed

src/vs/platform/storage/common/storage.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -623,32 +623,22 @@ export abstract class AbstractStorageService extends Disposable implements IStor
623623
return true;
624624
}
625625

626-
protected switchData(oldStorage: Map<string, string>, newStorage: IStorage, scope: StorageScope, preserveData: boolean): void {
626+
protected switchData(oldStorage: Map<string, string>, newStorage: IStorage, scope: StorageScope): void {
627627
this.withPausedEmitters(() => {
628-
629-
// Copy over previous keys if `preserveData`
630-
if (preserveData) {
631-
for (const [key, value] of oldStorage) {
632-
newStorage.set(key, value, true);
628+
// Signal storage keys that have changed
629+
const handledkeys = new Set<string>();
630+
for (const [key, oldValue] of oldStorage) {
631+
handledkeys.add(key);
632+
633+
const newValue = newStorage.get(key);
634+
if (newValue !== oldValue) {
635+
this.emitDidChangeValue(scope, { key, external: true });
633636
}
634637
}
635638

636-
// Otherwise signal storage keys that have changed
637-
else {
638-
const handledkeys = new Set<string>();
639-
for (const [key, oldValue] of oldStorage) {
640-
handledkeys.add(key);
641-
642-
const newValue = newStorage.get(key);
643-
if (newValue !== oldValue) {
644-
this.emitDidChangeValue(scope, { key, external: true });
645-
}
646-
}
647-
648-
for (const [key] of newStorage.items) {
649-
if (!handledkeys.has(key)) {
650-
this.emitDidChangeValue(scope, { key, external: true });
651-
}
639+
for (const [key] of newStorage.items) {
640+
if (!handledkeys.has(key)) {
641+
this.emitDidChangeValue(scope, { key, external: true });
652642
}
653643
}
654644
});

src/vs/platform/storage/common/storageService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class RemoteStorageService extends AbstractStorageService {
141141
]);
142142
}
143143

144-
protected async switchToProfile(toProfile: IUserDataProfile, preserveData: boolean): Promise<void> {
144+
protected async switchToProfile(toProfile: IUserDataProfile): Promise<void> {
145145
if (!this.canSwitchProfile(this.profileStorageProfile, toProfile)) {
146146
return;
147147
}
@@ -160,7 +160,7 @@ export class RemoteStorageService extends AbstractStorageService {
160160
await this.profileStorage.init();
161161

162162
// Handle data switch and eventing
163-
this.switchData(oldItems, this.profileStorage, StorageScope.PROFILE, preserveData);
163+
this.switchData(oldItems, this.profileStorage, StorageScope.PROFILE);
164164
}
165165

166166
protected async switchToWorkspace(toWorkspace: IAnyWorkspaceIdentifier, preserveData: boolean): Promise<void> {
@@ -175,7 +175,7 @@ export class RemoteStorageService extends AbstractStorageService {
175175
await this.workspaceStorage.init();
176176

177177
// Handle data switch and eventing
178-
this.switchData(oldItems, this.workspaceStorage, StorageScope.WORKSPACE, preserveData);
178+
this.switchData(oldItems, this.workspaceStorage, StorageScope.WORKSPACE);
179179
}
180180

181181
hasScope(scope: IAnyWorkspaceIdentifier | IUserDataProfile): boolean {

src/vs/workbench/contrib/snippets/browser/snippetsService.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,6 @@ export class SnippetsService implements ISnippetsService {
454454
};
455455
this._disposables.add(disposables);
456456
this._disposables.add(this._userDataProfileService.onDidChangeCurrentProfile(e => e.join((async () => {
457-
if (e.preserveData) {
458-
await this._fileService.copy(e.previous.snippetsHome, e.profile.snippetsHome);
459-
}
460457
this._pendingWork.push(updateUserSnippets());
461458
})())));
462459
await updateUserSnippets();

src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
457457
if (fromExisting) {
458458
await this.userDataProfileImportExportService.createFromCurrentProfile(name);
459459
} else {
460-
await this.userDataProfileManagementService.createAndEnterProfile(name, undefined, false);
460+
await this.userDataProfileManagementService.createAndEnterProfile(name);
461461
}
462462
} catch (error) {
463463
this.notificationService.error(error);

src/vs/workbench/services/configuration/browser/configurationService.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { WorkspaceConfiguration, FolderConfiguration, RemoteUserConfiguration, U
2525
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
2626
import { mark } from 'vs/base/common/performance';
2727
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
28-
import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
28+
import { IFileService } from 'vs/platform/files/common/files';
2929
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
3030
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
3131
import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
@@ -42,8 +42,6 @@ import { localize } from 'vs/nls';
4242
import { DidChangeUserDataProfileEvent, IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
4343
import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy';
4444
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
45-
import { updateIgnoredSettings } from 'vs/platform/userDataSync/common/settingsMerge';
46-
import { VSBuffer } from 'vs/base/common/buffer';
4745
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
4846
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
4947

@@ -709,12 +707,6 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
709707

710708
private onUserDataProfileChanged(e: DidChangeUserDataProfileEvent): void {
711709
e.join((async () => {
712-
if (e.preserveData) {
713-
await Promise.all([
714-
this.copyProfileSettings(e.previous.settingsResource, e.profile.settingsResource),
715-
this.copyProfileTasks(e.previous.tasksResource, e.profile.tasksResource)
716-
]);
717-
}
718710
const promises: Promise<ConfigurationModel>[] = [];
719711
promises.push(this.localUserConfiguration.reset(e.profile.settingsResource, e.profile.tasksResource, getLocalUserConfigurationScopes(e.profile, !!this.remoteUserConfiguration)));
720712
if (e.previous.isDefault !== e.profile.isDefault) {
@@ -728,30 +720,6 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
728720
})());
729721
}
730722

731-
private async copyProfileSettings(from: URI, to: URI): Promise<void> {
732-
let fromContent: string | undefined;
733-
try {
734-
fromContent = (await this.fileService.readFile(from)).value.toString();
735-
} catch (error) {
736-
if ((<FileOperationError>error).fileOperationResult !== FileOperationResult.FILE_NOT_FOUND) {
737-
throw error;
738-
}
739-
}
740-
if (!fromContent) {
741-
return;
742-
}
743-
const allSettings = Registry.as<IConfigurationRegistry>(Extensions.Configuration).getConfigurationProperties();
744-
const applicationSettings = Object.keys(allSettings).filter(key => allSettings[key]?.scope === ConfigurationScope.APPLICATION);
745-
const toContent = updateIgnoredSettings(fromContent, '{}', applicationSettings, {});
746-
await this.fileService.writeFile(to, VSBuffer.fromString(toContent));
747-
}
748-
749-
private async copyProfileTasks(from: URI, to: URI): Promise<void> {
750-
if (await this.fileService.exists(from)) {
751-
await this.fileService.copy(from, to);
752-
}
753-
}
754-
755723
private onDefaultConfigurationChanged(configurationModel: ConfigurationModel, properties?: string[]): void {
756724
if (this.workspace) {
757725
const previousData = this._configuration.toData();

src/vs/workbench/services/configuration/test/browser/configurationService.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ suite('WorkspaceConfigurationService - Profiles', () => {
16881688
await testObject.reloadConfiguration();
16891689

16901690
const promise = Event.toPromise(testObject.onDidChangeConfiguration);
1691-
await userDataProfileService.updateCurrentProfile(instantiationService.get(IUserDataProfilesService).defaultProfile, false);
1691+
await userDataProfileService.updateCurrentProfile(instantiationService.get(IUserDataProfilesService).defaultProfile);
16921692

16931693
const changeEvent = await promise;
16941694
assert.deepStrictEqual([...changeEvent.affectedKeys], ['configurationService.profiles.testSetting']);
@@ -1704,7 +1704,7 @@ suite('WorkspaceConfigurationService - Profiles', () => {
17041704
const profile = toUserDataProfile('custom2', 'custom2', joinPath(environmentService.userRoamingDataHome, 'profiles', 'custom2'), joinPath(environmentService.cacheHome, 'profilesCache'));
17051705
await fileService.writeFile(profile.settingsResource, VSBuffer.fromString('{ "configurationService.profiles.applicationSetting": "profileValue2", "configurationService.profiles.testSetting": "profileValue2" }'));
17061706
const promise = Event.toPromise(testObject.onDidChangeConfiguration);
1707-
await userDataProfileService.updateCurrentProfile(profile, false);
1707+
await userDataProfileService.updateCurrentProfile(profile);
17081708

17091709
const changeEvent = await promise;
17101710
assert.deepStrictEqual([...changeEvent.affectedKeys], ['configurationService.profiles.testSetting']);

src/vs/workbench/services/extensionManagement/common/extensionManagementChannelClient.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,31 +93,26 @@ export abstract class ProfileAwareExtensionManagementChannelClient extends BaseE
9393
return;
9494
}
9595

96-
const eventData = await this.switchExtensionsProfile(previousProfileLocation, currentProfileLocation, e.preserveData);
96+
const eventData = await this.switchExtensionsProfile(previousProfileLocation, currentProfileLocation);
9797
this._onDidChangeProfile.fire(eventData);
9898
}
9999

100-
protected async switchExtensionsProfile(previousProfileLocation: URI, currentProfileLocation: URI, preserve: boolean | ExtensionIdentifier[]): Promise<DidChangeProfileEvent> {
101-
if (preserve === true) {
102-
await this.copyExtensions(previousProfileLocation, currentProfileLocation);
103-
return { added: [], removed: [] };
104-
} else {
105-
const oldExtensions = await this.getInstalled(ExtensionType.User, previousProfileLocation);
106-
const newExtensions = await this.getInstalled(ExtensionType.User, currentProfileLocation);
107-
if (Array.isArray(preserve)) {
108-
const extensionsToInstall: IExtensionIdentifier[] = [];
109-
for (const extension of oldExtensions) {
110-
if (preserve.some(id => ExtensionIdentifier.equals(extension.identifier.id, id)) &&
111-
!newExtensions.some(e => ExtensionIdentifier.equals(e.identifier.id, extension.identifier.id))) {
112-
extensionsToInstall.push(extension.identifier);
113-
}
114-
}
115-
if (extensionsToInstall.length) {
116-
await this.installExtensionsFromProfile(extensionsToInstall, previousProfileLocation, currentProfileLocation);
100+
protected async switchExtensionsProfile(previousProfileLocation: URI, currentProfileLocation: URI, preserveExtensions?: ExtensionIdentifier[]): Promise<DidChangeProfileEvent> {
101+
const oldExtensions = await this.getInstalled(ExtensionType.User, previousProfileLocation);
102+
const newExtensions = await this.getInstalled(ExtensionType.User, currentProfileLocation);
103+
if (preserveExtensions?.length) {
104+
const extensionsToInstall: IExtensionIdentifier[] = [];
105+
for (const extension of oldExtensions) {
106+
if (preserveExtensions.some(id => ExtensionIdentifier.equals(extension.identifier.id, id)) &&
107+
!newExtensions.some(e => ExtensionIdentifier.equals(e.identifier.id, extension.identifier.id))) {
108+
extensionsToInstall.push(extension.identifier);
117109
}
118110
}
119-
return delta(oldExtensions, newExtensions, (a, b) => compare(`${ExtensionIdentifier.toKey(a.identifier.id)}@${a.manifest.version}`, `${ExtensionIdentifier.toKey(b.identifier.id)}@${b.manifest.version}`));
111+
if (extensionsToInstall.length) {
112+
await this.installExtensionsFromProfile(extensionsToInstall, previousProfileLocation, currentProfileLocation);
113+
}
120114
}
115+
return delta(oldExtensions, newExtensions, (a, b) => compare(`${ExtensionIdentifier.toKey(a.identifier.id)}@${a.manifest.version}`, `${ExtensionIdentifier.toKey(b.identifier.id)}@${b.manifest.version}`));
121116
}
122117

123118
protected getProfileLocation(profileLocation: URI): Promise<URI>;

src/vs/workbench/services/extensionManagement/common/remoteExtensionManagementService.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ export class RemoteExtensionManagementService extends ProfileAwareExtensionManag
5656
return profile?.extensionsResource;
5757
}
5858

59-
protected override async switchExtensionsProfile(previousProfileLocation: URI, currentProfileLocation: URI, preserveData: boolean | ExtensionIdentifier[]): Promise<DidChangeProfileEvent> {
59+
protected override async switchExtensionsProfile(previousProfileLocation: URI, currentProfileLocation: URI, preserveExtensions?: ExtensionIdentifier[]): Promise<DidChangeProfileEvent> {
6060
const remoteProfiles = await this.remoteUserDataProfilesService.getRemoteProfiles();
6161
const previousProfile = remoteProfiles.find(p => this.uriIdentityService.extUri.isEqual(p.extensionsResource, previousProfileLocation));
6262
const currentProfile = remoteProfiles.find(p => this.uriIdentityService.extUri.isEqual(p.extensionsResource, currentProfileLocation));
6363
if (previousProfile?.id === currentProfile?.id) {
6464
return { added: [], removed: [] };
6565
}
66-
if (preserveData === true && currentProfile?.isDefault) {
67-
preserveData = false;
68-
}
69-
return super.switchExtensionsProfile(previousProfileLocation, currentProfileLocation, preserveData);
66+
return super.switchExtensionsProfile(previousProfileLocation, currentProfileLocation, preserveExtensions);
7067
}
7168
}

src/vs/workbench/services/extensionManagement/common/webExtensionManagementService.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,10 @@ export class WebExtensionManagementService extends AbstractExtensionManagementSe
192192
if (!previousProfileLocation || !currentProfileLocation) {
193193
throw new Error('This should not happen');
194194
}
195-
if (e.preserveData) {
196-
await this.copyExtensions(previousProfileLocation, currentProfileLocation);
197-
this._onDidChangeProfile.fire({ added: [], removed: [] });
198-
} else {
199-
const oldExtensions = await this.webExtensionsScannerService.scanUserExtensions(previousProfileLocation);
200-
const newExtensions = await this.webExtensionsScannerService.scanUserExtensions(currentProfileLocation);
201-
const { added, removed } = delta(oldExtensions, newExtensions, (a, b) => compare(`${ExtensionIdentifier.toKey(a.identifier.id)}@${a.manifest.version}`, `${ExtensionIdentifier.toKey(b.identifier.id)}@${b.manifest.version}`));
202-
this._onDidChangeProfile.fire({ added: added.map(e => toLocalExtension(e)), removed: removed.map(e => toLocalExtension(e)) });
203-
}
195+
const oldExtensions = await this.webExtensionsScannerService.scanUserExtensions(previousProfileLocation);
196+
const newExtensions = await this.webExtensionsScannerService.scanUserExtensions(currentProfileLocation);
197+
const { added, removed } = delta(oldExtensions, newExtensions, (a, b) => compare(`${ExtensionIdentifier.toKey(a.identifier.id)}@${a.manifest.version}`, `${ExtensionIdentifier.toKey(b.identifier.id)}@${b.manifest.version}`));
198+
this._onDidChangeProfile.fire({ added: added.map(e => toLocalExtension(e)), removed: removed.map(e => toLocalExtension(e)) });
204199
}
205200
}
206201

src/vs/workbench/services/extensionManagement/electron-sandbox/nativeExtensionManagementService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,17 @@ export class NativeExtensionManagementService extends ProfileAwareExtensionManag
6464
return { location, cleanup };
6565
}
6666

67-
protected override async switchExtensionsProfile(previousProfileLocation: URI, currentProfileLocation: URI, preserveData: boolean | ExtensionIdentifier[]): Promise<DidChangeProfileEvent> {
68-
if (!preserveData && this.nativeEnvironmentService.remoteAuthority) {
67+
protected override async switchExtensionsProfile(previousProfileLocation: URI, currentProfileLocation: URI, preserveExtensions?: ExtensionIdentifier[]): Promise<DidChangeProfileEvent> {
68+
if (this.nativeEnvironmentService.remoteAuthority) {
6969
const previousInstalledExtensions = await this.getInstalled(ExtensionType.User, previousProfileLocation);
7070
const resolverExtension = previousInstalledExtensions.find(e => isResolverExtension(e.manifest, this.nativeEnvironmentService.remoteAuthority));
71-
preserveData = resolverExtension ? [new ExtensionIdentifier(resolverExtension.identifier.id)] : preserveData;
71+
if (resolverExtension) {
72+
if (!preserveExtensions) {
73+
preserveExtensions = [];
74+
}
75+
preserveExtensions.push(new ExtensionIdentifier(resolverExtension.identifier.id));
76+
}
7277
}
73-
return super.switchExtensionsProfile(previousProfileLocation, currentProfileLocation, preserveData);
78+
return super.switchExtensionsProfile(previousProfileLocation, currentProfileLocation, preserveExtensions);
7479
}
7580
}

0 commit comments

Comments
 (0)