From 9c787627a97c0eeaae78d63ec99638d43d0700c7 Mon Sep 17 00:00:00 2001 From: Roe-xin Date: Wed, 24 Dec 2025 12:00:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=9E=E7=8E=B0=E5=B7=B2=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E4=BB=BF=E7=9C=9F=E4=B9=8B=E5=90=8E=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=B3=A2=E5=BD=A2=E9=A2=84=E8=A7=88=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=B1=95=E7=A4=BA=E6=B3=A2=E5=BD=A2=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/messageArea.ts | 44 +++++++++++++++++++++++++++++++++++++ src/views/webviewContent.ts | 23 ++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/views/messageArea.ts b/src/views/messageArea.ts index 3c5f4f2..f88f87f 100644 --- a/src/views/messageArea.ts +++ b/src/views/messageArea.ts @@ -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 ? \`\` : ''} \`; + // 如果是仿真工具且成功完成,尝试添加波形预览 + 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 ? \`\` : ''} \`; + // 如果是仿真工具且成功完成,尝试添加波形预览 + 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()} `; } diff --git a/src/views/webviewContent.ts b/src/views/webviewContent.ts index 8918208..c3e321a 100644 --- a/src/views/webviewContent.ts +++ b/src/views/webviewContent.ts @@ -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':