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; }