Reputation: 7863
I'm authoring a VSC plugin that on activation, I would like to make an XHR call and then populate a menu with the results of that XHR. It doesn't seem like there is a way to dynamically add menus to the status bar or dynamic items to the list of items.
Upvotes: 6
Views: 3981
Reputation: 3233
You can't do that. All commands must be pre-defined in package.json
because of its declarative approach.
You can however, mimic this behavior. To do this you must use the vscode.window.showQuickPick
API, adding the items that you received from your XHR call. A good example of this dynamic approach is MDTools extension.
Also, a sample code for you to start:
let items: vscode.QuickPickItem[] = [];
for (let index = 0; index < yourHXRResultItems.length; index++) {
let item = yourHXRResultItems[index];
items.push({
label: item.name,
description: item.moreDetailedInfo});
}
vscode.window.showQuickPick(items).then(selection => {
// the user canceled the selection
if (!selection) {
return;
}
// the user selected some item. You could use `selection.name` too
switch (selection.description) {
case "onItem":
doSomething();
break;
case "anotherItem":
doSomethingElse();
break;
//.....
default:
break;
}
});
Upvotes: 8