From 531c0db03f15971bfcdb938ee50aef0f701f1632 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Fri, 2 Sep 2022 17:09:33 +0200 Subject: [PATCH] retain non existing view customizations --- .../views/browser/viewDescriptorService.ts | 23 ++++++------ .../browser/viewDescriptorService.test.ts | 37 +++++++++++++++++++ 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/vs/workbench/services/views/browser/viewDescriptorService.ts b/src/vs/workbench/services/views/browser/viewDescriptorService.ts index 1824fd7ca424b..de843eacab866 100644 --- a/src/vs/workbench/services/views/browser/viewDescriptorService.ts +++ b/src/vs/workbench/services/views/browser/viewDescriptorService.ts @@ -588,23 +588,24 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor for (const [containerId, location] of this.viewContainersCustomLocations) { const container = this.getViewContainerById(containerId); - // Save only if the view container exists and - // the view container is generated or not at default location - if (container && (this.isGeneratedContainerId(containerId) || location !== this.getDefaultViewContainerLocation(container))) { - viewCustomizations.viewContainerLocations[containerId] = location; + // Skip if the view container is not a generated container and in default location + if (container && !this.isGeneratedContainerId(containerId) && location === this.getDefaultViewContainerLocation(container)) { + continue; } + viewCustomizations.viewContainerLocations[containerId] = location; } - for (const viewContainer of this.viewContainers) { - const viewContainerModel = this.getViewContainerModel(viewContainer); - for (const viewDescriptor of viewContainerModel.allViewDescriptors) { - const defaultContainer = this.getDefaultContainerById(viewDescriptor.id); - // Save only if the view is not in the default container + for (const [viewId, viewContainerId] of this.viewDescriptorsCustomLocations) { + const viewContainer = this.getViewContainerById(viewContainerId); + if (viewContainer) { + const defaultContainer = this.getDefaultContainerById(viewId); + // Skip if the view is at default location // https://github.com/microsoft/vscode/issues/90414 - if (defaultContainer?.id !== viewContainer.id) { - viewCustomizations.viewLocations[viewDescriptor.id] = viewContainer.id; + if (defaultContainer?.id === viewContainer.id) { + continue; } } + viewCustomizations.viewLocations[viewId] = viewContainerId; } this.viewCustomizations = viewCustomizations; diff --git a/src/vs/workbench/services/views/test/browser/viewDescriptorService.test.ts b/src/vs/workbench/services/views/test/browser/viewDescriptorService.test.ts index 901bbb74675be..d072c37578bfc 100644 --- a/src/vs/workbench/services/views/test/browser/viewDescriptorService.test.ts +++ b/src/vs/workbench/services/views/test/browser/viewDescriptorService.test.ts @@ -584,4 +584,41 @@ suite('ViewDescriptorService', () => { assert.deepStrictEqual(viewContainer1Views.allViewDescriptors.map(v => v.id), ['view4']); }); + test('view containers with not existing views are not removed from customizations', async function () { + const storageService = instantiationService.get(IStorageService); + const viewContainer1 = ViewContainersRegistry.registerViewContainer({ id: `${viewContainerIdPrefix}-${generateUuid()}`, title: 'test', ctorDescriptor: new SyncDescriptor({}) }, ViewContainerLocation.Sidebar); + const generateViewContainer1 = `workbench.views.service.${ViewContainerLocationToString(ViewContainerLocation.Sidebar)}.${generateUuid()}`; + const viewsCustomizations = { + viewContainerLocations: { + [generateViewContainer1]: ViewContainerLocation.Sidebar, + [viewContainer1.id]: ViewContainerLocation.AuxiliaryBar + }, + viewLocations: { + 'view5': generateViewContainer1 + } + }; + storageService.store('views.customizations', JSON.stringify(viewsCustomizations), StorageScope.PROFILE, StorageTarget.USER); + + const viewDescriptors: IViewDescriptor[] = [ + { + id: 'view1', + ctorDescriptor: null!, + name: 'Test View 1', + canMoveView: true + } + ]; + + ViewsRegistry.registerViews(viewDescriptors, viewContainer1); + + const testObject = aViewDescriptorService(); + testObject.onDidRegisterExtensions(); + + const viewContainer1Views = testObject.getViewContainerModel(viewContainer1); + assert.deepStrictEqual(testObject.getViewContainerLocation(viewContainer1), ViewContainerLocation.AuxiliaryBar); + assert.deepStrictEqual(viewContainer1Views.allViewDescriptors.map(v => v.id), ['view1']); + + const actual = JSON.parse(storageService.get('views.customizations', StorageScope.PROFILE)!); + assert.deepStrictEqual(actual, viewsCustomizations); + }); + });