Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arguments for Commands in VS Code

So obviously there are arguments for commands and registering a command like

vscode.commands.registerCommand("bla", (arg1: any, arg2: any) => {});

brings arg1 with a strange object containing only one key and that's context; an object holding some information about - you guessed it - the context.

There is also no way for the user to specify arguments. Not through the command palette and not for keybindings.

So are those arguments only for internal stuff or are they supposed to be used by an extension developer?

like image 465
Databyte Avatar asked Jan 15 '16 11:01

Databyte


People also ask

How do you give command-line arguments in VS Code?

To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.

How do you write a VS Code command?

Ctrl+Shift+P > Multi command > custom command .

How do you see all commands in VS Code?

Note: You can review the full set of VS Code commands via the Keyboard Shortcuts editor File > Preferences > Keyboard Shortcuts (on macOS Code > Preferences > Keyboard Shortcuts).

How do I pass command-line arguments to Python from VS in Debug mode?

Go to your project properties, either by right-clicking on the project and picking "Properties" or by picking Properties from the Project menu. Click on Debug, then enter your arguments into the "Script Arguments" field. Save.


1 Answers

In keybindings.json you can specify arguments as such:

{
    "command": "workbench.action.tasks.runTask",
    "key": "alt+d",
    "args": "docker"
}

To access keybindings.json open View > Command Palette and type/choose Preferences: Open Keyboard Shortcuts (JSON). You may also want to assign a keyboard shortcut to this command.

like image 162
Michael Liquori Avatar answered Oct 11 '22 09:10

Michael Liquori