Document When Extension Commands Are Called With Arguments and What Those Arguments Are...
hi there :wave:
in certain circumstances commands provided by an extension are called with arguments. for example:
"editor/context": [
{
"command": "extension.myCommand",
"when": "resourceLangId == cpp",
"group": "my-tests"
}
]
within your extension manifest (package.json) creates a context menu item for myCommand. when a user invokes that menu item by right-clicking and selecting it from the context menu, myCommand is called with a single argument: the uri for the file where the context menu was clicked.
my understanding just from poking around is that commands exposed via explorer/context, editor/title, and editor/title/context have similar behavior (though in some cases they are called with more and / or different arguments).
it would be nice if all of these cases were documented - specifically: when a command will be called with additional arguments and what those arguments will be
thanks :pray::+1:
Hi @busticated I think this information is covered in the Contribution Points article in a Note for contributes.menu. https://code.visualstudio.com/api/references/contribution-points#contributes.menus. Are there other cases besides context menus where you've seen arguments being passed to commands?
hi @gregvanl thanks for taking a look 👍
if you are referring to:
Note: When a command is invoked from a (context) menu, VS Code tries to infer the currently selected resource and passes that as a parameter when invoking the command. For instance, a menu item inside the Explorer is passed the URI of the selected resource and a menu item inside an editor is passed the URI of the document.
i don't think that's sufficient. for one, there are different arguments provided depending on the contribution point. also, it's not clear that this is the only scenario where arguments are provided - e.g. keyboard shortcuts? command palette in special cases? other? 🤷♂️
edit
Are there other cases besides context menus where you've seen arguments being passed to commands?
missed this part, sorry. short answer is: i'm not sure.