Repository: microsoft/vscode (TypeScript)
Date: 2023-03-17 12:42:58+00:00
Task type: Bug Fix

Issue:
Hidden views re-appear on switching profiles
Steps to Reproduce:

1. Create profile A - move timeline view to secondary sidebar
2. Create profile B - hide timeline view
3. From profile A switch to profile B

🐛 Timeline view reappear



Issue discussion:

Solution patch:
diff --git a/src/vs/workbench/services/views/browser/viewDescriptorService.ts b/src/vs/workbench/services/views/browser/viewDescriptorService.ts
--- a/src/vs/workbench/services/views/browser/viewDescriptorService.ts
+++ b/src/vs/workbench/services/views/browser/viewDescriptorService.ts
@@ -574,7 +574,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
 		}
 		// Execute View Movements
 		for (const { views, from, to } of viewsToMove) {
-			this.moveViewsWithoutSaving(views, from, to);
+			this.moveViewsWithoutSaving(views, from, to, ViewVisibilityState.Default);
 		}
 
 		this.viewContainersCustomLocations = newViewContainerCustomizations;


Test patch:
diff --git a/src/vs/workbench/services/views/test/browser/viewDescriptorService.test.ts b/src/vs/workbench/services/views/test/browser/viewDescriptorService.test.ts
--- a/src/vs/workbench/services/views/test/browser/viewDescriptorService.test.ts
+++ b/src/vs/workbench/services/views/test/browser/viewDescriptorService.test.ts
@@ -16,6 +16,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
 import { DisposableStore } from 'vs/base/common/lifecycle';
 import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
 import { generateUuid } from 'vs/base/common/uuid';
+import { compare } from 'vs/base/common/strings';
 
 const ViewsRegistry = Registry.as<IViewsRegistry>(ViewContainerExtensions.ViewsRegistry);
 const ViewContainersRegistry = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry);
@@ -664,4 +665,56 @@ suite('ViewDescriptorService', () => {
 		assert.deepStrictEqual(generatedViewContainerModel.allViewDescriptors.map(v => v.id), ['view1']);
 	});
 
+	test('storage change move views and retain visibility state', async function () {
+		const storageService = instantiationService.get(IStorageService);
+		const testObject = aViewDescriptorService();
+
+		const viewContainer = ViewContainersRegistry.registerViewContainer({ id: `${viewContainerIdPrefix}-${generateUuid()}`, title: 'test', ctorDescriptor: new SyncDescriptor(<any>{}) }, ViewContainerLocation.Sidebar);
+		const viewDescriptors: IViewDescriptor[] = [
+			{
+				id: 'view1',
+				ctorDescriptor: null!,
+				name: 'Test View 1',
+				canMoveView: true,
+				canToggleVisibility: true
+			},
+			{
+				id: 'view2',
+				ctorDescriptor: null!,
+				name: 'Test View 2',
+				canMoveView: true
+			}
+		];
+		ViewsRegistry.registerViews(viewDescriptors, viewContainer);
+
+		testObject.whenExtensionsRegistered();
+
+		const viewContainer1Views = testObject.getViewContainerModel(viewContainer);
+		viewContainer1Views.setVisible('view1', false);
+
+		const generateViewContainerId = `workbench.views.service.${ViewContainerLocationToString(ViewContainerLocation.AuxiliaryBar)}.${generateUuid()}`;
+		const viewsCustomizations = {
+			viewContainerLocations: {
+				[generateViewContainerId]: ViewContainerLocation.AuxiliaryBar,
+			},
+			viewLocations: {
+				'view1': generateViewContainerId
+			}
+		};
+		storageService.store('views.customizations', JSON.stringify(viewsCustomizations), StorageScope.PROFILE, StorageTarget.USER);
+
+		const generateViewContainer = testObject.getViewContainerById(generateViewContainerId)!;
+		const generatedViewContainerModel = testObject.getViewContainerModel(generateViewContainer);
+
+		assert.deepStrictEqual(viewContainer1Views.allViewDescriptors.map(v => v.id), ['view2']);
+		assert.deepStrictEqual(testObject.getViewContainerLocation(generateViewContainer), ViewContainerLocation.AuxiliaryBar);
+		assert.deepStrictEqual(generatedViewContainerModel.allViewDescriptors.map(v => v.id), ['view1']);
+
+		storageService.store('views.customizations', JSON.stringify({}), StorageScope.PROFILE, StorageTarget.USER);
+
+		assert.deepStrictEqual(viewContainer1Views.allViewDescriptors.map(v => v.id).sort((a, b) => compare(a, b)), ['view1', 'view2']);
+		assert.deepStrictEqual(viewContainer1Views.visibleViewDescriptors.map(v => v.id), ['view2']);
+		assert.deepStrictEqual(generatedViewContainerModel.allViewDescriptors.map(v => v.id), []);
+	});
+
 });