Home > Software design >  Commands URIs pass parameters
Commands URIs pass parameters

Time:07-20

The following example. How to pass parameters to the corresponding command?

const commentCommandUri = vscode.Uri.parse(`command:editor.action.addCommentLine`);
const contents = new vscode.MarkdownString(`[Add comment](${commentCommandUri})`);
contents.isTrusted = true;

CodePudding user response:

The command editor.action.addCommentLine does not take any parameter. It simply comments the line that is selected currently in the editor (or the line where the cursor is positioned).

If you had another command that accepted arguments, then you could do something like this:

...
const arguments = [arg1, arg2];
const myCommandUri = Uri.parse(`command:myCommand?${encodeURIComponent(JSON.stringify(arguments))}`);
contents.appendMarkdown(`[Do something](${myCommandUri})`);
  • Related