diff --git a/resources/dide-doc/documentation.css b/resources/dide-doc/documentation.css index 18cfd1c..c30e764 100644 --- a/resources/dide-doc/documentation.css +++ b/resources/dide-doc/documentation.css @@ -635,4 +635,29 @@ img { .icon-parameter:before { font-weight: 1000; +} + +#write .source-lib-tag { + font-size: 0.85rem; + padding: 3px 4px; + border-radius: .5em; + background-color: rgb(35,102,93); +} + +#write .source-prj-tag { + font-size: 0.85rem; + padding: 3px 4px; + border-radius: .5em; + background-color: rgb(53,59,140); +} + +#write .source-unk-tag { + font-size: 0.85rem; + padding: 3px 4px; + border-radius: .5em; + background-color: #a09c9c; +} + +#write table, th, td { + border: 1px solid var(--vscode-foreground) !important; } \ No newline at end of file diff --git a/resources/dide-doc/iconfont.css b/resources/dide-doc/iconfont.css index 86f554a..8b0a030 100644 --- a/resources/dide-doc/iconfont.css +++ b/resources/dide-doc/iconfont.css @@ -1,8 +1,8 @@ @font-face { font-family: "iconfont"; /* Project id 4748764 */ - src: url('iconfont.woff2?t=1731847061847') format('woff2'), - url('iconfont.woff?t=1731847061847') format('woff'), - url('iconfont.ttf?t=1731847061847') format('truetype'); + src: url('iconfont.woff2?t=1731914985969') format('woff2'), + url('iconfont.woff?t=1731914985969') format('woff'), + url('iconfont.ttf?t=1731914985969') format('truetype'); } .iconfont { @@ -13,6 +13,10 @@ -moz-osx-font-smoothing: grayscale; } +.icon-tree:before { + content: "\e601"; +} + .icon-verilog:before { content: "\e634"; } diff --git a/resources/dide-doc/iconfont.woff2 b/resources/dide-doc/iconfont.woff2 index 38df031..6e23383 100644 Binary files a/resources/dide-doc/iconfont.woff2 and b/resources/dide-doc/iconfont.woff2 differ diff --git a/src/extension.ts b/src/extension.ts index b46a3c7..e2d7adc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,6 +9,8 @@ import { hdlMonitor } from './monitor'; import * as lspClient from './function/lsp-client'; import { refreshArchTree } from './function/treeView'; +import { hdlFile } from './hdlFs'; +import { initialiseI18n, t } from './i18n'; async function registerCommand(context: vscode.ExtensionContext, packageJson: any) { @@ -34,7 +36,8 @@ function readPackageJson(context: vscode.ExtensionContext): any | undefined { } async function launch(context: vscode.ExtensionContext) { - const { t } = vscode.l10n; + initialiseI18n(context); + console.log(t('info.welcome.title')); console.log(t('info.welcome.join-qq-group') + ' https://qm.qq.com/q/1M655h3GsA'); const packageJson = readPackageJson(context); diff --git a/src/function/dide-viewer/api.ts b/src/function/dide-viewer/api.ts index b5cf3e8..22c8db0 100644 --- a/src/function/dide-viewer/api.ts +++ b/src/function/dide-viewer/api.ts @@ -5,6 +5,7 @@ import { BSON } from 'bson'; import * as path from 'path'; import * as os from 'os'; import { getIconConfig } from '../../hdlFs/icons'; +import { t } from '../../i18n'; export interface SaveViewData { originVcdFile: string, @@ -80,9 +81,6 @@ function getFilename(file: string) { export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.WebviewPanel) { - const { t } = vscode.l10n; - - try { // 先保存原来的文件 payload 一定是 all let { originVcdFile, originVcdViewFile, payload } = data; @@ -101,7 +99,6 @@ export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.Webvi const vcdFilters: Record = {}; vcdFilters[t('info.vcd-viewer.vcd-view-file')] = ['view']; vcdFilters[t('info.vcd-viewer.all-file')] = ['*']; - const saveUri = await vscode.window.showSaveDialog({ title: t('info.vcd-viewer.save-as-view'), defaultUri: vscode.Uri.file(path.join(rootPath, defaultFilename)), @@ -137,7 +134,6 @@ export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.Webvi export async function loadView(data: any, uri: vscode.Uri, panel: vscode.WebviewPanel) { - const { t } = vscode.l10n; try { let { originVcdFile } = data; diff --git a/src/function/dide-viewer/index.ts b/src/function/dide-viewer/index.ts index 9f18120..183216e 100644 --- a/src/function/dide-viewer/index.ts +++ b/src/function/dide-viewer/index.ts @@ -7,6 +7,7 @@ import { opeParam, ReportType, WaveViewOutput } from '../../global'; import { LaunchFiles, loadView, saveView, saveViewAs } from './api'; import { BSON } from 'bson'; import { getIconConfig } from '../../hdlFs/icons'; +import { t } from '../../i18n'; function getWebviewContent(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel): string | undefined { const dideviewerPath = hdlPath.join(context.extensionPath, 'resources', 'dide-viewer', 'view'); @@ -202,7 +203,6 @@ function registerMessageEvent(panel: vscode.WebviewPanel, uri: vscode.Uri) { * @returns */ function getViewLaunchFiles(context: vscode.ExtensionContext, uri: vscode.Uri, panel: vscode.WebviewPanel): LaunchFiles | Error { - const { t } = vscode.l10n; const entryPath = uri.fsPath; const dideviewerPath = hdlPath.join(context.extensionPath, 'resources', 'dide-viewer', 'view'); const workerAbsPath = hdlPath.join(dideviewerPath, 'worker.js'); diff --git a/src/function/hdlDoc/markdown.ts b/src/function/hdlDoc/markdown.ts index f9e10ec..1dd1010 100644 --- a/src/function/hdlDoc/markdown.ts +++ b/src/function/hdlDoc/markdown.ts @@ -14,6 +14,7 @@ import { getSymbolComments } from '../lsp/util/feature'; import { HdlLangID, ThemeType } from '../../global/enum'; import { makeDiagram } from './diagram'; import { defaultMacro, doFastApi } from '../../hdlParser/util'; +import { t } from '../../i18n'; function makeSVGElementByLink(link: AbsPath, caption?: string) { @@ -45,12 +46,12 @@ function selectFieldValue(obj: any, subName: string, ws: string, name: string, i if (hdlFile && hdlFile.type === 'remote_lib') { // 如果是 库 文件,做出更加自定义的字面量 const libRelPath = value.replace(`${opeParam.extensionPath}/library/`, ''); - value = `(library) [${libRelPath}](file://${value})`; + value = `library [${libRelPath}](file://${value})`; } else { - value = `(project) [${relativePath}](file://${value})`; + value = `project [${relativePath}](file://${value})`; } } else { - value = '(unknown) ' + vscode.l10n.t('info.dide-doc.source.cannot-find'); + value = 'unknown ' + t('info.dide-doc.source.cannot-find'); } } @@ -123,8 +124,6 @@ async function patchComment(path: AbsPath, ports: (HdlModulePort | HdlModulePara * @param module */ async function getDocsFromModule(module: HdlModule): Promise { - const { t } = vscode.l10n; - const moduleName = module.name; const portNum = module.ports.length; const paramNum = module.params.length; @@ -182,7 +181,8 @@ async function getDocsFromModule(module: HdlModule): Promise { } // param section - md.addTitle(t('info.dide-doc.parameters'), 2); + const paramTitleIcon = ' '; + md.addTitle(paramTitleIcon + t('info.dide-doc.parameters'), 2); if (module.params.length > 0) { makeTableFromObjArray(md, module.params, 'params', ['name', 'init', 'empty', 'desc'], @@ -203,7 +203,8 @@ async function getDocsFromModule(module: HdlModule): Promise { // port section - md.addTitle(t('info.dide-doc.ports'), 2); + const portTitleIcon = ' '; + md.addTitle(portTitleIcon + t('info.dide-doc.ports'), 2); if (module.ports.length > 0) { makeTableFromObjArray(md, module.ports, 'ports', ['name', 'type', 'width', 'desc'], @@ -223,7 +224,8 @@ async function getDocsFromModule(module: HdlModule): Promise { md.addEnter(); // dependency section - md.addTitle(t('info.dide-doc.dependency'), 2); + const depTitleIcon = ' '; + md.addTitle(depTitleIcon + t('info.dide-doc.dependency'), 2); let insts = module.getAllInstances(); // 对于单文件模式而言,未进行 instance 搜索,所以insts必然是空的 @@ -269,8 +271,6 @@ async function getDocsFromModule(module: HdlModule): Promise { * @param path absolute path of the file */ async function getDocsFromFile(path: AbsPath): Promise { - const { t } = vscode.l10n; - let moduleFile = hdlParam.getHdlFile(path); // 没有说明是单文件模式,直接打开解析 if (!moduleFile) { diff --git a/src/function/index.ts b/src/function/index.ts index 7d75000..3e7efd2 100644 --- a/src/function/index.ts +++ b/src/function/index.ts @@ -22,6 +22,7 @@ import { hdlPath } from '../hdlFs'; import { LspClient, opeParam } from '../global'; import { DoFastToolChainType, SyncFastRequestType } from '../global/lsp'; import { makeDocBody } from './hdlDoc/html'; +import { State } from 'vscode-languageclient'; function registerDocumentation(context: vscode.ExtensionContext) { vscode.commands.registerCommand('digital-ide.hdlDoc.showWebview', async (uri: vscode.Uri) => { @@ -35,7 +36,7 @@ function registerDocumentation(context: vscode.ExtensionContext) { // TODO: 注册文件变动监听 const fileChangeDisposer = vscode.window.onDidChangeActiveTextEditor(async event => { // const client = LspClient.DigitalIDE; - // if (client && event?.document) { + // if (client && event?.document && client.state === State.Running && event.document.uri.path === uri.path) { // const path = hdlPath.toSlash(event.document.fileName); // const fileType = 'common'; // const toolChain = opeParam.prjInfo.toolChain as DoFastToolChainType; diff --git a/src/function/lsp-client/index.ts b/src/function/lsp-client/index.ts index b168fbe..dc07c8c 100644 --- a/src/function/lsp-client/index.ts +++ b/src/function/lsp-client/index.ts @@ -16,6 +16,7 @@ import axios, { AxiosResponse } from "axios"; import { chooseBestDownloadSource, getGiteeDownloadLink, getGithubDownloadLink, getPlatformPlatformSignature } from "./cdn"; import { hdlDir, hdlPath } from "../../hdlFs"; import { registerConfigurationUpdater } from "./config"; +import { t } from "../../i18n"; function getLspServerExecutionName() { const osname = platform(); @@ -98,8 +99,6 @@ async function checkAndDownload(context: vscode.ExtensionContext, version: strin } export async function downloadLsp(context: vscode.ExtensionContext, version: string, versionFolderPath: string): Promise { - const { t } = vscode.l10n; - const downloadLink = await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: t('info.progress.choose-best-download-source') diff --git a/src/function/netlist/index.ts b/src/function/netlist/index.ts index 78ff679..546d30e 100644 --- a/src/function/netlist/index.ts +++ b/src/function/netlist/index.ts @@ -7,6 +7,7 @@ import { hdlParam } from '../../hdlParser'; import { hdlFile, hdlPath } from '../../hdlFs'; import { defaultMacro, doFastApi } from '../../hdlParser/util'; import { HdlFile } from '../../hdlParser/core'; +import { t } from '../../i18n'; class Netlist { @@ -19,7 +20,6 @@ class Netlist { } public async open(uri: vscode.Uri) { - const { t } = vscode.l10n; // get dependence of the current uri const prjFiles = []; diff --git a/src/function/sim/instance.ts b/src/function/sim/instance.ts index e55e319..d2cb4e3 100644 --- a/src/function/sim/instance.ts +++ b/src/function/sim/instance.ts @@ -4,6 +4,7 @@ import { hdlParam } from '../../hdlParser'; import { HdlModulePort, HdlModuleParam, HdlModulePortType } from '../../hdlParser/common'; import { HdlModule } from '../../hdlParser/core'; import { hdlFile, hdlPath } from '../../hdlFs'; +import { t } from '../../i18n'; class ModuleInfoItem { label: string; @@ -275,7 +276,6 @@ function getSelectItem(modules: HdlModule[]) { * @description 调用vscode的窗体,让用户从所有的Module中选择模块(为后续的例化准备) */ async function selectModuleFromAll() { - const { t } = vscode.l10n; const option = { placeHolder: t('info.command.instantiation.pick-title') }; diff --git a/src/function/tool.ts b/src/function/tool.ts index dc5e9c8..2fe7cdf 100644 --- a/src/function/tool.ts +++ b/src/function/tool.ts @@ -7,6 +7,7 @@ import { opeParam } from '../global'; import { hdlFile, hdlPath } from '../hdlFs'; import { ModuleDataItem } from './treeView/tree'; import { hdlParam } from '../hdlParser'; +import { t } from '../i18n'; async function insertTextToUri(uri: vscode.Uri, text: string, position?: vscode.Position) { if (!position) { @@ -47,7 +48,6 @@ const PPY_LIB_REPLACE: Record = { }; async function transformOldPpy() { - const { t } = vscode.l10n; const propertyJsonPath = opeParam.propertyJsonPath; if (fs.existsSync(propertyJsonPath)) { const oldPpyContent = hdlFile.readJSON(propertyJsonPath) as Record; @@ -117,7 +117,6 @@ async function transformOldPpy() { } async function askUserToSaveFilelist(filelist: string[]) { - const { t } = vscode.l10n; const topModulePath = filelist[0]; const defaultSaveName = fspath.basename(topModulePath, fspath.extname(topModulePath)); diff --git a/src/function/treeView/index.ts b/src/function/treeView/index.ts index 84142af..069bb26 100644 --- a/src/function/treeView/index.ts +++ b/src/function/treeView/index.ts @@ -7,6 +7,7 @@ import { hardwareTreeProvider, softwareTreeProvider, toolTreeProvider } from './ import { moduleTreeProvider, ModuleDataItem } from './tree'; import { Range } from '../../hdlParser/common'; import { MainOutput, opeParam, ReportType } from '../../global'; +import { t } from '../../i18n'; async function openFileAtPosition(uri: vscode.Uri, range?: Range) { @@ -16,7 +17,7 @@ async function openFileAtPosition(uri: vscode.Uri, range?: Range) { end: { line: 0, character: 0 } } } - const document = await vscode.workspace.openTextDocument(uri); + const document = await vscode.workspace.openTextDocument(uri); const start = new vscode.Position(range.start.line, range.start.character); const end = new vscode.Position(range.end.line, range.end.character); @@ -29,7 +30,6 @@ async function openFileAtPosition(uri: vscode.Uri, range?: Range) { } function openFileByUri(path: string, range: Range, element: ModuleDataItem) { - const { t } = vscode.l10n; if (range === undefined) { // vscode.window.showErrorMessage(`${path} not support jump yet`); return; @@ -53,7 +53,6 @@ function openFileByUri(path: string, range: Range, element: ModuleDataItem) { } function gotoXilinxIPDefinition(element: ModuleDataItem) { - const { t } = vscode.l10n; const folderPath = element.path; if (folderPath) { const ipName = fspath.basename(folderPath); diff --git a/src/function/treeView/tree.ts b/src/function/treeView/tree.ts index c698337..e0f9ee6 100644 --- a/src/function/treeView/tree.ts +++ b/src/function/treeView/tree.ts @@ -8,6 +8,7 @@ import { hdlFile, hdlPath } from '../../hdlFs'; import { xilinx, itemModes, otherModes } from './common'; import { getIconConfig } from '../../hdlFs/icons'; import { DoFastFileType } from '../../global/lsp'; +import { t } from '../../i18n'; let needExpand = true; @@ -109,12 +110,10 @@ class ModuleTreeProvider implements vscode.TreeDataProvider { public getTreeItem(element: ModuleDataItem): vscode.TreeItem | Thenable { - const { t } = vscode.l10n; let itemName = element.name; if (itemModes.has(element.icon)) { itemName = `${element.type}(${itemName})`; } - const expandable = canExpandable(element); let collapsibleState; if (!expandable) { diff --git a/src/global/prjInfo.ts b/src/global/prjInfo.ts index cfb6e41..0cefc3a 100644 --- a/src/global/prjInfo.ts +++ b/src/global/prjInfo.ts @@ -11,6 +11,7 @@ import assert = require('assert'); import * as hdlPath from '../hdlFs/path'; import { hdlDir } from '../hdlFs'; import { MainOutput } from './outputChannel'; +import { t } from '../i18n'; type AbsPath = string; @@ -400,7 +401,6 @@ class PrjInfo implements PrjInfoMeta { } public updateArch(arch?: Arch) { - const { t } = vscode.l10n; const workspacePath = this._workspacePath; if (arch) { // 如果配置中存在,直接根据用户配置的项来赋值 diff --git a/src/hdlParser/core.ts b/src/hdlParser/core.ts index 59916a5..2fad1a2 100644 --- a/src/hdlParser/core.ts +++ b/src/hdlParser/core.ts @@ -9,6 +9,7 @@ import * as common from './common'; import { hdlFile, hdlPath } from '../hdlFs'; import { defaultMacro, defaultRange, doPrimitivesJudgeApi, HdlSymbol } from './util'; import { DoFastFileType } from '../global/lsp'; +import { t } from '../i18n'; class HdlParam { @@ -253,10 +254,8 @@ class HdlParam { public async initializeHdlFiles(hdlFiles: AbsPath[], progress: vscode.Progress) { - const { t } = vscode.l10n; let count: number = 0; let fileNum = hdlFiles.length; - const parallelChunk = Math.min(os.cpus().length, 32); console.log("use cpu: " + parallelChunk); @@ -290,7 +289,6 @@ class HdlParam { } public async initializeIPsPath(IPsPath: string[], progress: vscode.Progress) { - const { t } = vscode.l10n; let count: number = 0; let fileNum = IPsPath.length; diff --git a/src/i18n/index.ts b/src/i18n/index.ts new file mode 100644 index 0000000..0da6c74 --- /dev/null +++ b/src/i18n/index.ts @@ -0,0 +1,24 @@ +import * as vscode from 'vscode'; +import { hdlFile } from '../hdlFs'; + +const defaultBundle: Record = {} + +export function initialiseI18n(context: vscode.ExtensionContext) { + if (vscode.l10n.bundle === undefined) { + const bundlePath = context.asAbsolutePath('l10n/bundle.l10n.en.json'); + const bundle = hdlFile.readJSON(bundlePath) as Record; + Object.assign(defaultBundle, bundle); + } +} + +export function t(message: string, ...args: string[]): string { + if (vscode.l10n.bundle === undefined) { + let translateMessage = defaultBundle[message] || message; + for (let i = 0; i < args.length; ++ i) { + translateMessage.replace(`{${i}}`, args[i]); + } + return translateMessage; + } else { + return vscode.l10n.t(message, ...args); + } +} \ No newline at end of file diff --git a/src/manager/PL/index.ts b/src/manager/PL/index.ts index dfe9d68..5379993 100644 --- a/src/manager/PL/index.ts +++ b/src/manager/PL/index.ts @@ -13,6 +13,7 @@ import { moduleTreeProvider, ModuleDataItem } from '../../function/treeView/tree import { HdlFileType } from '../../hdlParser/common'; import { PropertySchema } from '../../global/propertySchema'; import { HardwareOutput, ReportType } from '../../global/outputChannel'; +import { t } from '../../i18n'; class PlManage extends BaseManage { context: PLContext; @@ -96,7 +97,6 @@ class PlManage extends BaseManage { } public exit() { - const { t } = vscode.l10n; if (this.context.process === undefined) { return; diff --git a/src/manager/PL/xilinx.ts b/src/manager/PL/xilinx.ts index bafd5f3..9b0f3c3 100644 --- a/src/manager/PL/xilinx.ts +++ b/src/manager/PL/xilinx.ts @@ -12,6 +12,7 @@ import { PropertySchema } from '../../global/propertySchema'; import { XilinxIP } from '../../global/enum'; import { HardwareOutput, MainOutput, ReportType } from '../../global/outputChannel'; import { debounce } from '../../global/util'; +import { t } from '../../i18n'; interface XilinxCustom { ipRepo: AbsPath, @@ -139,8 +140,6 @@ class XilinxOperation { * @param context */ public async launch(context: PLContext): Promise { - const { t } = vscode.l10n; - this.guiLaunched = false; let scripts: string[] = []; @@ -244,7 +243,7 @@ class XilinxOperation { } messageBuffer.push(line); } - const launchInfo = vscode.l10n.t('info.pl.launch.launch-info'); + const launchInfo = t('info.pl.launch.launch-info'); messageBuffer.unshift(launchInfo); return messageBuffer.join("\n"); } @@ -582,8 +581,6 @@ file delete ${scriptPath} -force\n`; } public async gui(context: PLContext) { - const { t } = vscode.l10n; - if (context.process === undefined) { await this.launch(context); } @@ -597,8 +594,6 @@ file delete ${scriptPath} -force\n`; } public addFiles(files: string[], context: PLContext) { - const { t } = vscode.l10n; - if (!this.guiLaunched && files.length > 0) { const filesString = files.join("\n"); HardwareOutput.report(t('info.pl.add-files.title') + '\n' + filesString); @@ -607,8 +602,6 @@ file delete ${scriptPath} -force\n`; } public delFiles(files: string[], context: PLContext) { - const { t } = vscode.l10n; - if (!this.guiLaunched && files.length > 0) { const filesString = files.join("\n"); HardwareOutput.report(t('info.pl.del-files.title') + '\n' + filesString); diff --git a/src/monitor/event.ts b/src/monitor/event.ts index d5d2aa3..2e481c5 100644 --- a/src/monitor/event.ts +++ b/src/monitor/event.ts @@ -14,6 +14,7 @@ import { libManage } from '../manager/lib'; import type { HdlMonitor } from './index'; import { HdlLangID, ToolChainType } from '../global/enum'; import { vlogLinterManager, vhdlLinterManager, svlogLinterManager } from '../function/lsp/linter'; +import { t } from '../i18n'; enum Event { Add = 'add', // emit when add file @@ -281,8 +282,6 @@ class PpyAction extends BaseAction { public async refreshHdlMonitor(m: HdlMonitor, originalHdlFiles: AbsPath[]) { m.remakeHdlMonitor(); - - const { t } = vscode.l10n; const newFiles = await prjManage.getPrjHardwareFiles(); const { addFiles, delFiles } = this.diffNewOld(newFiles, originalHdlFiles);