0

I'm learning VSCode extension development and want to run a command I defined from within the extension.

Here is my code:

const vscode = require('vscode');

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {

    console.log('Congratulations, your extension "cli-runner-by-blueray453" is now active!');

    const disposable = vscode.commands.registerCommand('extension.cli-runner-by-blueray453', function () {
        vscode.window.showInformationMessage('Hello World from cli-runner-by-blueray453!');
    });

    context.subscriptions.push(disposable);

    setTimeout(() => {
        vscode.commands.executeCommand('extension.cli-runner-by-blueray453');
    }, 3000);
}

function deactivate() {
    console.log('CLI Runner extension deactivated.');
}

module.exports = {
    activate,
    deactivate
}

However, After 3 seconds, the command does not display the information message window.

What is the proper way to programmatically trigger a command and see its UI effects during development?

20
  • Yes, vscode.commands.registerCommand is the right way to deal with the commands. Why would you ever call your setTimeout with vscode.commands.executeCommand from activate?! What makes you thinking it makes any sense? Does your command work in the intended way (F1, and so on)? Commented 2 days ago
  • Also, what's wrong with the development? Are you executing your extension under the debugger? Commented 2 days ago
  • Yes the command shows the window with F1. Commented 2 days ago
  • Then you have all you need. Don't do this setTimeout. The purpose of vscode.commands.executeCommand is to reuse command execution in other methods, for example, in the implementations of other commands. Not to call it from exported activate when the registration is not yet complete. Why? Why?! Commented 2 days ago
  • 1
    Okay, thank you for the answer. Commented yesterday

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.