提交 afda5a25 编写于 作者: B Benjamin Pasero

add a way to validate stacks model while running

上级 2a19987c
...@@ -29,6 +29,7 @@ import {Scope, IActionBarRegistry, Extensions as ActionBarExtensions} from 'vs/w ...@@ -29,6 +29,7 @@ import {Scope, IActionBarRegistry, Extensions as ActionBarExtensions} from 'vs/w
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions'; import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {SyncDescriptor} from 'vs/platform/instantiation/common/descriptors'; import {SyncDescriptor} from 'vs/platform/instantiation/common/descriptors';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes'; import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import {EditorStacksModel} from 'vs/workbench/common/editor/editorStacksModel';
// Register String Editor // Register String Editor
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditor( (<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditor(
...@@ -187,4 +188,14 @@ KeybindingsRegistry.registerCommandDesc({ ...@@ -187,4 +188,14 @@ KeybindingsRegistry.registerCommandDesc({
}, },
when: undefined, when: undefined,
primary: undefined primary: undefined
});
KeybindingsRegistry.registerCommandDesc({
id: '_workbench.validateStacksModel',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(0),
handler(accessor: ServicesAccessor) {
(<EditorStacksModel>accessor.get(IWorkbenchEditorService).getStacksModel()).validate();
},
when: undefined,
primary: undefined
}); });
\ No newline at end of file
...@@ -759,6 +759,12 @@ export class EditorStacksModel implements IEditorStacksModel { ...@@ -759,6 +759,12 @@ export class EditorStacksModel implements IEditorStacksModel {
} }
private save(): void { private save(): void {
const serialized = this.serialize();
this.storageService.store(EditorStacksModel.STORAGE_KEY, JSON.stringify(serialized), StorageScope.WORKSPACE);
}
private serialize(): ISerializedEditorStacksModel {
let activeIndex = this.indexOf(this._activeGroup); let activeIndex = this.indexOf(this._activeGroup);
let activeIsEmptyGroup = false; let activeIsEmptyGroup = false;
...@@ -791,12 +797,10 @@ export class EditorStacksModel implements IEditorStacksModel { ...@@ -791,12 +797,10 @@ export class EditorStacksModel implements IEditorStacksModel {
serializableActiveIndex = activeIndex; // active group is not empty and can be serialized serializableActiveIndex = activeIndex; // active group is not empty and can be serialized
} }
const serialized: ISerializedEditorStacksModel = { return {
groups: serializedGroups, groups: serializedGroups,
active: serializableActiveIndex active: serializableActiveIndex
}; };
this.storageService.store(EditorStacksModel.STORAGE_KEY, JSON.stringify(serialized), StorageScope.WORKSPACE);
} }
private fireEvent(emitter: Emitter<EditorGroup>, group: EditorGroup): void { private fireEvent(emitter: Emitter<EditorGroup>, group: EditorGroup): void {
...@@ -822,7 +826,7 @@ export class EditorStacksModel implements IEditorStacksModel { ...@@ -822,7 +826,7 @@ export class EditorStacksModel implements IEditorStacksModel {
const serialized: ISerializedEditorStacksModel = JSON.parse(modelRaw); const serialized: ISerializedEditorStacksModel = JSON.parse(modelRaw);
// TODO@stacks remove this once stacks are stable; prevent bad stored state // TODO@stacks remove this once stacks are stable; prevent bad stored state
const invalidId = this.validate(serialized); const invalidId = this.doValidate(serialized);
if (invalidId) { if (invalidId) {
console.warn(`Ignoring invalid stacks model (Error code: ${invalidId}): ${JSON.stringify(serialized)}`); console.warn(`Ignoring invalid stacks model (Error code: ${invalidId}): ${JSON.stringify(serialized)}`);
console.warn(serialized); console.warn(serialized);
...@@ -835,7 +839,7 @@ export class EditorStacksModel implements IEditorStacksModel { ...@@ -835,7 +839,7 @@ export class EditorStacksModel implements IEditorStacksModel {
} }
} }
private validate(serialized: ISerializedEditorStacksModel): number { private doValidate(serialized: ISerializedEditorStacksModel): number {
if (!serialized.groups.length && typeof serialized.active === 'number') { if (!serialized.groups.length && typeof serialized.active === 'number') {
return 1; // Invalid active (we have no groups, but an active one) return 1; // Invalid active (we have no groups, but an active one)
} }
...@@ -887,6 +891,17 @@ export class EditorStacksModel implements IEditorStacksModel { ...@@ -887,6 +891,17 @@ export class EditorStacksModel implements IEditorStacksModel {
dispose(this.toDispose); dispose(this.toDispose);
} }
public validate(): void {
const serialized = this.serialize();
const invalidId = this.doValidate(serialized);
if (invalidId) {
console.warn(`Ignoring invalid stacks model (Error code: ${invalidId}): ${JSON.stringify(serialized)}`);
console.warn(serialized);
} else {
console.log('Stacks Model OK!');
}
}
public toString(): string { public toString(): string {
this.ensureLoaded(); this.ensureLoaded();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册