From f1b79b92d34266b7d33c0f38d55f9984a402c0c3 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Mon, 18 Nov 2024 16:26:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=9A=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E4=B8=AD=E9=BB=98=E8=AE=A4=E8=AF=AD=E8=A8=80=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/dide-doc/documentation.css | 25 +++++++++++++++++++++++++ resources/dide-doc/iconfont.css | 10 +++++++--- resources/dide-doc/iconfont.woff2 | Bin 1608 -> 1844 bytes src/extension.ts | 5 ++++- src/function/dide-viewer/api.ts | 6 +----- src/function/dide-viewer/index.ts | 2 +- src/function/hdlDoc/markdown.ts | 20 ++++++++++---------- src/function/index.ts | 3 ++- src/function/lsp-client/index.ts | 3 +-- src/function/netlist/index.ts | 2 +- src/function/sim/instance.ts | 2 +- src/function/tool.ts | 3 +-- src/function/treeView/index.ts | 5 ++--- src/function/treeView/tree.ts | 3 +-- src/global/prjInfo.ts | 2 +- src/hdlParser/core.ts | 4 +--- src/i18n/index.ts | 24 ++++++++++++++++++++++++ src/manager/PL/index.ts | 2 +- src/manager/PL/xilinx.ts | 11 ++--------- src/monitor/event.ts | 3 +-- 20 files changed, 87 insertions(+), 48 deletions(-) create mode 100644 src/i18n/index.ts 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 38df0317f25a203e22c0355c37a64c7705e98ad7..6e233832eee55ddb6098d79e649ddc261d353b0b 100644 GIT binary patch delta 1837 zcmV+|2h#Y+473gycTYw#00961000Lx01E&B000g!000K%kr*C-YzmH4j3EIw0we<< z3labXAO(bH2WT5949E_ptdNiZVBi5lJn(<`yKnr~ECTOSk z|9_iyANb55o;VfdED_O_7#*N>Y=$^=G8G@HDcN3-ETVNGl6cD9xlS=c61 zLgVV{-0>6Qx`IQ0R4CNDI%dbRj)iJ!Os%anH3`pMCeKT=t@*nm$+GCL81RY9&miPBk0c7ei{$}gdk z&X#6q^405q!dlp^4PjVFA3-RvH)_C9G!nrGz^`Lk;C6-dSm?wa1BxUfJw#*|SY?6d z6ov&Ok_{n4bcx3yfhaCRSTJ5ld_sqhgmvLWT994a$JAeYWjw+gxQ<~61GVYZRe(Bp zQ|=m$10KvHHxL3B1L7Ad1j`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oJYBd1pc0+8v6;W)yFTO^DrCwTMT0N=3BjhWM+UUGRE&TH}mjtJZ=^00y|L zx3n-rm7!AS-e2{Gv?%GU}R)>nigep--goYq{}-&dAf2KU;3Wf)Ge z%_>5kbno`KIh}Y`U|k>I*Y}yWp)H@w8vkyYp^-l6)k`ozcL0*thr69)A^B*y!8s5> zO;kYgpsG?WAbC#RRSmwyTXFE0&_i4Mo9F+q=REDPl5($Ps6mCmx6p=I`<=CQ6^^NA zIdFB==vGVZT{eRUZ|)Tg2KbVHCNuJ2bM{PPD}M|2ObJ-HG=nY1^=>twk4-x-WZjj z1-*mPQ0I(8xYlpXSB>Jb(m!%2QGhf`@(o|uA+KYfu+B3P2ac(Q&))TauxSW9Q-wyN zLd4(3v8&oAGSv3oU=W4)+!jEylP@t49d2yN{=RRJoD~fU79#$`Oz3E+b|57p5g@*- zooK`Z=^j{H<)qeV_xAQqUIG}@ xySQSB5-qkk;)=&~JaX9{P`(iIH!ay!gTwgZbFWynD9F=QS9i4OMxI!DJpeU+5`F*x 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);