From 52349329df2d8cbfa79b15c3b36d94e01bbb9274 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Wed, 12 Apr 2023 22:09:03 +0800 Subject: [PATCH] do LibPick --- draft.json | 0 package.json | 37 ++++++ package.nls.zh-cn.json | 40 +++---- package.nls.zh-tw.json | 56 ++++----- script/command/make_title_token.py | 2 +- script/command/translate_from_en.py | 63 ++++++++++ src/extension.ts | 8 +- src/function/index.ts | 12 +- src/function/treeView/index.ts | 2 +- src/manager/index.ts | 11 +- src/manager/lib.ts | 2 +- src/manager/libPick.ts | 172 ++++++++++++++++++++++++++++ src/manager/prj.ts | 11 +- 13 files changed, 345 insertions(+), 71 deletions(-) delete mode 100644 draft.json create mode 100644 src/manager/libPick.ts diff --git a/draft.json b/draft.json deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index ce59c7f..04ea114 100644 --- a/package.json +++ b/package.json @@ -273,6 +273,23 @@ } ], "menus": { + "view/title": [ + { + "command": "digital-ide.treeView.arch.collapse", + "group": "navigation", + "when": "view == digital-ide-treeView-arch" + }, + { + "command": "TOOL.libPick", + "group": "navigation", + "when": "view == digital-ide-treeView-arch" + }, + { + "command": "digital-ide.treeView.arch.refresh", + "group": "navigation", + "when": "view == digital-ide-treeView-arch" + } + ], "editor/title": [ { "when": "editorLangId == verilog || editorLangId == systemverilog || editorLangId == vhdl", @@ -286,6 +303,26 @@ } ] }, + "views": { + "TOOL": [ + { + "id": "digital-ide-treeView-arch", + "name": "architecture" + }, + { + "id": "digital-ide-treeView-tool", + "name": "TOOL" + }, + { + "id": "digital-ide-treeView-hardware", + "name": "HARD Options" + }, + { + "id": "digital-ide-treeView-software", + "name": "SOFT Options" + } + ] + }, "keybindings": [ { "command": "digital-ide.tool.instance", diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index d50b45a..ebd5d80 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -7,24 +7,24 @@ "digital-ide.tool.instance.title": "生成选中 module 的例化模板", "digital-ide.tool.testbench.title": "从当前文件中选择 module 生成 testbench", "digital-ide.tool.icarus.simulateFile.title": "对当前文件进行仿真", - "digital-ide.treeView.arch.expand.title": "", - "digital-ide.treeView.arch.collapse.title": "", - "digital-ide.treeView.arch.refresh.title": "", - "digital-ide.treeView.arch.openFile.title": "", - "digital-ide.tool.tool.clean.title": "", - "digital-ide.soft.launch.title": "", - "digital-ide.soft.build.title": "", - "digital-ide.soft.download.title": "", - "digital-ide.hard.launch.title": "", - "digital-ide.hard.simulate.title": "", - "digital-ide.hard.simulate.cli.title": "", - "digital-ide.hard.simulate.gui.title": "", - "digital-ide.hard.refresh.title": "", - "digital-ide.hard.build.title": "", - "digital-ide.hard.build.synth.title": "", - "digital-ide.hard.build.impl.title": "", - "digital-ide.hard.build.bitstream.title": "", - "digital-ide.hard.program.title": "", - "digital-ide.hard.gui.title": "", - "digital-ide.hard.exit.title": "" + "digital-ide.treeView.arch.expand.title": "扩大树视图中的所有项目", + "digital-ide.treeView.arch.collapse.title": "崩溃树视图中的所有项目", + "digital-ide.treeView.arch.refresh.title": "刷新树视图", + "digital-ide.treeView.arch.openFile.title": "在树视图打开相应的文件", + "digital-ide.tool.tool.clean.title": "干净的当前项目", + "digital-ide.soft.launch.title": "启动SDK开发辅助功能", + "digital-ide.soft.build.title": "建立项目当前的SDK", + "digital-ide.soft.download.title": "下载文件到设备引导", + "digital-ide.hard.launch.title": "启动FPGA开发辅助功能", + "digital-ide.hard.simulate.title": "启动生产仿真", + "digital-ide.hard.simulate.cli.title": "在CLI推出制造商模拟", + "digital-ide.hard.simulate.gui.title": "在GUI推出制造商模拟", + "digital-ide.hard.refresh.title": "刷新当前的项目文件", + "digital-ide.hard.build.title": "fpga构建当前项目", + "digital-ide.hard.build.synth.title": "Synth当前项目", + "digital-ide.hard.build.impl.title": "Impl当前项目", + "digital-ide.hard.build.bitstream.title": "生成一些文件", + "digital-ide.hard.program.title": "下载文件到设备", + "digital-ide.hard.gui.title": "打开界面", + "digital-ide.hard.exit.title": "退出当前项目" } \ No newline at end of file diff --git a/package.nls.zh-tw.json b/package.nls.zh-tw.json index e13fb9c..67b7825 100644 --- a/package.nls.zh-tw.json +++ b/package.nls.zh-tw.json @@ -1,30 +1,30 @@ { - "digital-ide.property-json.generate.title": "", - "digital-ide.property-json.overwrite.title": "", - "digital-ide.hdlDoc.exportFile.title": "", - "digital-ide.hdlDoc.exportProject.title": "", - "digital-ide.hdlDoc.showWebview.title": "", - "digital-ide.tool.instance.title": "", - "digital-ide.tool.testbench.title": "", - "digital-ide.tool.icarus.simulateFile.title": "", - "digital-ide.treeView.arch.expand.title": "", - "digital-ide.treeView.arch.collapse.title": "", - "digital-ide.treeView.arch.refresh.title": "", - "digital-ide.treeView.arch.openFile.title": "", - "digital-ide.tool.tool.clean.title": "", - "digital-ide.soft.launch.title": "", - "digital-ide.soft.build.title": "", - "digital-ide.soft.download.title": "", - "digital-ide.hard.launch.title": "", - "digital-ide.hard.simulate.title": "", - "digital-ide.hard.simulate.cli.title": "", - "digital-ide.hard.simulate.gui.title": "", - "digital-ide.hard.refresh.title": "", - "digital-ide.hard.build.title": "", - "digital-ide.hard.build.synth.title": "", - "digital-ide.hard.build.impl.title": "", - "digital-ide.hard.build.bitstream.title": "", - "digital-ide.hard.program.title": "", - "digital-ide.hard.gui.title": "", - "digital-ide.hard.exit.title": "" + "digital-ide.property-json.generate.title": "生成 property.json 配置文件", + "digital-ide.property-json.overwrite.title": "修改默認的 property.json 模板文件", + "digital-ide.hdlDoc.exportFile.title": "導出當前文件的文檔", + "digital-ide.hdlDoc.exportProject.title": "導出當前項目的文檔", + "digital-ide.hdlDoc.showWebview.title": "在 webview 中展示文檔", + "digital-ide.tool.instance.title": "生成選中 module 的例化模板", + "digital-ide.tool.testbench.title": "從當前文件中選擇 module 生成 testbench", + "digital-ide.tool.icarus.simulateFile.title": "對當前文件進行仿真", + "digital-ide.treeView.arch.expand.title": "擴大樹視圖中的所有項目", + "digital-ide.treeView.arch.collapse.title": "崩潰樹視圖中的所有項目", + "digital-ide.treeView.arch.refresh.title": "刷新樹視圖", + "digital-ide.treeView.arch.openFile.title": "在樹視圖打開相應的文件", + "digital-ide.tool.tool.clean.title": "乾淨的當前項目", + "digital-ide.soft.launch.title": "啟動SDK開發輔助功能", + "digital-ide.soft.build.title": "建立項目當前的SDK", + "digital-ide.soft.download.title": "下載文件到設備引導", + "digital-ide.hard.launch.title": "啟動FPGA開發輔助功能", + "digital-ide.hard.simulate.title": "啟動生產仿真", + "digital-ide.hard.simulate.cli.title": "在CLI推出製造商模擬", + "digital-ide.hard.simulate.gui.title": "在GUI推出製造商模擬", + "digital-ide.hard.refresh.title": "刷新當前的項目文件", + "digital-ide.hard.build.title": "fpga構建當前項目", + "digital-ide.hard.build.synth.title": "Synth當前項目", + "digital-ide.hard.build.impl.title": "Impl當前項目", + "digital-ide.hard.build.bitstream.title": "生成一些文件", + "digital-ide.hard.program.title": "下載文件到設備", + "digital-ide.hard.gui.title": "打開界面", + "digital-ide.hard.exit.title": "退出當前項目" } \ No newline at end of file diff --git a/script/command/make_title_token.py b/script/command/make_title_token.py index 9c89342..196c875 100644 --- a/script/command/make_title_token.py +++ b/script/command/make_title_token.py @@ -10,7 +10,7 @@ PACKAGE_FILE = './package.json' LANG_PACKGE_FILES = { 'en': './package.nls.json', 'zh-cn': './package.nls.zh-cn.json', - 'zh-tw': './package.nls.zh-tw.json' + 'zh-tw': './package.nls.zh-tw.json', } def generate_title_token(command_name: str) -> str: diff --git a/script/command/translate_from_en.py b/script/command/translate_from_en.py index b1493db..ac90ead 100644 --- a/script/command/translate_from_en.py +++ b/script/command/translate_from_en.py @@ -1,6 +1,69 @@ import sys import os sys.path.append(os.path.abspath('.')) +from typing import Dict + +import requests as r +from zhconv import convert from script.util import read_json, write_json + +PACKAGE_FILE = './package.json' + +LANG_PACKGE_FILES = { + 'en': './package.nls.json', + 'zh-cn': './package.nls.zh-cn.json', + 'zh-tw': './package.nls.zh-tw.json', +} + +def youdao_translate(query: str, from_lang: str='AUTO', to_lang: str='AUTO') -> str: + url = 'http://fanyi.youdao.com/translate' + data = { + "i": query, # 待翻译的字符串 + "from": from_lang, + "to": to_lang, + "smartresult": "dict", + "client": "fanyideskweb", + "salt": "16081210430989", + "doctype": "json", + "version": "2.1", + "keyfrom": "fanyi.web", + "action": "FY_BY_CLICKBUTTION" + } + res = r.post(url, data=data).json() + return res['translateResult'][0][0]['tgt'] + +def to_complex_zh(words: str) -> str: + return convert(words, 'zh-tw') + +def translate_from_en(en_config: Dict[str, str], target_config: Dict[str, str], target_lang_id: str): + for command in target_config.keys(): + desc = target_config[command] + if len(desc) == 0: + en_desc = en_config.get(command, '') + assert len(en_desc) > 0, f'command:{command} in en_config is empty' + target_desc = youdao_translate(en_desc, from_lang='en', to_lang=target_lang_id) + target_config[command] = target_desc + +def translate_complex_zh(zh_config: Dict[str, str], zh_tw_config: Dict[str, str]): + for command in zh_tw_config.keys(): + zh_desc = zh_config.get(command, '') + assert len(zh_desc) > 0, f'{command} in zh_config is empty' + complex_zh_desc = to_complex_zh(zh_desc) + zh_tw_config[command] = complex_zh_desc + + +def main(): + en_config = read_json(LANG_PACKGE_FILES["en"]) + + zh_cn_config = read_json(LANG_PACKGE_FILES["zh-cn"]) + zh_tw_config = read_json(LANG_PACKGE_FILES["zh-tw"]) + + translate_from_en(en_config, zh_cn_config, 'zh') + translate_complex_zh(zh_cn_config, zh_tw_config) + + write_json(LANG_PACKGE_FILES["zh-cn"], zh_cn_config) + write_json(LANG_PACKGE_FILES["zh-tw"], zh_tw_config) + +main() \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index d94ad9e..3395309 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,12 +2,12 @@ import * as vscode from 'vscode'; import { opeParam, MainOutput, ReportType } from './global'; import { hdlParam } from './hdlParser'; -import { prjManage } from './manager'; - -import { registerAllCommands } from './function'; +import { prjManage, registerManagerCommands } from './manager'; +import { registerFunctionCommands } from './function'; async function registerCommand(context: vscode.ExtensionContext) { - registerAllCommands(context); + registerFunctionCommands(context); + registerManagerCommands(context); } async function launch(context: vscode.ExtensionContext) { diff --git a/src/function/index.ts b/src/function/index.ts index 6693458..f351b83 100644 --- a/src/function/index.ts +++ b/src/function/index.ts @@ -17,7 +17,7 @@ function registerSimulation(context: vscode.ExtensionContext) { vscode.commands.registerCommand('digital-ide.tool.icarus.simulateFile', sim.Icarus.simulateFile); } -function registerAllCommands(context: vscode.ExtensionContext) { +function registerFunctionCommands(context: vscode.ExtensionContext) { registerDocumentation(context); registerSimulation(context); registerTreeView(context); @@ -25,10 +25,10 @@ function registerAllCommands(context: vscode.ExtensionContext) { function registerTreeView(context: vscode.ExtensionContext) { // register normal tree - vscode.window.registerTreeDataProvider('digital-ide.treeView.arch', treeView.moduleTreeProvider); - vscode.window.registerTreeDataProvider('digital-ide.treeView.tool', treeView.toolTreeProvider); - vscode.window.registerTreeDataProvider('digital-ide.treeView.hardware', treeView.hardwareTreeProvider); - vscode.window.registerTreeDataProvider('digital-ide.treeView.software', treeView.softwareTreeProvider); + vscode.window.registerTreeDataProvider('digital-ide-treeView-arch', treeView.moduleTreeProvider); + vscode.window.registerTreeDataProvider('digital-ide-treeView-tool', treeView.toolTreeProvider); + vscode.window.registerTreeDataProvider('digital-ide-treeView-hardware', treeView.hardwareTreeProvider); + vscode.window.registerTreeDataProvider('digital-ide-treeView-software', treeView.softwareTreeProvider); // constant used in tree vscode.commands.executeCommand('setContext', 'TOOL-tree-expand', false); @@ -43,5 +43,5 @@ function registerTreeView(context: vscode.ExtensionContext) { export { - registerAllCommands + registerFunctionCommands }; \ No newline at end of file diff --git a/src/function/treeView/index.ts b/src/function/treeView/index.ts index a012b96..bd43c7b 100644 --- a/src/function/treeView/index.ts +++ b/src/function/treeView/index.ts @@ -21,7 +21,7 @@ function expandTreeView() { } function collapseTreeView() { - vscode.commands.executeCommand('workbench.actions.treeView.TOOL-tree-arch.collapseAll'); + vscode.commands.executeCommand('workbench.actions.treeView.digital-ide-treeView-arch.collapseAll'); vscode.commands.executeCommand('setContext', 'TOOL-tree-expand', true); } diff --git a/src/manager/index.ts b/src/manager/index.ts index 6308f7f..38716b7 100644 --- a/src/manager/index.ts +++ b/src/manager/index.ts @@ -1,5 +1,14 @@ +import * as vscode from 'vscode'; + import { prjManage } from './prj'; + +function registerManagerCommands(context: vscode.ExtensionContext) { + vscode.commands.registerCommand('digital-ide.property-json.generate', prjManage.generatePropertyJson); + vscode.commands.registerCommand('digital-ide.property-json.overwrite', prjManage.overwritePropertyJson); +} + export { - prjManage + prjManage, + registerManagerCommands }; \ No newline at end of file diff --git a/src/manager/lib.ts b/src/manager/lib.ts index 157a8f9..a35231e 100644 --- a/src/manager/lib.ts +++ b/src/manager/lib.ts @@ -33,7 +33,7 @@ class LibManage { } public processLibFiles() { - + } }; \ No newline at end of file diff --git a/src/manager/libPick.ts b/src/manager/libPick.ts new file mode 100644 index 0000000..0c933ad --- /dev/null +++ b/src/manager/libPick.ts @@ -0,0 +1,172 @@ +import * as vscode from 'vscode'; +import * as fspath from 'path'; +import * as fs from 'fs'; + +import { AbsPath, opeParam } from '../global'; +import { HdlLangID } from '../global/enum'; +import { hdlDir, hdlFile, hdlPath } from '../hdlFs'; +import { getIconConfig } from '../hdlFs/icons'; + +type MissPathType = { path?: string }; +type LibPickItem = vscode.QuickPickItem & MissPathType; + +class LibPick { + commonPath: AbsPath; + customPath: AbsPath; + commonQuickPickItem: LibPickItem; + customQuickPickItem: LibPickItem; + rootItems: LibPickItem[]; + backQuickPickItem: LibPickItem; + curPath: AbsPath; + selectedQuickPickItem: LibPickItem | undefined; + + constructor () { + this.commonPath = hdlPath.join(opeParam.extensionPath, 'lib', 'common'); + this.customPath = hdlPath.toSlash(vscode.workspace.getConfiguration('PRJ.custom.Lib.repo').get('path', '')); + + this.commonQuickPickItem = { + label: "$(libpick-common) common", + description: 'common library provided by us', + detail: 'current path: ' + this.commonPath, + path: this.commonPath, + buttons: [{iconPath: getIconConfig('import'), tooltip: 'import everything in common'}] + }; + + this.customQuickPickItem = { + label: "$(libpick-custom) custom", + description: 'custom library by yourself', + detail: 'current path: ' + this.customPath, + path: this.customPath, + buttons: [{iconPath: getIconConfig('import'), tooltip: 'import everything in custom'}] + }; + + this.rootItems = [ + this.commonQuickPickItem, + this.customQuickPickItem + ]; + + this.backQuickPickItem = { + label: '...', + description: 'return' + }; + + this.curPath = ''; + } + + getPathIcon(path: AbsPath): string { + let prompt; + if (hdlFile.isFile(path)) { + const langID = hdlFile.getLanguageId(path); + if (langID === HdlLangID.Vhdl) { + prompt = 'vhdl'; + } else if (langID === HdlLangID.Verilog || + langID === HdlLangID.SystemVerilog) { + prompt = 'verilog'; + } else { + prompt = 'unknown'; + } + } else { + prompt = 'folder'; + } + return `$(libpick-${prompt})`; + } + + private makeQuickPickItemsByPath(path: AbsPath, back: boolean=true): LibPickItem[] { + const items: LibPickItem[] = []; + if (!hdlPath.exist(path)) { + return items; + } + if (back) { + items.push(this.backQuickPickItem); + } + + for (const fileName of fs.readdirSync(path)) { + const filePath = hdlPath.join(path, fileName); + const themeIcon = this.getPathIcon(filePath); + const label = themeIcon + " " + fileName; + const mdPath = hdlPath.join(path, fileName, 'readme.md'); + const mdText = hdlFile.readFile(mdPath); + const description = mdText ? mdText : ''; + const buttons = [{iconPath: getIconConfig('import'), tooltip: 'import everything in ' + fileName}]; + items.push({label, description, path: filePath, buttons}); + } + return items; + } + + private provideQuickPickItem(item?: LibPickItem) { + if (!item) { + return this.rootItems; + } else if (item === this.backQuickPickItem) { + if ((this.curPath === this.commonPath) || + (this.curPath === this.customPath)) { + return this.rootItems; + } else { + // rollback the current path + this.curPath = fspath.dirname(this.curPath); + } + } else if (item === this.commonQuickPickItem) { + this.curPath = this.commonPath; + } else if (item === this.customQuickPickItem) { + this.curPath = this.customPath; + } else { + const label = item.label; + const fileName = label.replace(/\$\([\s\S]*\)/, '').trim(); + this.curPath = hdlPath.join(this.curPath, fileName); + } + + return this.makeQuickPickItemsByPath(this.curPath); + } + + async pickItems() { + const pickWidget = vscode.window.createQuickPick(); + + pickWidget.placeholder = 'pick the library'; + pickWidget.items = this.provideQuickPickItem(); + + pickWidget.onDidChangeSelection(items => { + console.log('enter onDidChangeSelection'); + if (items[0]) { + this.selectedQuickPickItem = items[0]; + } + }); + + pickWidget.onDidAccept(() => { + console.log('enter onDidAccept'); + if (this.selectedQuickPickItem) { + const childernItems = this.provideQuickPickItem(this.selectedQuickPickItem); + if (childernItems && childernItems.length > 0) { + pickWidget.items = childernItems; + } + } + }); + + pickWidget.onDidTriggerItemButton(event => { + const selectedPath = event.item.path; + + if (selectedPath && hdlPath.exist(selectedPath)) { + const ppyPath = hdlPath.join(opeParam.workspacePath, '.vscode', 'property.json'); + let prjInfo = null; + // 如果存在,则读取用户的配置文件,否则使用默认的 + if (!hdlPath.exist(ppyPath)) { + prjInfo = hdlFile.readJSON(opeParam.propertyInitPath); + } else { + prjInfo = hdlFile.readJSON(ppyPath); + } + + if (selectedPath.includes(this.commonQuickPickItem.path!)) { + // this is a module import from common, use relative path + const relPath = selectedPath.replace(this.commonQuickPickItem.path + '/', ''); + + appendLibraryCommonPath(relPath, prjInfo); + } else { + // this is a module import from custom, use absolute path + const relPath = selectedPath.replace(this.customQuickPickItem.path + '/', ''); + appendLibraryCustomPath(relPath, prjInfo); + } + hdlFile.writeJSON(ppyPath, prjInfo); + } + }); + + pickWidget.show(); + } +} \ No newline at end of file diff --git a/src/manager/prj.ts b/src/manager/prj.ts index e0234b8..8978ba5 100644 --- a/src/manager/prj.ts +++ b/src/manager/prj.ts @@ -8,15 +8,8 @@ import { RawPrjInfo } from '../global/prjInfo'; import { hdlFile, hdlPath } from '../hdlFs'; class PrjManage { - constructor() { - vscode.commands.registerCommand('digital-ide.property-json.generate', - this.generatePropertyJson); - vscode.commands.registerCommand('digital-ide.property-json.overwrite', - this.overwritePropertyJson); - } - // generate property template and write it to .vscode/property.json - private async generatePropertyJson() { + public async generatePropertyJson() { if (fs.existsSync(opeParam.propertyJsonPath)) { vscode.window.showWarningMessage('property file already exists !!!'); return; @@ -26,7 +19,7 @@ class PrjManage { } // overwrite content in current property.json to property-init.json - private async overwritePropertyJson() { + public async overwritePropertyJson() { const options = { preview: false, viewColumn: vscode.ViewColumn.Active