Skip to content

Commit 900f1be

Browse files
authored
Chat API: command links with arguments (#7645)
* Add info about command args * Add code comment
1 parent 57520f8 commit 900f1be

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

api/extension-guides/chat.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ The following list provides the output types for a chat response in the Chat vie
312312
stream.markdown(markdownCommandString);
313313
```
314314

315+
If the command takes arguments, you need to first JSON encode the arguments and then encode the JSON string as a URI component. You then append the encoded arguments as a query string to the command link.
316+
317+
```typescript
318+
// Encode the command arguments
319+
const encodedArgs = encodeURIComponent(JSON.stringify(args));
320+
321+
// Use command URIs with arguments to link to commands from Markdown
322+
let markdownCommandString: vscode.MarkdownString = new vscode.MarkdownString(`[Use cat names](command:${CAT_NAMES_COMMAND_ID}?${encodedArgs})`);
323+
markdownCommandString.isTrusted = { enabledCommands: [ CAT_NAMES_COMMAND_ID ] };
324+
325+
stream.markdown(markdownCommandString);
326+
```
327+
315328
- **Command button**
316329

317330
Render a button that invokes a VS Code command. The command can be a built-in command or one that you define in your extension. Use the [`ChatResponseStream.button`](/api/references/vscode-api#ChatResponseStream.button) method and provide the button text and command ID.

0 commit comments

Comments
 (0)