From bf11c6cd52b4e603a58d34e55e9c6853a3c30d73 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Fri, 7 Jun 2024 01:13:11 +0200 Subject: [PATCH] fix canceling (#214519) --- .../browser/userDataProfilesEditorModel.ts | 10 +++---- .../userDataProfileImportExportService.ts | 30 ++++++++++++------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts b/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts index 2756c2a3f48..6f5b528020e 100644 --- a/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts +++ b/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts @@ -823,7 +823,7 @@ export class UserDataProfilesEditorModel extends EditorModel { () => this.previewNewProfile(cancellationTokenSource.token) )); this.newProfileElement = disposables.add(this.instantiationService.createInstance(NewProfileElement, - localize('untitled', "Untitled"), + copyFrom ? '' : localize('untitled', "Untitled"), copyFrom, [[createAction], [previewProfileAction, cancelAction]], [[], []], @@ -911,7 +911,7 @@ export class UserDataProfilesEditorModel extends EditorModel { const template = await this.newProfileElement.resolveTemplate(copyFrom); if (template) { this.telemetryService.publicLog2('userDataProfile.createFromTemplate', createProfileTelemetryData); - await this.userDataProfileImportExportService.createProfileFromTemplate( + profile = await this.userDataProfileImportExportService.createProfileFromTemplate( template, { name, @@ -925,7 +925,7 @@ export class UserDataProfilesEditorModel extends EditorModel { } } else if (isUserDataProfile(copyFrom)) { this.telemetryService.publicLog2('userDataProfile.createFromProfile', createProfileTelemetryData); - await this.userDataProfileImportExportService.createFromProfile( + profile = await this.userDataProfileImportExportService.createFromProfile( copyFrom, { name, @@ -938,10 +938,8 @@ export class UserDataProfilesEditorModel extends EditorModel { ); } else { this.telemetryService.publicLog2('userDataProfile.createEmptyProfile', createProfileTelemetryData); - await this.userDataProfileManagementService.createProfile(name, { useDefaultFlags, icon, transient }); + profile = await this.userDataProfileManagementService.createProfile(name, { useDefaultFlags, icon, transient }); } - - profile = this.userDataProfilesService.profiles.find(p => p.name === name); } } finally { if (this.newProfileElement) { diff --git a/src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.ts b/src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.ts index 2d569e09eed..1d5217c67d3 100644 --- a/src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.ts +++ b/src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.ts @@ -241,7 +241,14 @@ export class UserDataProfileImportExportService extends Disposable implements IU creationPromise = createCancelablePromise(async token => { const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, from, { ...options?.resourceTypeFlags, extensions: false })); const profileTemplate = await userDataProfilesExportState.getProfileTemplate(options.name ?? from.name, options?.icon); - profile = await this.doCreateProfile2(profileTemplate, options, reportProgress, token); + profile = await this.getProfileToImport({ ...profileTemplate, name: options.name ?? profileTemplate.name }, !!options.transient, options); + if (!profile) { + return; + } + if (token.isCancellationRequested) { + return; + } + await this.applyProfileTemplate(profileTemplate, profile, options, reportProgress, token); }); try { await creationPromise; @@ -252,6 +259,7 @@ export class UserDataProfileImportExportService extends Disposable implements IU } catch (error) { if (profile) { await this.userDataProfilesService.removeProfile(profile); + profile = undefined; } } return profile; @@ -272,27 +280,28 @@ export class UserDataProfileImportExportService extends Disposable implements IU }, async progress => { const reportProgress = (message: string) => progress.report({ message: localize('create from profile', "Create Profile: {0}", message) }); creationPromise = createCancelablePromise(async token => { - profile = await this.doCreateProfile2(profileTemplate, options, reportProgress, token); + profile = await this.getProfileToImport({ ...profileTemplate, name: options.name ?? profileTemplate.name }, !!options.transient, options); + if (!profile) { + return; + } + if (token.isCancellationRequested) { + return; + } + await this.applyProfileTemplate(profileTemplate, profile, options, reportProgress, token); }); try { await creationPromise; } catch (error) { if (profile) { await this.userDataProfilesService.removeProfile(profile); + profile = undefined; } } return profile; }, () => creationPromise.cancel()).finally(() => disposables.dispose()); } - private async doCreateProfile2(profileTemplate: IUserDataProfileTemplate, options: IUserDataProfileCreateOptions, reportProgress: (message: string) => void, token: CancellationToken): Promise { - const profile = await this.getProfileToImport({ ...profileTemplate, name: options.name ?? profileTemplate.name }, !!options.transient, options); - if (!profile) { - return; - } - if (token.isCancellationRequested) { - return; - } + private async applyProfileTemplate(profileTemplate: IUserDataProfileTemplate, profile: IUserDataProfile, options: IUserDataProfileCreateOptions, reportProgress: (message: string) => void, token: CancellationToken): Promise { if (profileTemplate.settings && (options.resourceTypeFlags?.settings ?? true) && !profile.useDefaultFlags?.settings) { reportProgress(localize('creating settings', "Creating Settings...")); await this.instantiationService.createInstance(SettingsResource).apply(profileTemplate.settings, profile); @@ -332,7 +341,6 @@ export class UserDataProfileImportExportService extends Disposable implements IU reportProgress(localize('installing extensions', "Installing Extensions...")); await this.instantiationService.createInstance(ExtensionsResource).apply(profileTemplate.extensions, profile, reportProgress, token); } - return profile; } private saveProfile(profile: IUserDataProfile): Promise;