Skip to content

Commit 02a191b

Browse files
committed
grid: catch bad deserialization
1 parent 18a1030 commit 02a191b

1 file changed

Lines changed: 44 additions & 36 deletions

File tree

src/vs/workbench/browser/layout.ts

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -713,55 +713,63 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
713713
this.panelPartView = panelPart;
714714
this.statusBarPartView = statusBar;
715715

716+
let workbenchGrid: SerializableGrid<ISerializableView> | undefined;
717+
716718
const savedGrid = this.storageService.get(Storage.GRID_LAYOUT, StorageScope.GLOBAL, undefined);
717719
if (savedGrid) {
718720
const parsedGrid: ISerializedGrid = JSON.parse(savedGrid);
719-
this.workbenchGrid = SerializableGrid.deserialize(parsedGrid, {
720-
fromJSON: (serializedPart: { type: Parts } | null) => {
721-
if (serializedPart && serializedPart.type) {
722-
switch (serializedPart.type) {
723-
case Parts.ACTIVITYBAR_PART:
724-
return this.activityBarPartView;
725-
case Parts.TITLEBAR_PART:
726-
return this.titleBarPartView;
727-
case Parts.EDITOR_PART:
728-
return this.editorPartView;
729-
case Parts.PANEL_PART:
730-
return this.panelPartView;
731-
case Parts.SIDEBAR_PART:
732-
return this.sideBarPartView;
733-
case Parts.STATUSBAR_PART:
734-
return this.statusBarPartView;
735-
default:
736-
return this.editorPartView;
737-
}
738-
} else {
739-
return this.editorPartView;
721+
722+
const fromJSON = (serializedPart: { type: Parts } | null) => {
723+
if (serializedPart && serializedPart.type) {
724+
switch (serializedPart.type) {
725+
case Parts.ACTIVITYBAR_PART:
726+
return this.activityBarPartView;
727+
case Parts.TITLEBAR_PART:
728+
return this.titleBarPartView;
729+
case Parts.EDITOR_PART:
730+
return this.editorPartView;
731+
case Parts.PANEL_PART:
732+
return this.panelPartView;
733+
case Parts.SIDEBAR_PART:
734+
return this.sideBarPartView;
735+
case Parts.STATUSBAR_PART:
736+
return this.statusBarPartView;
737+
default:
738+
return this.editorPartView;
740739
}
740+
} else {
741+
return this.editorPartView;
741742
}
742-
},
743-
{ proportionalLayout: false });
743+
};
744744

745+
try {
746+
workbenchGrid = SerializableGrid.deserialize(parsedGrid, { fromJSON }, { proportionalLayout: false });
745747

746-
// Set some layout state
747-
this.state.sideBar.position = Position.LEFT;
748-
for (let view of this.workbenchGrid.getNeighborViews(this.sideBarPartView, Direction.Right)) {
749-
if (view === this.activityBarPartView) {
750-
this.state.sideBar.position = Position.RIGHT;
748+
// Set some layout state
749+
this.state.sideBar.position = Position.LEFT;
750+
for (let view of workbenchGrid.getNeighborViews(this.sideBarPartView, Direction.Right)) {
751+
if (view === this.activityBarPartView) {
752+
this.state.sideBar.position = Position.RIGHT;
753+
}
751754
}
752-
}
753755

754-
this.state.panel.position = Position.BOTTOM;
755-
for (let view of this.workbenchGrid.getNeighborViews(this.panelPartView, Direction.Left)) {
756-
if (view === this.editorPartView) {
757-
this.state.panel.position = Position.RIGHT;
756+
this.state.panel.position = Position.BOTTOM;
757+
for (let view of workbenchGrid.getNeighborViews(this.panelPartView, Direction.Left)) {
758+
if (view === this.editorPartView) {
759+
this.state.panel.position = Position.RIGHT;
760+
}
758761
}
762+
} catch (err) {
763+
console.error(err);
759764
}
760-
} else {
761-
this.workbenchGrid = new SerializableGrid(this.editorPartView, { proportionalLayout: false });
762765
}
763766

764-
this.container.prepend(this.workbenchGrid.element);
767+
if (!workbenchGrid) {
768+
workbenchGrid = new SerializableGrid(this.editorPartView, { proportionalLayout: false });
769+
}
770+
771+
this.container.prepend(workbenchGrid.element);
772+
this.workbenchGrid = workbenchGrid;
765773

766774
this._register((this.sideBarPartView as SidebarPart).onDidVisibilityChange((visible) => {
767775
this.setSideBarHidden(!visible, true);

0 commit comments

Comments
 (0)