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':