add document to event

This commit is contained in:
Johannes Rieken
2016-09-20 16:46:41 +02:00
parent 13b1a8758d
commit 23fef6b12f
2 changed files with 28 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {ExtHostDocuments} from 'vs/workbench/api/node/extHostDocuments';
export interface TextDocumentWillSaveEvent {
document: vscode.TextDocument;
waitUntil(t: Thenable<any>): void;
}
@@ -52,16 +53,23 @@ export class ExtHostDocumentSaveParticipant {
}
private _deliverEventAsync(listener: Function, thisArg: any, document: vscode.TextDocument): TPromise<any> {
const promises: TPromise<any>[] = [];
const event = {
const event: TextDocumentWillSaveEvent = Object.freeze({
document,
waitUntil(p: Thenable<any>) {
if (Object.isFrozen(promises)) {
throw illegalState('waitUntil can not be called async');
}
promises.push(TPromise.wrap(p));
}
};
});
try {
listener.apply(thisArg, [event]);
} finally {
event.waitUntil = () => { throw illegalState(); };
Object.freeze(promises);
return TPromise.join(promises).then(() => void 0, err => void 0 /* ignore */);
}
}