提交 ee081520 编写于 作者: C Christof Marti

Fix timing issue (fixes #61748)

上级 0d987455
......@@ -422,6 +422,7 @@ suite('window namespace tests', () => {
canPickMany: true
});
const first = new Promise(resolve => resolves.push(resolve));
await new Promise(resolve => setTimeout(resolve, 10)); // Allow UI to update.
await commands.executeCommand('workbench.action.quickOpenSelectNext');
assert.equal(await first, 'eins');
await commands.executeCommand('workbench.action.quickPickManyToggle');
......
......@@ -21,10 +21,10 @@ export class MainThreadQuickOpen implements MainThreadQuickOpenShape {
private _proxy: ExtHostQuickOpenShape;
private _quickInputService: IQuickInputService;
private _doSetItems: (items: TransferQuickPickItems[]) => any;
private _doSetError: (error: Error) => any;
private _contents: TPromise<TransferQuickPickItems[]>;
private _token: number = 0;
private _items: Record<number, {
resolve(items: TransferQuickPickItems[]): void;
reject(error: Error): void;
}> = {};
constructor(
extHostContext: IExtHostContext,
......@@ -37,21 +37,9 @@ export class MainThreadQuickOpen implements MainThreadQuickOpenShape {
public dispose(): void {
}
$show(options: IPickOptions<TransferQuickPickItems>, token: CancellationToken): Thenable<number | number[]> {
const myToken = ++this._token;
this._contents = new TPromise<TransferQuickPickItems[]>((c, e) => {
this._doSetItems = (items) => {
if (myToken === this._token) {
c(items);
}
};
this._doSetError = (error) => {
if (myToken === this._token) {
e(error);
}
};
$show(instance: number, options: IPickOptions<TransferQuickPickItems>, token: CancellationToken): Thenable<number | number[]> {
const contents = new Promise<TransferQuickPickItems[]>((resolve, reject) => {
this._items[instance] = { resolve, reject };
});
options = {
......@@ -64,14 +52,14 @@ export class MainThreadQuickOpen implements MainThreadQuickOpenShape {
};
if (options.canPickMany) {
return this._quickInputService.pick(this._contents, options as { canPickMany: true }, token).then(items => {
return this._quickInputService.pick(contents, options as { canPickMany: true }, token).then(items => {
if (items) {
return items.map(item => item.handle);
}
return undefined;
});
} else {
return this._quickInputService.pick(this._contents, options, token).then(item => {
return this._quickInputService.pick(contents, options, token).then(item => {
if (item) {
return item.handle;
}
......@@ -80,16 +68,18 @@ export class MainThreadQuickOpen implements MainThreadQuickOpenShape {
}
}
$setItems(items: TransferQuickPickItems[]): Thenable<void> {
if (this._doSetItems) {
this._doSetItems(items);
$setItems(instance: number, items: TransferQuickPickItems[]): Thenable<void> {
if (this._items[instance]) {
this._items[instance].resolve(items);
delete this._items[instance];
}
return undefined;
}
$setError(error: Error): Thenable<void> {
if (this._doSetError) {
this._doSetError(error);
$setError(instance: number, error: Error): Thenable<void> {
if (this._items[instance]) {
this._items[instance].reject(error);
delete this._items[instance];
}
return undefined;
}
......
......@@ -416,9 +416,9 @@ export interface TransferInputBox extends BaseTransferQuickInput {
}
export interface MainThreadQuickOpenShape extends IDisposable {
$show(options: IPickOptions<TransferQuickPickItems>, token: CancellationToken): Thenable<number | number[]>;
$setItems(items: TransferQuickPickItems[]): Thenable<void>;
$setError(error: Error): Thenable<void>;
$show(instance: number, options: IPickOptions<TransferQuickPickItems>, token: CancellationToken): Thenable<number | number[]>;
$setItems(instance: number, items: TransferQuickPickItems[]): Thenable<void>;
$setError(instance: number, error: Error): Thenable<void>;
$input(options: vscode.InputBoxOptions, validateInput: boolean, token: CancellationToken): Thenable<string>;
$createOrUpdate(params: TransferQuickInput): Thenable<void>;
$dispose(id: number): Thenable<void>;
......
......@@ -28,6 +28,8 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
private _sessions = new Map<number, ExtHostQuickInput>();
private _instances = 0;
constructor(mainContext: IMainContext, workspace: ExtHostWorkspace, commands: ExtHostCommands) {
this._proxy = mainContext.getProxy(MainContext.MainThreadQuickOpen);
this._workspace = workspace;
......@@ -44,7 +46,9 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
const itemsPromise = <Promise<Item[]>>Promise.resolve(itemsOrItemsPromise);
const quickPickWidget = this._proxy.$show({
const instance = ++this._instances;
const quickPickWidget = this._proxy.$show(instance, {
placeHolder: options && options.placeHolder,
matchOnDescription: options && options.matchOnDescription,
matchOnDetail: options && options.matchOnDetail,
......@@ -99,7 +103,7 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
}
// show items
this._proxy.$setItems(pickItems);
this._proxy.$setItems(instance, pickItems);
return quickPickWidget.then(handle => {
if (typeof handle === 'number') {
......@@ -115,7 +119,7 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
return undefined;
}
this._proxy.$setError(err);
this._proxy.$setError(instance, err);
return Promise.reject(err);
});
......@@ -140,8 +144,6 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
return undefined;
}
this._proxy.$setError(err);
return Promise.reject(err);
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册