2017-01-10 48 views
2

有兩個VSCode擴展名。
- extension1是註冊命令'exCommand1'。
- 擴展名2是註冊命令'exCommand2'。
是否可以在VSCode中的擴展之間調用命令?例如

VSCode擴展可以調用命令。
(參考:https://code.visualstudio.com/docs/extensionAPI/vscode-api

executeCommand<T>(command: string, ...rest: any[]): Thenable<T | undefined> 

如果API文檔是正確的,那麼..

extension1 can call extension2's 'exCommand2'. and 
extension2 can call extension1's 'exCommand1'. 

這可能嗎?

VSCode的擴展名是延遲加載...

如果間延伸的命令調用可能那麼如何才能加載擴展到另一分機?

回答

1

我知道這是一箇舊的帖子,如果你仍然有相同的要求或其他人使用Google,這是我已經做到了。

 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); 
       } 
      ) 
     }; 
相關問題