diff --git a/src/extension.ts b/src/extension.ts index a5d7146..2bbdbda 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; -import { opeParam, MainOutput, AbsPath, ReportType, LspClient } from './global'; +import { opeParam, MainOutput, AbsPath, ReportType, LspClient, IProgress } from './global'; import { hdlParam } from './hdlParser'; import * as manager from './manager'; import * as func from './function'; @@ -25,7 +25,6 @@ async function registerCommand(context: vscode.ExtensionContext) { // lspClient.activateVHDL(context); } - async function launch(context: vscode.ExtensionContext) { await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, @@ -37,9 +36,9 @@ async function launch(context: vscode.ExtensionContext) { await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: 'Initialization (Digtial-IDE)' - }, async () => { + }, async (progress: vscode.Progress, token: vscode.CancellationToken) => { // 初始化解析 - await manager.prjManage.initialise(context); + await manager.prjManage.initialise(context, progress); // 这里是因为 pl 对象在 initialise 完成初始化,此处再注册它的行为 manager.registerManagerCommands(context); diff --git a/src/global/index.ts b/src/global/index.ts index 4b760cf..5e4b2ba 100644 --- a/src/global/index.ts +++ b/src/global/index.ts @@ -11,6 +11,12 @@ type RelPath = string; type AllowNull = T | null; + +interface IProgress { + message?: string, + increment?: number +} + export { opeParam, OpeParamDefaults, @@ -26,5 +32,6 @@ export { WaveViewOutput, ReportType, AllowNull, - LspClient + LspClient, + IProgress }; \ No newline at end of file diff --git a/src/hdlParser/core.ts b/src/hdlParser/core.ts index 8e57d7b..ccd8913 100644 --- a/src/hdlParser/core.ts +++ b/src/hdlParser/core.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; -import { AbsPath, opeParam } from '../global'; +import { AbsPath, IProgress, opeParam } from '../global'; import { HdlLangID } from '../global/enum'; import { MainOutput, ReportType } from '../global/outputChannel'; @@ -241,14 +241,44 @@ class HdlParam { } } - public async initHdlFiles(hdlFiles: AbsPath[] | Generator) { - for (const path of hdlFiles) { - await this.doHdlFast(path); + public async initHdlFiles(hdlFiles: AbsPath[], progress?: vscode.Progress) { + let count: number = 0; + let fileNum = hdlFiles.length; + const parallelChunk = 5; + + const pools: { id: number, promise: Promise }[] = []; + + vscode.window.showInformationMessage("files to handle: " + fileNum); + + async function consumePools() { + for (const p of pools) { + const increment = Math.floor(p.id / fileNum * 100); + await p.promise; + console.log("handle id " + p.id + ' increment: ' + increment); + + progress?.report({ message: `build module tree ${p.id}/${fileNum}`, increment }); + } + pools.length = 0; } + + for (const path of hdlFiles) { + count ++; + const p = this.doHdlFast(path); + pools.push({ id: count, promise: p }); + if (pools.length % parallelChunk === 0) { + // 消费并发池 + await consumePools(); + } + } + + if (pools.length > 0) { + await consumePools(); + } + } - public async initialize(hdlFiles: AbsPath[] | Generator) { - await this.initHdlFiles(hdlFiles); + public async initialize(hdlFiles: AbsPath[], progress: vscode.Progress) { + await this.initHdlFiles(hdlFiles, progress); for (const hdlFile of this.getAllHdlFiles()) { hdlFile.makeInstance(); diff --git a/src/hdlParser/util.ts b/src/hdlParser/util.ts index 684f400..e9b9594 100644 --- a/src/hdlParser/util.ts +++ b/src/hdlParser/util.ts @@ -11,12 +11,14 @@ 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; } } catch (error) { console.error("error happen when run doFastApi, " + error); + console.error("error file path: " + path); return undefined; } } diff --git a/src/manager/prj.ts b/src/manager/prj.ts index ece1fb8..ff4d234 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, MainOutput, opeParam, ReportType } from '../global'; +import { AbsPath, IProgress, MainOutput, opeParam, ReportType } from '../global'; import { PathSet } from '../global/util'; import { RawPrjInfo } from '../global/prjInfo'; import { hdlDir, hdlFile, hdlPath } from '../hdlFs'; @@ -136,7 +136,7 @@ class PrjManage { - public async initialise(context: vscode.ExtensionContext, countTimeCost: boolean = true) { + public async initialise(context: vscode.ExtensionContext, progress: vscode.Progress, countTimeCost: boolean = true) { if (countTimeCost) { console.time('launch'); } @@ -147,7 +147,7 @@ class PrjManage { const hdlFiles = await this.getPrjHardwareFiles(); MainOutput.report(`finish collect ${hdlFiles.length} hdl files`, ReportType.Info); - await hdlParam.initialize(hdlFiles); + await hdlParam.initialize(hdlFiles, progress); const unhandleNum = hdlParam.getUnhandleInstanceNumber(); MainOutput.report(`finish analyse ${hdlFiles.length} hdl files, find ${unhandleNum} unsolved instances`, ReportType.Info);