feat:实现已完成仿真之后直接调用波形预览组件展示波形预览图

This commit is contained in:
Roe-xin
2025-12-24 12:00:03 +08:00
parent 463eedf1dd
commit 9c787627a9
2 changed files with 66 additions and 1 deletions

View File

@ -16,6 +16,10 @@ import {
syntaxCheckIconSvg,
SearchCode,
} from "../constants/toolIcons";
import {
getWaveformPreviewContent,
getWaveformPreviewScript,
} from "./waveformPreviewContent";
/**
* 获取消息区域的 HTML 内容
@ -523,6 +527,8 @@ export function getMessageAreaStyles(): string {
color: var(--vscode-button-secondaryForeground);
border-radius: 4px;
font-size: 12px;}
${getWaveformPreviewContent()}
`;
}
@ -783,6 +789,24 @@ export function getMessageAreaScript(): string {
\${shouldCollapse ? \`<div class="tool-segment-content collapsed"><span class="tool-segment-result" style="display:block;white-space:pre-wrap;max-width:100%;margin-top:8px;margin-left:18px;">\${toolResult}</span></div>\` : ''}
\`;
// 如果是仿真工具且成功完成,尝试添加波形预览
if (segment.toolName === 'simulation' && segment.toolStatus === 'success') {
// 优先使用显式提供的路径,否则从结果文本中解析
let vcdPath = segment.vcdFilePath;
if (!vcdPath && segment.toolResult) {
const match = String(segment.toolResult).match(/路径\s*:\s*(.+)/);
if (match && match[1]) {
vcdPath = match[1].trim();
}
}
if (vcdPath) {
const fileName = segment.fileName || vcdPath.split(/[\\\\\/]/).pop() || 'waveform.vcd';
const waveformPreview = createWaveformPreview(vcdPath, fileName);
segmentDiv.appendChild(waveformPreview);
}
}
// 添加折叠/展开事件监听
if (shouldCollapse) {
setTimeout(() => {
@ -963,6 +987,24 @@ export function getMessageAreaScript(): string {
\${shouldCollapse ? \`<div class="tool-segment-content collapsed"><span class="tool-segment-result" style="display:block;white-space:pre-wrap;max-width:100%;margin-top:8px;margin-left:18px;">\${toolResult}</span></div>\` : ''}
\`;
// 如果是仿真工具且成功完成,尝试添加波形预览
if (segment.toolName === 'simulation' && segment.toolStatus === 'success') {
// 优先使用显式提供的路径,否则从结果文本中解析
let vcdPath = segment.vcdFilePath;
if (!vcdPath && segment.toolResult) {
const match = String(segment.toolResult).match(/路径\s*:\s*(.+)/);
if (match && match[1]) {
vcdPath = match[1].trim();
}
}
if (vcdPath) {
const fileName = segment.fileName || vcdPath.split(/[\\\\\/]/).pop() || 'waveform.vcd';
const waveformPreview = createWaveformPreview(vcdPath, fileName);
segmentDiv.appendChild(waveformPreview);
}
}
// 添加折叠/展开事件监听
if (shouldCollapse) {
setTimeout(() => {
@ -1218,5 +1260,7 @@ export function getMessageAreaScript(): string {
customInput: answer
});
}
${getWaveformPreviewScript()}
`;
}

View File

@ -484,9 +484,30 @@ export function getWebviewContent(iconUri?: string): string {
hideLoadingIndicator();
break;
case 'vcdInfo':
// 渲染迷你波形预览信息
try {
if (message.containerId && typeof renderWaveformInfo === 'function') {
renderWaveformInfo(message.containerId, message.vcdInfo || {});
}
} catch (e) {
console.warn('[WebView] 渲染波形信息失败:', e);
}
break;
case 'vcdGenerated':
// VCD 文件生成成功
// VCD 文件生成成功,添加消息并附带波形预览
addMessage(message.text, 'bot');
try {
if (message.vcdFilePath) {
const lastMsg = messagesEl ? messagesEl.lastElementChild : null;
if (lastMsg && typeof addWaveformPreviewToMessage === 'function') {
addWaveformPreviewToMessage(lastMsg, message.vcdFilePath, message.fileName || 'waveform.vcd');
}
}
} catch (e) {
console.warn('[WebView] 添加波形预览失败:', e);
}
break;
case 'fileContent':