From 17da1c12495d9e877bad80f04253d6234f2fd881 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Sun, 5 Jan 2025 14:23:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20netlist=20=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=B7=B3=E8=BD=AC=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/function/dide-netlist/api.ts | 40 ++++++++++++++++++++++++++++++ src/function/dide-netlist/index.ts | 5 +++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/function/dide-netlist/api.ts b/src/function/dide-netlist/api.ts index 74f9f2f..f7ee665 100644 --- a/src/function/dide-netlist/api.ts +++ b/src/function/dide-netlist/api.ts @@ -114,6 +114,46 @@ export async function saveAsPdf(data: any, panel: vscode.WebviewPanel) { } } +export async function gotoDefinition(data: any, panel: vscode.WebviewPanel) { + try { + const { defs } = data; + if (defs.length === 0) { + return; + } + + const { path, range } = defs[0]; + const uri = vscode.Uri.file(getRealPath(path)); + await vscode.commands.executeCommand('vscode.open', uri, { + selection: new vscode.Range( + new vscode.Position(range.start.line, range.end.character), + new vscode.Position(range.end.line, range.end.character) + ) + }); + + panel.webview.postMessage({ + command: 'goto-definition', + arguments: [{ success: false }] + }); + } catch (error) { + console.log('error happen in /goto-definition, ' + error); + panel.webview.postMessage({ + command: 'goto-definition', + arguments: [{ success: false }] + }); + } +} + +function getRealPath(path: string) { + path = hdlPath.toSlash(path); + if (path.startsWith('/')) { + path = path.substring(1); + } + path = path + .replace('{workspace}', opeParam.workspacePath) + .replace('{library}', opeParam.prjInfo.libCommonPath); + return path; +} + async function html2pdf(htmlPath: string, pdfPath: string, moduleName: string, width: number, height: number) { const browserPath = getDefaultBrowerPath(); const browser = await puppeteer.launch({ diff --git a/src/function/dide-netlist/index.ts b/src/function/dide-netlist/index.ts index ad4ea9c..a0ce67c 100644 --- a/src/function/dide-netlist/index.ts +++ b/src/function/dide-netlist/index.ts @@ -12,7 +12,7 @@ import { t } from '../../i18n'; import { HdlLangID } from '../../global/enum'; import { getIconConfig } from '../../hdlFs/icons'; import { PathSet } from '../../global/util'; -import { saveAsPdf, saveAsSvg } from './api'; +import { gotoDefinition, saveAsPdf, saveAsSvg } from './api'; type SynthMode = 'before' | 'after' | 'RTL'; @@ -313,6 +313,9 @@ function registerMessageEvent(panel: vscode.WebviewPanel) { case 'save-as-pdf': saveAsPdf(data, panel); break; + case 'goto-definition': + gotoDefinition(data, panel); + break; default: break; }