多线程解析

This commit is contained in:
锦恢 2024-09-23 20:56:46 +08:00
parent 4d93f443fa
commit 306c57f07e
5 changed files with 52 additions and 14 deletions

View File

@ -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<IProgress>, token: vscode.CancellationToken) => {
// 初始化解析
await manager.prjManage.initialise(context);
await manager.prjManage.initialise(context, progress);
// 这里是因为 pl 对象在 initialise 完成初始化,此处再注册它的行为
manager.registerManagerCommands(context);

View File

@ -11,6 +11,12 @@ type RelPath = string;
type AllowNull<T> = T | null;
interface IProgress {
message?: string,
increment?: number
}
export {
opeParam,
OpeParamDefaults,
@ -26,5 +32,6 @@ export {
WaveViewOutput,
ReportType,
AllowNull,
LspClient
LspClient,
IProgress
};

View File

@ -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<AbsPath>) {
public async initHdlFiles(hdlFiles: AbsPath[], progress?: vscode.Progress<IProgress>) {
let count: number = 0;
let fileNum = hdlFiles.length;
const parallelChunk = 5;
const pools: { id: number, promise: Promise<void> }[] = [];
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) {
await this.doHdlFast(path);
count ++;
const p = this.doHdlFast(path);
pools.push({ id: count, promise: p });
if (pools.length % parallelChunk === 0) {
// 消费并发池
await consumePools();
}
}
public async initialize(hdlFiles: AbsPath[] | Generator<AbsPath>) {
await this.initHdlFiles(hdlFiles);
if (pools.length > 0) {
await consumePools();
}
}
public async initialize(hdlFiles: AbsPath[], progress: vscode.Progress<IProgress>) {
await this.initHdlFiles(hdlFiles, progress);
for (const hdlFile of this.getAllHdlFiles()) {
hdlFile.makeInstance();

View File

@ -11,12 +11,14 @@ async function doFastApi(path: string): Promise<Fast | undefined> {
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;
}
}

View File

@ -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<IProgress>, 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);