我正在编写一个 VSC 插件,在激活时,我想进行 XHR 调用,然后使用该 XHR 的结果填充菜单。似乎没有办法动态地将菜单添加到状态栏或将动态项目添加到项目列表。
你不能那样做。所有命令必须预先定义在package.json
因为它的声明式方法.
但是,您可以模仿这种行为。为此,您必须使用vscode.window.showQuickPick
API,添加您从 XHR 调用收到的项目。一个很好的例子动态方法 is MDTools 扩展.
另外,还有一个示例代码可供您开始:
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;
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)