支持 Unix 上 wave 的显示

This commit is contained in:
锦恢 2024-10-23 12:37:26 +08:00
parent 473207b78b
commit 57d63f3b05
2 changed files with 14 additions and 11 deletions

View File

@ -3,6 +3,8 @@ import * as vscode from 'vscode';
import * as url from 'url';
import { BSON } from 'bson';
import * as path from 'path';
import * as os from 'os';
import { getIconConfig } from '../../hdlFs/icons';
export interface SaveViewData {
originVcdFile: string,
@ -34,9 +36,11 @@ function extractFilepath(webviewUri: string) {
}
const parsedUrl = new url.URL(webviewUri);
const pathname = decodeURIComponent(parsedUrl.pathname);
if (pathname.startsWith('/')) {
const platform = os.platform();
if (platform === 'win32' && pathname.startsWith('/')) {
return pathname.slice(1);
}
return pathname;
}
@ -106,6 +110,9 @@ export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.Webvi
const buffer = BSON.serialize(originPayload);
fs.writeFileSync(savePath, buffer);
panel.title = path.basename(savePath);
panel.iconPath = getIconConfig('view');
// 创建新的缓存 savePath 会成为新的 originVcdViewFile
mergePayloadCache(savePath, payload);
@ -153,6 +160,9 @@ export async function loadView(data: any, uri: vscode.Uri, panel: vscode.Webview
if (viewUri) {
const viewPath = viewUri[0].fsPath;
const buffer = fs.readFileSync(viewPath);
panel.title = path.basename(viewPath);
panel.iconPath = getIconConfig('view');
const recoverJson = BSON.deserialize(buffer);
panel.webview.postMessage({
command: 'load-view',

View File

@ -6,6 +6,7 @@ import { hdlFile, hdlPath } from '../../hdlFs';
import { opeParam, ReportType, WaveViewOutput } from '../../global';
import { LaunchFiles, loadView, saveView, saveViewAs } from './api';
import { BSON } from 'bson';
import { getIconConfig } from '../../hdlFs/icons';
function getWebviewContent(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel): string | undefined {
const dideviewerPath = hdlPath.join(context.extensionPath, 'resources', 'dide-viewer', 'view');
@ -49,10 +50,6 @@ class WaveViewer {
this.panel = undefined;
}, null, this.context.subscriptions);
this.panel.webview.onDidReceiveMessage(message => {
console.log(message);
}, null, this.context.subscriptions);
const context = this.context;
const previewHtml = getWebviewContent(context, this.panel);
if (this.panel && previewHtml) {
@ -69,9 +66,7 @@ class WaveViewer {
.replace('worker.js', worker)
.replace('<root>', root);
this.panel.webview.html = preprocessHtml;
const iconPath = hdlPath.join(context.extensionPath, 'images', 'icon.svg');
this.panel.iconPath = vscode.Uri.file(iconPath);
this.panel.iconPath = getIconConfig('view');
registerMessageEvent(this.panel, uri);
} else {
WaveViewOutput.report('preview html in <WaveViewer.create> is empty', ReportType.Warn);
@ -137,9 +132,7 @@ class VcdViewerProvider implements vscode.CustomEditorProvider {
.replace('worker.js', worker)
.replace('<root>', root);
webviewPanel.webview.html = preprocessHtml;
const iconPath = hdlPath.join(context.extensionPath, 'images', 'icon.svg');
webviewPanel.iconPath = vscode.Uri.file(iconPath);
webviewPanel.iconPath = getIconConfig('view');
} else {
WaveViewOutput.report('preview html in <WaveViewer.create> is empty', ReportType.Warn);
}