Is it possible to call commands between extensions in VSCode?

后端 未结 1 699
花落未央
花落未央 2021-01-01 19:43

For example, there are two VSCode extensions:

  • extension1 has registered command exCommand1
  • extension2 has regis
相关标签:
1条回答
  • 2021-01-01 20:41

    I know this is an old post, if you still have the same requirement or for others googling, this is how I have done it.

    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);
            }
        )
    };
    
    0 讨论(0)
提交回复
热议问题