diff --git a/src/sql/azdata.d.ts b/src/sql/azdata.d.ts index f1f2b6a0b7..e0ab0f9eea 100644 --- a/src/sql/azdata.d.ts +++ b/src/sql/azdata.d.ts @@ -2612,7 +2612,7 @@ declare module 'azdata' { export interface ComponentBuilder { component(): TComponent; withProperties(properties: U): ComponentBuilder; - withValidation(validation: (component: TComponent) => boolean): ComponentBuilder; + withValidation(validation: (component: TComponent) => boolean | Thenable): ComponentBuilder; } export interface ContainerBuilder extends ComponentBuilder { withLayout(layout: TLayout): ContainerBuilder; diff --git a/src/sql/workbench/api/common/extHostModelView.ts b/src/sql/workbench/api/common/extHostModelView.ts index 4a9b9025da..ec82710c9b 100644 --- a/src/sql/workbench/api/common/extHostModelView.ts +++ b/src/sql/workbench/api/common/extHostModelView.ts @@ -284,7 +284,7 @@ class ModelBuilderImpl implements azdata.ModelBuilder { } } - public runCustomValidations(componentId: string): boolean { + public runCustomValidations(componentId: string): Thenable { let component = this._componentBuilders.get(componentId).componentWrapper(); return component.runCustomValidations(); } @@ -323,7 +323,7 @@ class ComponentBuilderImpl boolean): azdata.ComponentBuilder { + withValidation(validation: (component: T) => boolean | Thenable): azdata.ComponentBuilder { this._component.customValidations.push(validation); return this; } @@ -574,7 +574,7 @@ class ComponentWrapper implements azdata.Component { public properties: { [key: string]: any } = {}; public layout: any; public itemConfigs: InternalItemConfig[]; - public customValidations: ((component: ThisType) => boolean)[] = []; + public customValidations: ((component: ThisType) => boolean | Thenable)[] = []; private _valid: boolean = true; private _onValidityChangedEmitter = new Emitter(); public readonly onValidityChanged = this._onValidityChangedEmitter.event; @@ -808,14 +808,14 @@ class ComponentWrapper implements azdata.Component { this._onErrorEmitter.fire(err); } - public runCustomValidations(): boolean { + public async runCustomValidations(): Promise { let isValid = true; try { - this.customValidations.forEach(validation => { - if (!validation(this)) { + await Promise.all(this.customValidations.map(async validation => { + if (!await validation(this)) { isValid = false; } - }); + })); } catch (e) { isValid = false; } @@ -1988,7 +1988,7 @@ class ModelViewImpl implements azdata.ModelView { return this._proxy.$validate(this._handle, this._component.id); } - public runCustomValidations(componentId: string): boolean { + public runCustomValidations(componentId: string): Thenable { return this._modelBuilder.runCustomValidations(componentId); } } @@ -2035,6 +2035,6 @@ export class ExtHostModelView implements ExtHostModelViewShape { $runCustomValidations(handle: number, componentId: string): Thenable { const view = this._modelViews.get(handle); - return Promise.resolve(view.runCustomValidations(componentId)); + return view.runCustomValidations(componentId); } }