diff --git a/css/documentation.css b/css/documentation.css index eb1f52a..c4cf9e5 100644 --- a/css/documentation.css +++ b/css/documentation.css @@ -570,17 +570,17 @@ img { } .diagram-container .i-port-name { - font-size: 16px; + font-size: 18px; padding: 3px 8px; } .diagram-container .o-port-name { - font-size: 16px; + font-size: 18px; padding: 3px 8px; } .diagram-container .io-port-name { - font-size: 16px; + font-size: 18px; padding: 3px 8px; } @@ -605,12 +605,14 @@ img { .diagram-container .port-width-left-caption { position: absolute; - margin: -10px 35px; + margin: -5px 10px; + font-size: 14px; } .diagram-container .port-width-right-caption { position: absolute; - margin: -10px 10px; + margin: -5px 10px; + font-size: 14px; } .vscode-dark .diagram-container { diff --git a/images/svg/dark/left-arrow.svg b/images/svg/dark/left-arrow.svg index b89500f..e182f33 100644 --- a/images/svg/dark/left-arrow.svg +++ b/images/svg/dark/left-arrow.svg @@ -4,7 +4,7 @@ - \ No newline at end of file diff --git a/images/svg/dark/left-right-arrow.svg b/images/svg/dark/left-right-arrow.svg index 239d918..212f3e9 100644 --- a/images/svg/dark/left-right-arrow.svg +++ b/images/svg/dark/left-right-arrow.svg @@ -4,9 +4,9 @@ - - \ No newline at end of file diff --git a/images/svg/dark/right-arrow.svg b/images/svg/dark/right-arrow.svg index 59c4b1a..25df4be 100644 --- a/images/svg/dark/right-arrow.svg +++ b/images/svg/dark/right-arrow.svg @@ -4,7 +4,7 @@ - \ No newline at end of file diff --git a/images/svg/dark/right-dot-arrow.svg b/images/svg/dark/right-dot-arrow.svg index e4df021..8f6c7d4 100644 --- a/images/svg/dark/right-dot-arrow.svg +++ b/images/svg/dark/right-dot-arrow.svg @@ -4,9 +4,9 @@ - - \ No newline at end of file diff --git a/images/svg/light/left-arrow.svg b/images/svg/light/left-arrow.svg index b5576cd..425f13f 100644 --- a/images/svg/light/left-arrow.svg +++ b/images/svg/light/left-arrow.svg @@ -4,7 +4,7 @@ - \ No newline at end of file diff --git a/images/svg/light/left-right-arrow.svg b/images/svg/light/left-right-arrow.svg index f7cc752..e42fcdd 100644 --- a/images/svg/light/left-right-arrow.svg +++ b/images/svg/light/left-right-arrow.svg @@ -4,9 +4,9 @@ - - \ No newline at end of file diff --git a/images/svg/light/right-arrow.svg b/images/svg/light/right-arrow.svg index 8e87cb2..7205d3e 100644 --- a/images/svg/light/right-arrow.svg +++ b/images/svg/light/right-arrow.svg @@ -4,7 +4,7 @@ - \ No newline at end of file diff --git a/images/svg/light/right-dot-arrow.svg b/images/svg/light/right-dot-arrow.svg index 878c5b5..35f3a68 100644 --- a/images/svg/light/right-dot-arrow.svg +++ b/images/svg/light/right-dot-arrow.svg @@ -4,9 +4,9 @@ - - \ No newline at end of file diff --git a/package.json b/package.json index 2572b2e..ed1cb5e 100644 --- a/package.json +++ b/package.json @@ -748,6 +748,18 @@ } ] }, + "customEditors": [ + { + "viewType": "digital-ide.vcd.viewer", + "displayName": "Digital Viewer", + "selector": [ + { + "filenamePattern": "*.vcd" + } + ], + "priority": "default" + } + ], "viewsContainers": { "activitybar": [ { diff --git a/src/function/dide-viewer/index.ts b/src/function/dide-viewer/index.ts index 96849e4..a00e39d 100644 --- a/src/function/dide-viewer/index.ts +++ b/src/function/dide-viewer/index.ts @@ -4,6 +4,18 @@ import * as fspath from 'path'; import { hdlFile, hdlPath } from '../../hdlFs'; import { opeParam, ReportType, WaveViewOutput } from '../../global'; +function getWebviewContent(panel?: vscode.WebviewPanel): string | undefined { + const dideviewerPath = hdlPath.join(opeParam.extensionPath, 'resources', 'dide-viewer', 'view'); + const htmlIndexPath = hdlPath.join(dideviewerPath, 'index.html'); + const html = hdlFile.readFile(htmlIndexPath)?.replace(/( { + const absLocalPath = fspath.resolve(dideviewerPath, $2); + const webviewUri = panel?.webview.asWebviewUri(vscode.Uri.file(absLocalPath)); + const replaceHref = $1 + webviewUri?.toString() + '"'; + return replaceHref; + }); + return html; +} + class WaveViewer { context: vscode.ExtensionContext; panel?: vscode.WebviewPanel; @@ -36,7 +48,7 @@ class WaveViewer { console.log(message); }, null, this.context.subscriptions); - const previewHtml = this.getWebviewContent(); + const previewHtml = getWebviewContent(this.panel); if (this.panel && previewHtml) { const dideviewerPath = hdlPath.join(opeParam.extensionPath, 'resources', 'dide-viewer', 'view'); const workerAbsPath = hdlPath.join(dideviewerPath, 'worker.js'); @@ -62,18 +74,6 @@ class WaveViewer { }); } - - public getWebviewContent(): string | undefined { - const dideviewerPath = hdlPath.join(opeParam.extensionPath, 'resources', 'dide-viewer', 'view'); - const htmlIndexPath = hdlPath.join(dideviewerPath, 'index.html'); - const html = hdlFile.readFile(htmlIndexPath)?.replace(/( { - const absLocalPath = fspath.resolve(dideviewerPath, $2); - const webviewUri = this.panel?.webview.asWebviewUri(vscode.Uri.file(absLocalPath)); - const replaceHref = $1 + webviewUri?.toString() + '"'; - return replaceHref; - }); - return html; - } } async function openWaveViewer(context: vscode.ExtensionContext, uri: vscode.Uri) { @@ -81,6 +81,83 @@ async function openWaveViewer(context: vscode.ExtensionContext, uri: vscode.Uri) viewer.open(uri); } +class VcdViewerDocument implements vscode.CustomDocument { + uri: vscode.Uri; + constructor(uri: vscode.Uri) { + this.uri = uri; + } + dispose(): void { + + } +} + +class VcdViewerProvider implements vscode.CustomEditorProvider { + private readonly _onDidChangeCustomDocument = new vscode.EventEmitter>(); + public readonly onDidChangeCustomDocument = this._onDidChangeCustomDocument.event; + + async resolveCustomEditor(document: VcdViewerDocument, webviewPanel: vscode.WebviewPanel, token: vscode.CancellationToken) { + webviewPanel.webview.options = { + enableScripts: true, + enableForms: true, + }; + + webviewPanel.onDidDispose(() => { + webviewPanel.dispose(); + }, null); + + webviewPanel.webview.onDidReceiveMessage(message => { + console.log(message); + }, null); + + const previewHtml = getWebviewContent(webviewPanel); + + if (webviewPanel && previewHtml) { + const dideviewerPath = hdlPath.join(opeParam.extensionPath, 'resources', 'dide-viewer', 'view'); + const workerAbsPath = hdlPath.join(dideviewerPath, 'worker.js'); + const webviewUri = webviewPanel.webview.asWebviewUri(document.uri); + const workerUri = webviewPanel.webview.asWebviewUri(vscode.Uri.file(workerAbsPath)); + const workerRootUri = webviewPanel.webview.asWebviewUri(vscode.Uri.file(dideviewerPath)); + + let preprocessHtml = previewHtml + .replace('test.vcd', webviewUri.toString()) + .replace('worker.js', workerUri.toString()) + .replace('', workerRootUri.toString()); + webviewPanel.webview.html = preprocessHtml; + + const iconPath = hdlPath.join(opeParam.extensionPath, 'images', 'icon.svg'); + webviewPanel.iconPath = vscode.Uri.file(iconPath); + } else { + WaveViewOutput.report('preview html in is empty', ReportType.Warn); + } + } + + openCustomDocument(uri: vscode.Uri, openContext: vscode.CustomDocumentOpenContext, token: vscode.CancellationToken): VcdViewerDocument | Thenable { + const document = new VcdViewerDocument(uri); + return document; + } + + async revertCustomDocument(document: VcdViewerDocument, cancellation: vscode.CancellationToken): Promise { + return; + } + + async saveCustomDocument(document: VcdViewerDocument, cancellation: vscode.CancellationToken): Promise { + + } + + + async saveCustomDocumentAs(document: VcdViewerDocument, destination: vscode.Uri, cancellation: vscode.CancellationToken): Promise { + + } + + + async backupCustomDocument(document: VcdViewerDocument, context: vscode.CustomDocumentBackupContext, cancellation: vscode.CancellationToken): Promise { + + } +} + +const vcdViewerProvider = new VcdViewerProvider(); + export { - openWaveViewer + openWaveViewer, + vcdViewerProvider }; \ No newline at end of file diff --git a/src/function/hdlDoc/diagram.ts b/src/function/hdlDoc/diagram.ts index 191973c..3730e92 100644 --- a/src/function/hdlDoc/diagram.ts +++ b/src/function/hdlDoc/diagram.ts @@ -80,8 +80,8 @@ function makeDiagramPortWrapper(ports: HdlModulePort[]): string { const leftPorts = ports.filter(port => port.type === HdlModulePortType.Input || port.type === HdlModulePortType.Inout); const rightPorts = ports.filter(port => port.type === HdlModulePortType.Output); - const leftDirection = makeLeftDirection(leftPorts); - const diagramPorts = makeDiagramPorts(leftPorts, rightPorts); + const leftDirection = makeLeftDirection(leftPorts); + const diagramPorts = makeDiagramPorts(leftPorts, rightPorts); const rightDirection = makeRightDirection(rightPorts); const diagramPortWrapper = `
${leftDirection}${diagramPorts}${rightDirection}
`; @@ -177,7 +177,7 @@ function makeDiagramPorts(leftPorts: HdlModulePort[], rightPorts: HdlModulePort[ diagramePorts += diagramPortItem; } while (rightIndex < rightPorts.length) { - const rightPortName = makePortName(leftPorts[leftIndex ++]); + const rightPortName = makePortName(rightPorts[rightIndex ++]); const diagramPortItem = `
${rightPortName}
`; diagramePorts += diagramPortItem; } @@ -185,7 +185,7 @@ function makeDiagramPorts(leftPorts: HdlModulePort[], rightPorts: HdlModulePort[ } function makeRightDirection(rightPorts: HdlModulePort[]): string { - let rightDirection = ''; + let rightDirection = ''; for (const port of rightPorts) { const portCaption = makePortCaption(port, 'right'); let portArrow = makePortArrow(port, 'right'); diff --git a/src/function/hdlDoc/html.ts b/src/function/hdlDoc/html.ts index d03a131..99c7b5e 100644 --- a/src/function/hdlDoc/html.ts +++ b/src/function/hdlDoc/html.ts @@ -104,6 +104,7 @@ function makeWavedromRenderErrorHTML() { * @param usage in whick module is used */ async function makeShowHTML(usage: 'webview' | 'pdf' | 'html' | 'markdown'): Promise { + // start to render the real html let body = ''; const userStyle = (usage === 'webview' || usage === 'markdown') ? undefined : ThemeType.Light; @@ -113,7 +114,7 @@ async function makeShowHTML(usage: 'webview' | 'pdf' | 'html' | 'markdown'): Pro if (!renderList || renderList.length === 0) { return ''; } - + for (const r of renderList) { const renderResult = r.render(); if (renderResult) { diff --git a/src/function/hdlDoc/markdown.ts b/src/function/hdlDoc/markdown.ts index 11bfe2d..d9877aa 100644 --- a/src/function/hdlDoc/markdown.ts +++ b/src/function/hdlDoc/markdown.ts @@ -48,13 +48,15 @@ function selectFieldValue(obj: any, subName: string, ws: string, name: string): function makeTableFromObjArray(md: MarkdownString, array: any[], name: string, fieldNames: string[], displayNames: string[]) { const ws = hdlPath.toSlash(opeParam.workspacePath) + '/'; + console.log('enter showhtml'); + if (array.length === 0) { md.addText(`no ${name} info`); } else { const rows = []; for (const obj of array) { const data = []; - for (const subName of fieldNames) { + for (const subName of fieldNames) { const value = selectFieldValue(obj, subName, ws, name); data.push(value); } @@ -97,7 +99,7 @@ async function patchComment(path: AbsPath, ports: (HdlModulePort | HdlModulePara async function getDocsFromModule(module: HdlModule): Promise { const moduleName = module.name; const portNum = module.ports.length; - const paramNum = module.params.length; + const paramNum = module.params.length; // add desc can optimizer in the future version const paramPP = patchComment(module.path, module.params); diff --git a/src/function/index.ts b/src/function/index.ts index 35736f2..694a8c6 100644 --- a/src/function/index.ts +++ b/src/function/index.ts @@ -119,6 +119,14 @@ function registerNetlist(context: vscode.ExtensionContext) { function registerWaveViewer(context: vscode.ExtensionContext) { vscode.commands.registerCommand('digital-ide.waveviewer.show', uri => WaveView.openWaveViewer(context, uri)); + vscode.window.registerCustomEditorProvider('digital-ide.vcd.viewer', WaveView.vcdViewerProvider, + { + webviewOptions: { + retainContextWhenHidden: true, + }, + supportsMultipleEditorsPerDocument: false + } + ); } export { diff --git a/src/global/util.ts b/src/global/util.ts index 7a17ace..2ec4a7a 100644 --- a/src/global/util.ts +++ b/src/global/util.ts @@ -1,4 +1,5 @@ import * as fs from 'fs'; +import * as vscode from 'vscode'; import * as childProcess from 'child_process'; import { AbsPath } from "."; @@ -59,10 +60,43 @@ async function easyExec(executor: string, args: string[]): Promise(); + /** + * Get all known webviews for a given uri. + */ + public *get(uri: vscode.Uri): Iterable { + const key = uri.toString(); + for (const entry of this._webviews) { + if (entry.resource === key) { + yield entry.webviewPanel; + } + } + } + + /** + * Add a new webview to the collection. + */ + public add(uri: vscode.Uri, webviewPanel: vscode.WebviewPanel) { + const entry = { resource: uri.toString(), webviewPanel }; + this._webviews.add(entry); + + webviewPanel.onDidDispose(() => { + this._webviews.delete(entry); + }); + } +} export { PathSet, isSameSet, - easyExec + easyExec, + WebviewCollection }; \ No newline at end of file diff --git a/src/hdlParser/core.ts b/src/hdlParser/core.ts index 9f1d522..4546ae8 100644 --- a/src/hdlParser/core.ts +++ b/src/hdlParser/core.ts @@ -477,7 +477,6 @@ class HdlModule { public createHdlInstance(rawHdlInstance: common.RawHdlInstance): HdlInstance { const instModName = rawHdlInstance.type; - if (this.languageId === HdlLangID.Verilog || this.languageId === HdlLangID.SystemVerilog) { const searchResult = this.searchInstModPath(instModName); const hdlInstance = new HdlInstance(rawHdlInstance.name, @@ -525,7 +524,11 @@ class HdlModule { } } - public makeNameToInstances() { + public makeNameToInstances() { + if (this.name === 'u_reg_cfg') { + console.log('[u_reg_cfg debug]'); + console.log(this.rawInstances); + } if (this.rawInstances !== undefined) { this.nameToInstances.clear(); for (const inst of this.rawInstances) {