Remove first cut of QuickInput API (#49340)

This commit is contained in:
Christof Marti
2018-05-28 09:30:39 +02:00
parent a48089ce51
commit 0662a71dfb
3 changed files with 2 additions and 124 deletions

View File

@@ -405,84 +405,6 @@ suite('window namespace tests', () => {
return Promise.all([a, b]);
});
test('multiStepInput, two steps', async function () {
const picks = window.multiStepInput(async (input, token) => {
const pick1 = input.showQuickPick(['eins', 'zwei', 'drei']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick1, 'eins');
const pick2 = input.showQuickPick(['vier', 'fünf', 'sechs']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick2, 'vier');
return [ await pick1, await pick2 ];
});
assert.deepEqual(await picks, ['eins', 'vier']);
});
test('multiStepInput, interrupted by showQuickPick', async function () {
const picks = window.multiStepInput(async (input, token) => {
const pick1 = input.showQuickPick(['eins', 'zwei', 'drei']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick1, 'eins');
assert.ok(!token.isCancellationRequested);
const otherPick = window.showQuickPick(['sieben', 'acht', 'neun']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await otherPick, 'sieben');
assert.ok(token.isCancellationRequested);
const pick2 = input.showQuickPick(['vier', 'fünf', 'sechs']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick2, undefined);
return [ await pick1, await pick2 ];
});
assert.deepEqual(await picks, ['eins', undefined]);
});
test('multiStepInput, interrupted by multiStepInput', async function () {
const picks = window.multiStepInput(async (input, token) => {
const pick1 = input.showQuickPick(['eins', 'zwei', 'drei']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick1, 'eins');
assert.ok(!token.isCancellationRequested);
const otherPick = window.multiStepInput(async (input, token) => {
const otherPick = window.showQuickPick(['sieben', 'acht', 'neun']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await otherPick, 'sieben');
return otherPick;
});
assert.equal(await otherPick, 'sieben');
assert.ok(token.isCancellationRequested);
const pick2 = input.showQuickPick(['vier', 'fünf', 'sechs']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick2, undefined);
return [ await pick1, await pick2 ];
});
assert.deepEqual(await picks, ['eins', undefined]);
});
test('multiStepInput, interrupted by error', async function () {
try {
const picks = window.multiStepInput(async (input, token) => {
const pick1 = input.showQuickPick(['eins', 'zwei', 'drei']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick1, 'eins');
throw new Error('because');
});
await picks;
assert.ok(false);
} catch (error) {
assert.equal(error.message, 'because');
}
});
test('showWorkspaceFolderPick', function () {
const p = window.showWorkspaceFolderPick(undefined);

View File

@@ -394,9 +394,6 @@ export function createApiFactory(
showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken) {
return extHostQuickOpen.showInput(undefined, options, token);
},
multiStepInput<T>(handler: (input: vscode.QuickInput, token: vscode.CancellationToken) => Thenable<T>, token?: vscode.CancellationToken): Thenable<T> {
return extHostQuickOpen.multiStepInput(handler, token);
},
showOpenDialog(options) {
return extHostDialogs.showOpenDialog(options);
},

View File

@@ -6,12 +6,11 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { wireCancellationToken, asWinJsPromise } from 'vs/base/common/async';
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
import { QuickPickOptions, QuickPickItem, InputBoxOptions, WorkspaceFolderPickOptions, WorkspaceFolder, QuickInput } from 'vscode';
import { CancellationToken } from 'vs/base/common/cancellation';
import { QuickPickOptions, QuickPickItem, InputBoxOptions, WorkspaceFolderPickOptions, WorkspaceFolder } from 'vscode';
import { MainContext, MainThreadQuickOpenShape, ExtHostQuickOpenShape, MyQuickPickItems, IMainContext } from './extHost.protocol';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
import { isPromiseCanceledError } from 'vs/base/common/errors';
export type Item = string | QuickPickItem;
@@ -24,8 +23,6 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
private _onDidSelectItem: (handle: number) => void;
private _validateInput: (input: string) => string | Thenable<string>;
private _nextMultiStepHandle = 1;
constructor(mainContext: IMainContext, workspace: ExtHostWorkspace, commands: ExtHostCommands) {
this._proxy = mainContext.getProxy(MainContext.MainThreadQuickOpen);
this._workspace = workspace;
@@ -145,42 +142,4 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
return this._workspace.getWorkspaceFolders().filter(folder => folder.uri.toString() === selectedFolder.uri.toString())[0];
});
}
// ---- Multi-step input
multiStepInput<T>(handler: (input: QuickInput, token: CancellationToken) => Thenable<T>, clientToken: CancellationToken = CancellationToken.None): Thenable<T> {
const handle = this._nextMultiStepHandle++;
const remotePromise = this._proxy.$multiStep(handle);
const cancellationSource = new CancellationTokenSource();
const handlerPromise = TPromise.wrap(handler({
showQuickPick: this.showQuickPick.bind(this, handle),
showInputBox: this.showInput.bind(this, handle)
}, cancellationSource.token));
clientToken.onCancellationRequested(() => {
remotePromise.cancel();
cancellationSource.cancel();
});
return TPromise.join<void, T>([
remotePromise.then(() => {
throw new Error('Unexpectedly fulfilled promise.');
}, err => {
if (!isPromiseCanceledError(err)) {
throw err;
}
cancellationSource.cancel();
}),
handlerPromise.then(result => {
remotePromise.cancel();
return result;
}, err => {
remotePromise.cancel();
throw err;
})
]).then(([_, result]) => result, ([remoteErr, handlerErr]) => {
throw handlerErr || remoteErr;
});
}
}