用途:该技能汇总 VS Code Chat API 的聊天参与者(Chat Participant)开发模式,供扩展开发者在实现聊天交互时参考。资料标注最后验证时间为 2026 年 2 月(VS Code 1.108+),并提示 Chat API、LM API、Tools API 会随 VS Code 版本演进,使用前应核对最新文档。
主要能力:在 package.json 的 contributes.chatParticipants 中声明参与者(id、name、fullName、description、isSticky、commands),在 activate() 中用 vscode.chat.createChatParticipant 创建并设置 iconPath;处理器签名为 ChatRequestHandler(request, context, stream, token)。流式操作包括 stream.markdown()、progress()、button()、filetree()、reference()、anchor();可读取 context.history、request.references、request.model、request.command、request.location。支持 MarkdownString 命令链接、文件树与引用输出。
LM 与工具:通过 vscode.lm.selectChatModels 选择模型并 sendRequest 流式返回;推荐使用 @vscode/chat-extension-utils 的 sendChatParticipantRequest 进行工具调用,工具经 vscode.lm.registerTool 注册并返回 LanguageModelToolResult。还包含 disambiguation 自动路由与 followupProvider 追问建议。
最佳实践:增量流式输出、响应 token 取消、捕获错误、长任务用 progress、每个扩展限一个参与者、高成本操作先征得同意。限制:资料未提供安装命令、收费与平台信息,具体 API 行为以官方文档为准。