Skip to content

Instantly share code, notes, and snippets.

@ecool
Last active January 13, 2021 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecool/5d5042162194989772e50a0d15432489 to your computer and use it in GitHub Desktop.
Save ecool/5d5042162194989772e50a0d15432489 to your computer and use it in GitHub Desktop.
import * as vscode from 'vscode';
export async function quickPickItem(items: string[]): Promise<string[]> {
const options = items.map(item => ({ label: item }));
return new Promise((resolve, _) => {
const quickPick = vscode.window.createQuickPick();
const placeholder = "Select a item.";
quickPick.placeholder = placeholder;
quickPick.items = options;
quickPick.canSelectMany = true;
let selectedItems = [];
quickPick.onDidChangeSelection((selected) => {
selectedItems = selected; // string[]
});
quickPick.onDidAccept(_ => {
// workaround for no activeItems when canSelectMany is true
resolve(selectedItems);
quickPick.hide();
});
quickPick.onDidHide(_ => quickPick.dispose());
quickPick.show();
});
}
async function example() {
const result = await quickPickItem(['one', 'two', 'three']);
console.log(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment