VSCode扩展可以调用命令 (参考:https://code.visualstudio.com/docs/extensionAPI/vscode-api)
executeCommand<T>(command: string, ...rest: any[]): Thenable<T | undefined>
如果API Doc正确,那么..
extension1 can call extension2's 'exCommand2'. and
extension2 can call extension1's 'exCommand1'.
有可能吗?
VSCode的扩展名为Lazy Loading ...
如果可以进行inter extension命令调用,那么如何将扩展加载到另一个扩展名?
答案 0 :(得分:8)
我知道这是一个老帖子,如果你仍然有相同的要求或其他人用谷歌搜索,这就是我做的。
var xmlExtension = vscode.extensions.getExtension( 'DotJoshJohnson.xml' );
// is the ext loaded and ready?
if( xmlExtension.isActive == false ){
xmlExtension.activate().then(
function(){
console.log( "Extension activated");
// comment next line out for release
findCommand();
vscode.commands.executeCommand("xmlTools.formatAsXml");
},
function(){
console.log( "Extension activation failed");
}
);
} else {
vscode.commands.executeCommand("xmlTools.formatAsXml");
}
// dev helper function to dump all the command identifiers to the console
// helps if you cannot find the command id on github.
var findCommand = function(){
vscode.commands.getCommands(true).then(
function(cmds){
console.log("fulfilled");
console.log(cmd);
},
function() {
console.log("failed");
console.log(arguments);
}
)
};