From dd3732129525db23ed092ccd3e4c3cb05f699465 Mon Sep 17 00:00:00 2001
From: LSTM-Kirigaya <1193466151@qq.com>
Date: Tue, 24 Sep 2024 14:38:34 +0800
Subject: [PATCH] support i18n
---
images/svg/dark/export.svg | 1 +
images/svg/light/export.svg | 1 +
l10n/bundle.l10n.en.json | 9 ++++++++
l10n/bundle.l10n.zh-cn.json | 9 ++++++++
l10n/bundle.l10n.zh-tw.json | 9 ++++++++
package.json | 27 +++++++++++++++++++---
package.nls.json | 3 ++-
package.nls.zh-cn.json | 9 ++++----
package.nls.zh-tw.json | 9 ++++----
src/extension.ts | 15 ++++++------
src/function/index.ts | 3 +++
src/function/tool.ts | 46 +++++++++++++++++++++++++++++++++++--
src/hdlParser/core.ts | 44 +++++++++++++++++++++++++++++++----
src/hdlParser/util.ts | 1 -
src/manager/prj.ts | 27 +++++++++++++++++++++-
src/monitor/event.ts | 11 +++++----
16 files changed, 192 insertions(+), 32 deletions(-)
create mode 100644 images/svg/dark/export.svg
create mode 100644 images/svg/light/export.svg
create mode 100644 l10n/bundle.l10n.en.json
create mode 100644 l10n/bundle.l10n.zh-cn.json
create mode 100644 l10n/bundle.l10n.zh-tw.json
diff --git a/images/svg/dark/export.svg b/images/svg/dark/export.svg
new file mode 100644
index 0000000..e1b051f
--- /dev/null
+++ b/images/svg/dark/export.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/images/svg/light/export.svg b/images/svg/light/export.svg
new file mode 100644
index 0000000..065e63f
--- /dev/null
+++ b/images/svg/light/export.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/l10n/bundle.l10n.en.json b/l10n/bundle.l10n.en.json
new file mode 100644
index 0000000..dd7bf7d
--- /dev/null
+++ b/l10n/bundle.l10n.en.json
@@ -0,0 +1,9 @@
+{
+ "hello": "hello in English",
+ "welcome.title": "Thanks for using Digital-IDE ❤️. Your star will be our best motivation! 😊",
+ "welcome.star": "Star",
+ "welcome.refuse": "Refuse",
+ "progress.register-command": "(Digital IDE) Register Command",
+ "progress.initialization": "(Digital IDE) Initialization",
+ "progress.build-module-tree": "build module tree"
+}
\ No newline at end of file
diff --git a/l10n/bundle.l10n.zh-cn.json b/l10n/bundle.l10n.zh-cn.json
new file mode 100644
index 0000000..dd7bf7d
--- /dev/null
+++ b/l10n/bundle.l10n.zh-cn.json
@@ -0,0 +1,9 @@
+{
+ "hello": "hello in English",
+ "welcome.title": "Thanks for using Digital-IDE ❤️. Your star will be our best motivation! 😊",
+ "welcome.star": "Star",
+ "welcome.refuse": "Refuse",
+ "progress.register-command": "(Digital IDE) Register Command",
+ "progress.initialization": "(Digital IDE) Initialization",
+ "progress.build-module-tree": "build module tree"
+}
\ No newline at end of file
diff --git a/l10n/bundle.l10n.zh-tw.json b/l10n/bundle.l10n.zh-tw.json
new file mode 100644
index 0000000..dd7bf7d
--- /dev/null
+++ b/l10n/bundle.l10n.zh-tw.json
@@ -0,0 +1,9 @@
+{
+ "hello": "hello in English",
+ "welcome.title": "Thanks for using Digital-IDE ❤️. Your star will be our best motivation! 😊",
+ "welcome.star": "Star",
+ "welcome.refuse": "Refuse",
+ "progress.register-command": "(Digital IDE) Register Command",
+ "progress.initialization": "(Digital IDE) Initialization",
+ "progress.build-module-tree": "build module tree"
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index ec2a669..a410183 100644
--- a/package.json
+++ b/package.json
@@ -4,8 +4,9 @@
"description": "all in one vscode plugin for Verilog/VHDL development",
"publisher": "sterben",
"homepage": "https://digital-eda.github.io/DIDE-doc-Cn",
- "version": "0.3.3",
+ "version": "0.4.0",
"main": "./out/extension",
+ "l10n": "./l10n",
"icon": "images/icon.png",
"engines": {
"vscode": "^1.72.0"
@@ -344,6 +345,15 @@
"dark": "images/svg/dark/debug.svg"
}
},
+ {
+ "command": "digital-ide.tool.export-filelist",
+ "title": "%digital-ide.tool.export-filelist.title%",
+ "category": "Digital-IDE",
+ "icon": {
+ "light": "images/svg/light/export.svg",
+ "dark": "images/svg/dark/export.svg"
+ }
+ },
{
"command": "digital-ide.pickLibrary",
"title": "%digital-ide.pickLibrary.title%",
@@ -616,7 +626,18 @@
{
"command": "digital-ide.tool.icarus.simulateFile",
"group": "navigation@3",
- "when": "view == digital-ide-treeView-arch && viewItem == file"
+ "when": "view == digital-ide-treeView-arch && viewItem == file",
+ "args": {
+ "file": "${viewItem}"
+ }
+ },
+ {
+ "command": "digital-ide.tool.export-filelist",
+ "group": "navigation@4",
+ "when": "view == digital-ide-treeView-arch && viewItem == file",
+ "args": {
+ "file": "${viewItem}"
+ }
}
],
"editor/title": [
@@ -1167,4 +1188,4 @@
"vscode-textmate": "^9.0.0",
"wavedrom": "^2.9.1"
}
-}
+}
\ No newline at end of file
diff --git a/package.nls.json b/package.nls.json
index eb7d2c1..59af08b 100644
--- a/package.nls.json
+++ b/package.nls.json
@@ -45,5 +45,6 @@
"digital-ide.lsp.vlog.linter.pick.title": "select a diagnostic for verilog",
"digital-ide.lsp.svlog.linter.pick.title": "select a diagnostic for systemverilog verilog",
"digital-ide.lsp.vhdl.linter.pick.title": "select a diagnostic for vhdl",
- "digital-ide.lsp.systemverilog.linter.pick.title": "select a diagnostic for systemverilog"
+ "digital-ide.lsp.systemverilog.linter.pick.title": "select a diagnostic for systemverilog",
+ "digital-ide.tool.export-filelist.title": "export filelist"
}
\ No newline at end of file
diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json
index f978a1c..88a6f4b 100644
--- a/package.nls.zh-cn.json
+++ b/package.nls.zh-cn.json
@@ -42,8 +42,9 @@
"digital-ide.fsm.show.title": "显示当前文件的FSM图",
"digital-ide.netlist.show.title": "显示当前文件的netlist",
"digital-ide.waveviewer.show.title": "在 dide viewer 中渲染当前的 vcd",
- "digital-ide.lsp.vlog.linter.pick.title": "选择 Verilog 的诊断",
- "digital-ide.lsp.svlog.linter.pick.title": "选择 System Verilog 的诊断",
- "digital-ide.lsp.vhdl.linter.pick.title": "选择 VHDL 的诊断",
- "digital-ide.lsp.systemverilog.linter.pick.title": "选择 SystemVerilog 的诊断"
+ "digital-ide.lsp.vlog.linter.pick.title": "选择 Verilog 的诊断",
+ "digital-ide.lsp.svlog.linter.pick.title": "选择 System Verilog 的诊断",
+ "digital-ide.lsp.vhdl.linter.pick.title": "选择 VHDL 的诊断",
+ "digital-ide.lsp.systemverilog.linter.pick.title": "选择 SystemVerilog 的诊断",
+ "digital-ide.tool.export-filelist.title": "导出 filelist"
}
\ No newline at end of file
diff --git a/package.nls.zh-tw.json b/package.nls.zh-tw.json
index f0f7a05..97645ad 100644
--- a/package.nls.zh-tw.json
+++ b/package.nls.zh-tw.json
@@ -42,8 +42,9 @@
"digital-ide.fsm.show.title": "顯示當前文件的FSM圖",
"digital-ide.netlist.show.title": "顯示當前文件的netlist",
"digital-ide.waveviewer.show.title": "Render the vcd in viewer",
- "digital-ide.lsp.vlog.linter.pick.title": "選擇 Verilog 的診斷",
- "digital-ide.lsp.svlog.linter.pick.title": "選擇 System Verilog 的診斷",
- "digital-ide.lsp.vhdl.linter.pick.title": "選擇 VHDL 的診斷",
- "digital-ide.lsp.systemverilog.linter.pick.title": "選擇 SystemVerilog 的診斷"
+ "digital-ide.lsp.vlog.linter.pick.title": "選擇 Verilog 的診斷",
+ "digital-ide.lsp.svlog.linter.pick.title": "選擇 System Verilog 的診斷",
+ "digital-ide.lsp.vhdl.linter.pick.title": "選擇 VHDL 的診斷",
+ "digital-ide.lsp.systemverilog.linter.pick.title": "選擇 SystemVerilog 的診斷",
+ "digital-ide.tool.export-filelist.title": "導出 filelist"
}
\ No newline at end of file
diff --git a/src/extension.ts b/src/extension.ts
index 2bbdbda..d74a689 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -26,16 +26,18 @@ async function registerCommand(context: vscode.ExtensionContext) {
}
async function launch(context: vscode.ExtensionContext) {
+ const { t } = vscode.l10n;
+
await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
- title: 'Register Command (Digtial-IDE)'
+ title: t('progress.register-command')
}, async () => {
await registerCommand(context);
});
await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
- title: 'Initialization (Digtial-IDE)'
+ title: t('progress.initialization')
}, async (progress: vscode.Progress, token: vscode.CancellationToken) => {
// 初始化解析
await manager.prjManage.initialise(context, progress);
@@ -50,8 +52,7 @@ async function launch(context: vscode.ExtensionContext) {
});
-
- MainOutput.report('Digital-IDE has launched, Version: 0.3.3', ReportType.Launch);
+ MainOutput.report('Digital-IDE has launched, Version: 0.4.0', ReportType.Launch);
MainOutput.report('OS: ' + opeParam.os, ReportType.Launch);
console.log(hdlParam);
@@ -64,9 +65,9 @@ async function launch(context: vscode.ExtensionContext) {
// don't show in next time
welcomeSetting.update('show', false, vscode.ConfigurationTarget.Global);
const res = await vscode.window.showInformationMessage(
- 'Thanks for using Digital-IDE ❤️. Your star will be our best motivation! 😊',
- { title: 'Star', value: true },
- { title: 'Refuse', value: false },
+ t('welcome.title'),
+ { title: t('welcome.star'), value: true },
+ { title: t('welcome.refuse'), value: false },
);
if (res?.value) {
vscode.env.openExternal(vscode.Uri.parse(extensionUrl));
diff --git a/src/function/index.ts b/src/function/index.ts
index 799d3f1..ba09c90 100644
--- a/src/function/index.ts
+++ b/src/function/index.ts
@@ -110,6 +110,9 @@ function registerLsp(context: vscode.ExtensionContext) {
function registerToolCommands(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('digital-ide.lsp.tool.insertTextToUri', tool.insertTextToUri);
vscode.commands.registerCommand('digital-ide.lsp.tool.transformOldPropertyFile', tool.transformOldPpy);
+ vscode.commands.registerCommand('digital-ide.tool.export-filelist', (view: ModuleDataItem) => {
+ tool.exportFilelist(view);
+ });
}
function registerFSM(context: vscode.ExtensionContext) {
diff --git a/src/function/tool.ts b/src/function/tool.ts
index ed1ef26..28b28e2 100644
--- a/src/function/tool.ts
+++ b/src/function/tool.ts
@@ -1,9 +1,12 @@
/* eslint-disable @typescript-eslint/naming-convention */
import * as vscode from 'vscode';
import * as fs from 'fs';
+import * as fspath from 'path';
import { opeParam } from '../global';
-import { hdlFile } from '../hdlFs';
+import { hdlFile, hdlPath } from '../hdlFs';
+import { ModuleDataItem } from './treeView/tree';
+import { hdlParam } from '../hdlParser';
async function insertTextToUri(uri: vscode.Uri, text: string, position?: vscode.Position) {
if (!position) {
@@ -70,8 +73,47 @@ async function transformOldPpy() {
}
}
+async function askUserToSaveFilelist(filelist: string[]) {
+ const topModulePath = filelist[0];
+ const defaultSaveName = fspath.basename(topModulePath, fspath.extname(topModulePath));
+ const defaultSavePath = hdlPath.join(opeParam.workspacePath, defaultSaveName + '.f');
+
+ const uri = await vscode.window.showSaveDialog({
+ filters: {
+ 'All Files': ['*']
+ },
+ saveLabel: 'save',
+ defaultUri: vscode.Uri.file(defaultSavePath)
+ });
+
+
+}
+
+/**
+ * @description 导出当前 module 的 filelist
+ * @param view treeview 中的模块对象
+ */
+function exportFilelist(view: ModuleDataItem) {
+ const fileset = new Set();
+ if (view.path !== undefined) {
+ const deps = hdlParam.getAllDependences(view.path, view.name);
+ if (deps) {
+ deps.others.forEach(path => fileset.add(path));
+ deps.include.forEach(path => fileset.add(path));
+ const filelist = [view.path];
+ filelist.push(...fileset);
+
+ } else {
+ vscode.window.showErrorMessage('fail to get deps of view ' + view.name);
+ }
+ } else {
+ vscode.window.showErrorMessage('cannot find path for current module');
+ }
+
+}
export {
insertTextToUri,
- transformOldPpy
+ transformOldPpy,
+ exportFilelist
};
\ No newline at end of file
diff --git a/src/hdlParser/core.ts b/src/hdlParser/core.ts
index ccd8913..162c63c 100644
--- a/src/hdlParser/core.ts
+++ b/src/hdlParser/core.ts
@@ -7,7 +7,7 @@ import { MainOutput, ReportType } from '../global/outputChannel';
import * as common from './common';
import { hdlFile, hdlPath } from '../hdlFs';
import { HdlSymbol } from './util';
-import { vhdlFast } from '../../resources/hdlParser';
+import { Fast, vhdlFast } from '../../resources/hdlParser';
class HdlParam {
private readonly topModules : Set = new Set();
@@ -242,13 +242,13 @@ class HdlParam {
}
public async initHdlFiles(hdlFiles: AbsPath[], progress?: vscode.Progress) {
+ const { t } = vscode.l10n;
let count: number = 0;
let fileNum = hdlFiles.length;
const parallelChunk = 5;
const pools: { id: number, promise: Promise }[] = [];
-
- vscode.window.showInformationMessage("files to handle: " + fileNum);
+ const reportTitle = t('progress.build-module-tree');
async function consumePools() {
for (const p of pools) {
@@ -256,7 +256,7 @@ class HdlParam {
await p.promise;
console.log("handle id " + p.id + ' increment: ' + increment);
- progress?.report({ message: `build module tree ${p.id}/${fileNum}`, increment });
+ progress?.report({ message: reportTitle + ` ${p.id}/${fileNum}`, increment });
}
pools.length = 0;
}
@@ -347,6 +347,42 @@ class HdlParam {
}
}
}
+
+ public updateFast(path: string, fast: Fast) {
+ const moduleFile = this.getHdlFile(path);
+ if (moduleFile === undefined) {
+ return;
+ }
+
+ // 1. update marco directly
+ moduleFile.updateMacro(fast.macro);
+
+ // 2. update modules one by one
+ const uncheckedModuleNames = new Set();
+ for (const name of moduleFile.getAllModuleNames()) {
+ uncheckedModuleNames.add(name);
+ }
+
+ for (const rawHdlModule of fast.content) {
+ const moduleName = rawHdlModule.name;
+ if (uncheckedModuleNames.has(moduleName)) {
+ // match the same module, check then
+ const originalModule = moduleFile.getHdlModule(moduleName);
+ uncheckedModuleNames.delete(moduleName);
+ originalModule?.update(rawHdlModule);
+ } else {
+ // no matched, create it
+ const newModule = moduleFile.createHdlModule(rawHdlModule);
+ newModule.makeNameToInstances();
+ newModule.solveUnhandleInstance();
+ }
+ }
+
+ // 3. delete module not visited yet
+ for (const moduleName of uncheckedModuleNames) {
+ moduleFile.deleteHdlModule(moduleName);
+ }
+ }
};
const hdlParam = new HdlParam();
diff --git a/src/hdlParser/util.ts b/src/hdlParser/util.ts
index e9b9594..d5bb0ed 100644
--- a/src/hdlParser/util.ts
+++ b/src/hdlParser/util.ts
@@ -11,7 +11,6 @@ async function doFastApi(path: string): Promise {
const client = LspClient.MainClient;
const langID = hdlFile.getLanguageId(path);
if (client) {
- console.log(client.initializeResult);
const response = await client.sendRequest(DoFastRequestType, { path });
response.languageId = langID;
return response;
diff --git a/src/manager/prj.ts b/src/manager/prj.ts
index ff4d234..3634b8a 100644
--- a/src/manager/prj.ts
+++ b/src/manager/prj.ts
@@ -2,7 +2,7 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
-import { AbsPath, IProgress, MainOutput, opeParam, ReportType } from '../global';
+import { AbsPath, IProgress, LspClient, MainOutput, opeParam, ReportType } from '../global';
import { PathSet } from '../global/util';
import { RawPrjInfo } from '../global/prjInfo';
import { hdlDir, hdlFile, hdlPath } from '../hdlFs';
@@ -13,6 +13,9 @@ import { PsManage } from './PS';
import { hdlIgnore } from './ignore';
import { ppyAction } from '../monitor/event';
import { hdlMonitor } from '../monitor';
+import { NotificationType } from 'vscode-jsonrpc';
+import { refreshArchTree } from '../function/treeView';
+import { Fast } from '../../resources/hdlParser';
interface RefreshPrjConfig {
mkdir: boolean
@@ -151,6 +154,28 @@ class PrjManage {
const unhandleNum = hdlParam.getUnhandleInstanceNumber();
MainOutput.report(`finish analyse ${hdlFiles.length} hdl files, find ${unhandleNum} unsolved instances`, ReportType.Info);
+ // 完成后端向前端发送消息的注册
+ const mainClient = LspClient.MainClient;
+ if (mainClient !== undefined) {
+ await mainClient.onReady();
+ mainClient.onNotification('update/fast', async (params: any) => {
+ try {
+ const fast = params.fast as Fast;
+ const path = params.path as string;
+ console.log("[receive notification] path: " + path);
+ hdlParam.updateFast(path, fast);
+ refreshArchTree();
+ } catch (error) {
+ console.error("error happen when update fast: " + error);
+ }
+ });
+
+ // mainClient.onNotification('update/string', async (params: any) => {
+ // console.log('[StringNotificationType] receive from backend');
+ // console.log(params);
+ // });
+ }
+
this.pl = new PlManage();
// TODO : finish it later
diff --git a/src/monitor/event.ts b/src/monitor/event.ts
index 2aee56f..85edc0c 100644
--- a/src/monitor/event.ts
+++ b/src/monitor/event.ts
@@ -119,12 +119,15 @@ class HdlAction extends BaseAction {
async change(path: string, m: HdlMonitor): Promise {
console.log('HdlAction change');
path = hdlPath.toSlash(path);
+ const langID = hdlFile.getLanguageId(path);
// TODO : check performance
- await this.updateSymbolStorage(path);
+ if (langID === HdlLangID.Vhdl) {
+ await this.updateSymbolStorage(path);
+ await this.updateHdlParam(path);
+ }
await this.updateLinter(path);
- await this.updateHdlParam(path);
refreshArchTree();
}
@@ -148,7 +151,7 @@ class HdlAction extends BaseAction {
async updateHdlParam(path: string) {
const moduleFile = hdlParam.getHdlFile(path);
-
+
if (!moduleFile) {
return;
}
@@ -183,8 +186,6 @@ class HdlAction extends BaseAction {
}
}
-
-
// 3. delete module not visited yet
for (const moduleName of uncheckedModuleNames) {
moduleFile.deleteHdlModule(moduleName);