docs: 完善 Vivado 联动文档

- 添加后端工具调用控制前端的详细说明
   - 新增 mode 参数(batch/gui)支持批处理和图形界面模式
   - 补充参数询问流程和验证规则
   - 添加完整实现示例:生成比特流和布局布线
   - 更新所有调用示例包含必需参数
This commit is contained in:
Roe-xin
2026-03-16 14:05:34 +08:00
parent 0ae627ca7c
commit aa80088abc
3 changed files with 342 additions and 35 deletions

View File

@ -548,8 +548,19 @@ import { runVivado } from './vivadoRunner';
export async function handleVivadoTool(
panel: vscode.WebviewPanel,
toolCall: any
): Promise<void> {
const { command, topModule, files, constraints } = toolCall.parameters;
): Promise<VivadoToolResponse> {
const { command, topModule, files, constraints, part } = toolCall.parameters;
// 验证必需参数
if (!part) {
return {
success: false,
command,
executionTime: 0,
output: '',
error: '缺少必需参数芯片型号part'
};
}
// 构建请求
const request: VivadoToolRequest = {
@ -557,7 +568,8 @@ export async function handleVivadoTool(
parameters: {
topModule,
files,
constraints
constraints,
part
},
importOutput: {
enabled: true,
@ -585,6 +597,53 @@ export async function handleVivadoTool(
type: 'vivado-complete',
response
});
// 返回结果给后端
return response;
}
```
### 3.6 参数验证和处理
```typescript
// src/utils/vivadoValidator.ts
export interface ValidationResult {
valid: boolean;
error?: string;
}
export function validateVivadoRequest(request: VivadoToolRequest): ValidationResult {
const { command, parameters } = request;
// 验证命令类型
if (!['synthesis', 'implementation', 'bitstream'].includes(command)) {
return { valid: false, error: `无效的命令类型: ${command}` };
}
// 验证必需参数
if (!parameters?.topModule) {
return { valid: false, error: '缺少顶层模块名topModule' };
}
if (!parameters?.part) {
return { valid: false, error: '缺少芯片型号part' };
}
// 验证芯片型号格式
const partPattern = /^xc[0-9a-z]+$/i;
if (!partPattern.test(parameters.part)) {
return { valid: false, error: `芯片型号格式不正确: ${parameters.part}` };
}
// 综合命令需要文件列表
if (command === 'synthesis') {
if (!parameters?.files || parameters.files.length === 0) {
return { valid: false, error: '综合命令需要提供源文件列表' };
}
}
return { valid: true };
}
```