From 5cafbc67a6bdb3e03b8e7215f9ce68a43dfcee48 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Sun, 22 Sep 2024 21:40:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E7=BA=BF=E6=96=B0=E7=9A=84=E5=90=8E?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/hdlParser/index.js | 2 +- src/extension.ts | 14 ++++++++-- src/global/lsp.ts | 29 +++++++++++++++++++- src/hdlParser/core.ts | 16 +++++------ src/hdlParser/util.ts | 53 ++++++++++++++++++++++++++++++++++-- 5 files changed, 98 insertions(+), 16 deletions(-) diff --git a/resources/hdlParser/index.js b/resources/hdlParser/index.js index 93f9bf3..725d901 100644 --- a/resources/hdlParser/index.js +++ b/resources/hdlParser/index.js @@ -51,7 +51,7 @@ async function callParser(path, func) { // console.log(res); debug.compute += Date.now() - s3; - console.log(path, debug); + // console.log(path, debug); return JSON.parse(res); } catch (error) { console.log(`errors happen when call wasm, path: ${path}, errors: ${error}, input params: (${path}, ${func})`); diff --git a/src/extension.ts b/src/extension.ts index 9f95002..e4c1a69 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,8 +12,6 @@ import * as lspClient from './function/lsp-client'; async function registerCommand(context: vscode.ExtensionContext) { - manager.registerManagerCommands(context); - func.registerFunctionCommands(context); func.registerLsp(context); func.registerToolCommands(context); @@ -28,15 +26,25 @@ async function registerCommand(context: vscode.ExtensionContext) { async function launch(context: vscode.ExtensionContext) { + await vscode.window.withProgress({ + location: vscode.ProgressLocation.Window, + title: 'Register Command (Digtial-IDE)' + }, async () => { + await registerCommand(context); + }); + await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: 'Initialization (Digtial-IDE)' }, async () => { await manager.prjManage.initialise(context); - await registerCommand(context); + manager.registerManagerCommands(context); + hdlMonitor.start(); }); + + MainOutput.report('Digital-IDE has launched, Version: 0.3.3', ReportType.Launch); MainOutput.report('OS: ' + opeParam.os, ReportType.Launch); diff --git a/src/global/lsp.ts b/src/global/lsp.ts index 6d20499..ceb7cba 100644 --- a/src/global/lsp.ts +++ b/src/global/lsp.ts @@ -1,4 +1,6 @@ +import * as vscode from 'vscode'; import { LanguageClient, RequestType, ProtocolConnection } from 'vscode-languageclient/node'; +import { Fast } from '../../resources/hdlParser'; interface IDigitalIDELspClient { @@ -11,4 +13,29 @@ export const LspClient: IDigitalIDELspClient = { VhdlClient: undefined }; -export const CustomRequestType = new RequestType('custom/request'); +/** + * @description 构造请求参数 + * RequestType + * P: 请求的参数类型。 + * R: 请求的响应类型。 + * E: 请求的错误类型。 + * RO: 请求的可选参数类型。 + */ +export const CustomRequestType = new RequestType('custom/request'); +export const CustomParamRequestType = new RequestType('custom/paramRequest'); +export const DoFastRequestType = new RequestType('api/fast'); + +export interface ITextDocumentItem { + uri: vscode.Uri, + languageId: string, + version: number, + text: string +} + +export interface ICommonParam { + param: string +} + +export interface IDoFastParam { + +} \ No newline at end of file diff --git a/src/hdlParser/core.ts b/src/hdlParser/core.ts index 0950cdb..441f827 100644 --- a/src/hdlParser/core.ts +++ b/src/hdlParser/core.ts @@ -227,10 +227,9 @@ class HdlParam { private async doHdlFast(path: AbsPath) { try { - // TODO: make this quick - const fast = await HdlSymbol.fast(path); + const fast = await HdlSymbol.fast(path); if (fast) { - const languageId = this.alignLanguageId(fast.languageId); + const languageId = hdlFile.getLanguageId(path); new HdlFile(path, languageId, fast.macro, @@ -248,13 +247,12 @@ class HdlParam { } } - public async initialize(hdlFiles: AbsPath[] | Generator) { + public async initialize(hdlFiles: AbsPath[] | Generator) { + await this.initHdlFiles(hdlFiles); - // await this.initHdlFiles(hdlFiles); - - // for (const hdlFile of this.getAllHdlFiles()) { - // hdlFile.makeInstance(); - // } + for (const hdlFile of this.getAllHdlFiles()) { + hdlFile.makeInstance(); + } } public getTopModulesByType(type: string): HdlModule[] { diff --git a/src/hdlParser/util.ts b/src/hdlParser/util.ts index 8880ae9..30e8e28 100644 --- a/src/hdlParser/util.ts +++ b/src/hdlParser/util.ts @@ -1,9 +1,53 @@ -import { Fast, vlogAll, vlogFast, vhdlAll, svFast, svAll, vhdlFast, All } from '../../resources/hdlParser'; +import * as vscode from 'vscode'; +import { Fast, vlogAll, vhdlAll, svAll, vhdlFast, All } from '../../resources/hdlParser'; import { hdlFile } from '../hdlFs'; import { HdlLangID } from '../global/enum'; -import { AbsPath } from '../global'; +import { AbsPath, LspClient } from '../global'; +import { DoFastRequestType, ITextDocumentItem, CustomParamRequestType } from '../global/lsp'; +import { RawHdlModule } from './common'; + +async function doFastApi(path: string): Promise { + try { + const client = LspClient.MainClient; + const langID = hdlFile.getLanguageId(path); + if (client) { + const response = await client.sendRequest(DoFastRequestType, { path }) as { fast: any }; + if (response.fast instanceof Array) { + const rawModules = response.fast as RawHdlModule[]; + return { + content: rawModules, + languageId: langID, + macro: { + errors: [], + defines: [], + includes: [], + invalid: [] + } + }; + } + } + } catch (error) { + console.error("error happen when run doFastApi, " + error); + return undefined; + } +} + +async function vlogFast(path: string): Promise { + const fast = await doFastApi(path); + return fast; +} + +async function svFast(path: string): Promise { + const fast = await doFastApi(path); + return fast; +} namespace HdlSymbol { + /** + * @description 计算出模块级的信息 + * @param path 文件绝对路径 + * @returns + */ export function fast(path: AbsPath): Promise { const langID = hdlFile.getLanguageId(path); switch (langID) { @@ -14,6 +58,11 @@ namespace HdlSymbol { } } + /** + * @description 0.4.0 后丢弃 + * @param path 文件绝对路径 + * @returns + */ export function all(path: AbsPath): Promise { const langID = hdlFile.getLanguageId(path); switch (langID) {