From e016893bd610d94a2e382e1042af393a2dc468cf Mon Sep 17 00:00:00 2001 From: wangshi Date: Fri, 7 Feb 2025 17:08:29 +0800 Subject: [PATCH 1/4] refator h2dts,h2dtscpp,h2sa,h2hdf,dts2cpp Signed-off-by: wangshi --- .../src/controller/crosscompilectrl.ts | 67 +++++++++++++++++ .../src/controller/dts2cppctrl.ts | 67 +++++++++++++++++ .../src/controller/h2dtscppctrl.ts | 67 +++++++++++++++++ src/vscode_plugin/src/controller/h2dtsctrl.ts | 72 +++++++++---------- src/vscode_plugin/src/controller/h2hdfctrl.ts | 67 +++++++++++++++++ src/vscode_plugin/src/controller/h2sactrl.ts | 69 ++++++++++++++++++ .../src/controller/welcomectrl.ts | 67 +++++++++++++++++ 7 files changed, 439 insertions(+), 37 deletions(-) create mode 100644 src/vscode_plugin/src/controller/crosscompilectrl.ts create mode 100644 src/vscode_plugin/src/controller/dts2cppctrl.ts create mode 100644 src/vscode_plugin/src/controller/h2dtscppctrl.ts create mode 100644 src/vscode_plugin/src/controller/h2hdfctrl.ts create mode 100644 src/vscode_plugin/src/controller/h2sactrl.ts create mode 100644 src/vscode_plugin/src/controller/welcomectrl.ts diff --git a/src/vscode_plugin/src/controller/crosscompilectrl.ts b/src/vscode_plugin/src/controller/crosscompilectrl.ts new file mode 100644 index 00000000..5f87ce69 --- /dev/null +++ b/src/vscode_plugin/src/controller/crosscompilectrl.ts @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { Uri } from "vscode"; +import { CrossCompileMod } from "../model/crosscompilemod"; +import { IModel } from "../model/imodel"; +import { CrossCompileView } from "../view/crosscompileview"; + +import { IView } from "../view/iview"; +import { IController } from "./icontroller"; +import { EVENT_ERROR } from "../common/eventtype"; + +export class CrossCompileCtrl extends IController { + name: string; + view: IView; + model: IModel; + uri: Uri; + constructor(uri: Uri) { + super(); + this.name = 'crosscompilectrl'; + this.model = CrossCompileMod.getInstance(); + this.view = new CrossCompileView; + this.uri = uri; + } + + public init(): void { + if (this.uri && this.uri.fsPath) { + this.view.init(this); + this.model.init(this.uri); + this.view.showProgress(); + } + } + + public start(): void { + try { + this.model.doStart(); + } catch(e) { + let errmsg = "h2dts start error: " + JSON.stringify(e) + console.error(errmsg); + this.view.showMsg(EVENT_ERROR, errmsg); + } + } + + public stop(): void { + throw new Error("Method not implemented."); + } + + public pause(): void { + throw new Error("Method not implemented."); + } + + public resume(): void { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/controller/dts2cppctrl.ts b/src/vscode_plugin/src/controller/dts2cppctrl.ts new file mode 100644 index 00000000..28850027 --- /dev/null +++ b/src/vscode_plugin/src/controller/dts2cppctrl.ts @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { Uri } from "vscode"; +import { Dts2cppMod } from "../model/dts2cppmod"; +import { IModel } from "../model/imodel"; +import { Dts2cppView } from "../view/dts2cppview"; + +import { IView } from "../view/iview"; +import { IController } from "./icontroller"; +import { EVENT_ERROR } from "../common/eventtype"; + +export class Dts2cppCtrl extends IController { + name: string; + view: IView; + model: IModel; + uri: Uri; + constructor(uri: Uri) { + super(); + this.name = 'dts2cppctrl'; + this.model = Dts2cppMod.getInstance(); + this.view = new Dts2cppView; + this.uri = uri; + } + + public init(): void { + if (this.uri && this.uri.fsPath) { + this.view.init(this); + this.model.init(this.uri); + this.view.showProgress(); + } + } + + public start(): void { + try { + this.model.doStart(); + } catch(e) { + let errmsg = this.name + " start error: " + JSON.stringify(e) + console.error(errmsg); + this.view.showMsg(EVENT_ERROR, errmsg); + } + } + + public stop(): void { + throw new Error("Method not implemented."); + } + + public pause(): void { + throw new Error("Method not implemented."); + } + + public resume(): void { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/controller/h2dtscppctrl.ts b/src/vscode_plugin/src/controller/h2dtscppctrl.ts new file mode 100644 index 00000000..b05feeb2 --- /dev/null +++ b/src/vscode_plugin/src/controller/h2dtscppctrl.ts @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { Uri } from "vscode"; +import { IModel } from "../model/imodel"; + +import { IView } from "../view/iview"; +import { IController } from "./icontroller"; +import { EVENT_ERROR } from "../common/eventtype"; +import { H2dtscppView } from "../view/h2dtscppview"; +import { H2dtscppMod } from "../model/h2dtscppmod"; + +export class H2dtscppCtrl extends IController { + name: string; + view: IView; + model: IModel; + uri: Uri; + constructor(uri: Uri) { + super(); + this.name = 'h2dtsctrl'; + this.model = H2dtscppMod.getInstance(); + this.view = new H2dtscppView; + this.uri = uri; + } + + public init(): void { + if (this.uri && this.uri.fsPath) { + this.view.init(this); + this.model.init(this.uri); + this.view.showProgress(); + } + } + + public start(): void { + try { + this.model.doStart(); + } catch(e) { + let errmsg = "h2dts start error: " + JSON.stringify(e) + console.error(errmsg); + this.view.showMsg(EVENT_ERROR, errmsg); + } + } + + public stop(): void { + throw new Error("Method not implemented."); + } + + public pause(): void { + throw new Error("Method not implemented."); + } + + public resume(): void { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/controller/h2dtsctrl.ts b/src/vscode_plugin/src/controller/h2dtsctrl.ts index 7e92f669..cf8ad3f1 100644 --- a/src/vscode_plugin/src/controller/h2dtsctrl.ts +++ b/src/vscode_plugin/src/controller/h2dtsctrl.ts @@ -23,47 +23,45 @@ import { IController } from "./icontroller"; import { EVENT_ERROR } from "../common/eventtype"; export class H2dtsCtrl extends IController { - name: string; - view: IView; - model: IModel; - uri: Uri; - constructor(uri: Uri) { - super(); - this.name = 'h2dtsctrl'; - this.model = H2dtsMod.getInstance(); - this.view = new H2dtsView; - this.uri = uri; - } + name: string; + view: IView; + model: IModel; + uri: Uri; + constructor(uri: Uri) { + super(); + this.name = 'h2dtsctrl'; + this.model = H2dtsMod.getInstance(); + this.view = new H2dtsView; + this.uri = uri; + } - public init(): void { - if (this.uri && this.uri.fsPath) { - this.view.init(this); - this.model.init(this.uri); - this.view.showProgress(); - } + public init(): void { + if (this.uri && this.uri.fsPath) { + this.view.init(this); + this.model.init(this.uri); + this.view.showProgress(); } + } - public start(): void { - try { - this.model.doStart(); - } catch(e) { - let errmsg = "h2dts start error: " + JSON.stringify(e) - console.error(errmsg); - this.view.showMsg(EVENT_ERROR, errmsg); - } - - } + public start(): void { + try { + this.model.doStart(); + } catch(e) { + let errmsg = "h2dts start error: " + JSON.stringify(e) + console.error(errmsg); + this.view.showMsg(EVENT_ERROR, errmsg); + } + } - public stop(): void { - throw new Error("Method not implemented."); - } + public stop(): void { + throw new Error("Method not implemented."); + } - public pause(): void { - throw new Error("Method not implemented."); - } + public pause(): void { + throw new Error("Method not implemented."); + } - public resume(): void { - throw new Error("Method not implemented."); - } - + public resume(): void { + throw new Error("Method not implemented."); + } } \ No newline at end of file diff --git a/src/vscode_plugin/src/controller/h2hdfctrl.ts b/src/vscode_plugin/src/controller/h2hdfctrl.ts new file mode 100644 index 00000000..cb218462 --- /dev/null +++ b/src/vscode_plugin/src/controller/h2hdfctrl.ts @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { Uri } from "vscode"; +import { H2hdfMod } from "../model/h2hdfmod"; +import { IModel } from "../model/imodel"; +import { H2hdfView } from "../view/h2hdfview"; + +import { IView } from "../view/iview"; +import { IController } from "./icontroller"; +import { EVENT_ERROR } from "../common/eventtype"; + +export class H2hdfCtrl extends IController { + name: string; + view: IView; + model: IModel; + uri: Uri; + constructor(uri: Uri) { + super(); + this.name = 'H2hdfCtrl'; + this.model = H2hdfMod.getInstance(); + this.view = new H2hdfView; + this.uri = uri; + } + + public init(): void { + if (this.uri && this.uri.fsPath) { + this.view.init(this); + this.model.init(this.uri); + this.view.showProgress(); + } + } + + public start(): void { + try { + this.model.doStart(); + } catch(e) { + let errmsg = this.name + " start error: " + JSON.stringify(e) + console.error(errmsg); + this.view.showMsg(EVENT_ERROR, errmsg); + } + } + + public stop(): void { + throw new Error("Method not implemented."); + } + + public pause(): void { + throw new Error("Method not implemented."); + } + + public resume(): void { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/controller/h2sactrl.ts b/src/vscode_plugin/src/controller/h2sactrl.ts new file mode 100644 index 00000000..3bca4468 --- /dev/null +++ b/src/vscode_plugin/src/controller/h2sactrl.ts @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { Uri } from "vscode"; +import { H2saMod } from "../model/h2samod"; +import { IModel } from "../model/imodel"; +import { H2saView } from "../view/h2saview"; + +import { IView } from "../view/iview"; +import { IController } from "./icontroller"; +import { EVENT_ERROR } from "../common/eventtype"; + +export class H2saCtrl extends IController { + name: string; + view: IView; + model: IModel; + uri: Uri; + constructor(uri: Uri) { + super(); + this.name = 'h2sactrl'; + this.model = H2saMod.getInstance(); + this.view = new H2saView; + this.uri = uri; + } + + public init(): void { + if (this.uri && this.uri.fsPath) { + this.view.init(this); + this.model.init(this.uri); + this.view.showProgress(); + } + } + + public start(): void { + try { + this.model.doStart(); + } catch(e) { + let errmsg = this.name + " start error: " + JSON.stringify(e) + console.error(errmsg); + this.view.showMsg(EVENT_ERROR, errmsg); + } + + } + + public stop(): void { + throw new Error("Method not implemented."); + } + + public pause(): void { + throw new Error("Method not implemented."); + } + + public resume(): void { + throw new Error("Method not implemented."); + } + +} \ No newline at end of file diff --git a/src/vscode_plugin/src/controller/welcomectrl.ts b/src/vscode_plugin/src/controller/welcomectrl.ts new file mode 100644 index 00000000..8d6a424b --- /dev/null +++ b/src/vscode_plugin/src/controller/welcomectrl.ts @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { Uri } from "vscode"; +import { WelcomeMod } from "../model/welcomemod"; +import { IModel } from "../model/imodel"; +import { WelcomeView } from "../view/welcomeview"; + +import { IView } from "../view/iview"; +import { IController } from "./icontroller"; +import { EVENT_ERROR } from "../common/eventtype"; + +export class WelcomeCtrl extends IController { + name: string; + view: IView; + model: IModel; + uri: Uri; + constructor(uri: Uri) { + super(); + this.name = 'welcomectrl'; + this.model = WelcomeMod.getInstance(); + this.view = new WelcomeView; + this.uri = uri; + } + + public init(): void { + if (this.uri && this.uri.fsPath) { + this.view.init(this); + this.model.init(this.uri); + this.view.showProgress(); + } + } + + public start(): void { + try { + this.model.doStart(); + } catch(e) { + let errmsg = this.name + " start error: " + JSON.stringify(e) + console.error(errmsg); + this.view.showMsg(EVENT_ERROR, errmsg); + } + } + + public stop(): void { + throw new Error("Method not implemented."); + } + + public pause(): void { + throw new Error("Method not implemented."); + } + + public resume(): void { + throw new Error("Method not implemented."); + } +} \ No newline at end of file -- Gitee From e015596d2ff139a79e5b07b6d4178ee6e4956dc1 Mon Sep 17 00:00:00 2001 From: wangshi Date: Fri, 7 Feb 2025 17:08:40 +0800 Subject: [PATCH 2/4] refator h2dts,h2dtscpp,h2sa,h2hdf,dts2cpp Signed-off-by: wangshi --- .../src/model/crosscompilemod.ts | 86 ++++++++++++ src/vscode_plugin/src/model/dts2cppmod.ts | 107 +++++++++++++++ src/vscode_plugin/src/model/h2dtscppmod.ts | 105 +++++++++++++++ src/vscode_plugin/src/model/h2dtsmod.ts | 103 +++++++------- src/vscode_plugin/src/model/h2hdfmod.ts | 115 ++++++++++++++++ src/vscode_plugin/src/model/h2samod.ts | 115 ++++++++++++++++ src/vscode_plugin/src/model/welcomemod.ts | 127 ++++++++++++++++++ 7 files changed, 706 insertions(+), 52 deletions(-) create mode 100644 src/vscode_plugin/src/model/crosscompilemod.ts create mode 100644 src/vscode_plugin/src/model/dts2cppmod.ts create mode 100644 src/vscode_plugin/src/model/h2dtscppmod.ts create mode 100644 src/vscode_plugin/src/model/h2hdfmod.ts create mode 100644 src/vscode_plugin/src/model/h2samod.ts create mode 100644 src/vscode_plugin/src/model/welcomemod.ts diff --git a/src/vscode_plugin/src/model/crosscompilemod.ts b/src/vscode_plugin/src/model/crosscompilemod.ts new file mode 100644 index 00000000..17f2714f --- /dev/null +++ b/src/vscode_plugin/src/model/crosscompilemod.ts @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import * as path from 'path'; +import { IModel } from "./imodel"; +import { parseHeaderFile } from '../parse/parsec'; +import { GenInfo } from '../gen/datatype'; +import { genDtsFile } from '../gen/gendts'; +import { GEN_COMPLETE, PARSE_COMPLETE } from '../common/constants'; + +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; + +export class CrossCompileMod extends IModel { + name: string; + private static instance: CrossCompileMod; + constructor() { + super(); + this.name = 'h2dtsmod'; + } + + static getInstance(): IModel { + if (!CrossCompileMod.instance) { + CrossCompileMod.instance = new CrossCompileMod(); + } + return CrossCompileMod.instance; + } + + init(uri: vscode.Uri): void { + this.uri = uri; + } + + async doStart(): Promise { + try { + if (this.uri) { + // parse + let parseRes = await parseHeaderFile(this.uri.fsPath); + console.log('parse header file res: ', parseRes); + this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE); + + let rootInfo: GenInfo = { + parseObj: parseRes, + rawFilePath: this.uri.fsPath, // e://xxx.h + fileName: path.basename(this.uri.fsPath, '.h') // xxx + }; + // generator + let outPath = genDtsFile(rootInfo); + this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE); + } else { + console.error('parse header file error with undefine uri.'); + } + } catch (e) { + let errmsg = 'parse header file error: ' + JSON.stringify(e); + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } + + async doStop(): Promise { + throw new Error("Method not implemented."); + } + + async doPause(): Promise { + throw new Error("Method not implemented."); + } + + async doResume(): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/model/dts2cppmod.ts b/src/vscode_plugin/src/model/dts2cppmod.ts new file mode 100644 index 00000000..f8f58bd2 --- /dev/null +++ b/src/vscode_plugin/src/model/dts2cppmod.ts @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import * as path from 'path'; +import { IModel } from "./imodel"; +import { parseHeaderFile } from '../parse/parsec'; +import { GenInfo } from '../gen/datatype'; +import { genDtsFile } from '../gen/gendts'; +import { GEN_COMPLETE, OPEN_IN_EXPLORER, PARSE_COMPLETE } from '../common/constants'; + +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { parseTsFile } from '../parse/parsets'; +import { genCppFile } from '../gen/gendtscpp'; + +export class Dts2cppMod extends IModel { + name: string; + private static instance: Dts2cppMod; + constructor() { + super(); + this.name = 'dts2cppmod'; + } + + static getInstance(): IModel { + if (!Dts2cppMod.instance) { + Dts2cppMod.instance = new Dts2cppMod(); + } + return Dts2cppMod.instance; + } + + init(uri: vscode.Uri): void { + this.uri = uri; + } + + async doStart(): Promise { + try { + if (this.uri) { + const filename = path.basename(this.uri.fsPath); + console.log('get filename ' ); + if (filename.endsWith('.d.ts')) { + // Display a message box to the user + // analyze + let res = parseTsFile(this.uri.fsPath); + console.info('res: ' + JSON.stringify(res)); + // progress.report({ increment: 50, message: PARSE_COMPLETE }); + this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE); + // generator + let out = path.dirname(this.uri.fsPath); + genCppFile(res, this.uri.fsPath, out); + // progress.report({ increment: 100, message: GEN_COMPLETE + out }); + this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE + out); + + // show genarate path + const choice = await vscode.window.showInformationMessage( + 'outPath:', path.dirname(this.uri.fsPath), OPEN_IN_EXPLORER); + if (choice === OPEN_IN_EXPLORER) { + // open the folder + vscode.commands.executeCommand( + 'revealFileInOS', vscode.Uri.file(this.uri.fsPath)); + } + } else { + let errmsg = 'not dts uri is : ' + this.uri.fsPath; + console.error(errmsg); + // Display a message box to the user + //vscode.window.showInformationMessage(`${this.uri.fsPath} is not a .d.ts file!`); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } else { + let errmsg = 'parse header file error with undefine uri'; + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } catch (e) { + let errmsg = 'parse header file error: ' + JSON.stringify(e); + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } + + async doStop(): Promise { + throw new Error("Method not implemented."); + } + + async doPause(): Promise { + throw new Error("Method not implemented."); + } + + async doResume(): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/model/h2dtscppmod.ts b/src/vscode_plugin/src/model/h2dtscppmod.ts new file mode 100644 index 00000000..431827c7 --- /dev/null +++ b/src/vscode_plugin/src/model/h2dtscppmod.ts @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import * as path from 'path'; +import { IModel } from "./imodel"; +import { parseHeaderFile } from '../parse/parsec'; +import { DtscppRootInfo, GenInfo } from '../gen/datatype'; +import { genDtsFile } from '../gen/gendts'; +import { GEN_COMPLETE, OPEN_IN_EXPLORER, PARSE_COMPLETE } from '../common/constants'; + +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { genDtsCppFile } from '../gen/gendtscpp'; + +export class H2dtscppMod extends IModel { + name: string; + private static instance: H2dtscppMod; + constructor() { + super(); + this.name = 'h2dtscppmod'; + } + + static getInstance(): IModel { + if (!H2dtscppMod.instance) { + H2dtscppMod.instance = new H2dtscppMod(); + } + return H2dtscppMod.instance; + } + + init(uri: vscode.Uri): void { + this.uri = uri; + } + + async doStart(): Promise { + try { + if (this.uri) { + // analyze + let funDescList = await parseHeaderFile(this.uri.fsPath); + let fileName = path.basename(this.uri.fsPath, '.h'); + console.log('parse header file res: ', funDescList); + console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); + + // progress.report({ increment: 50, message: PARSE_COMPLETE }); + this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE); + + let rootInfo: DtscppRootInfo = { + funcs: funDescList.funcs, + rawFilePath: this.uri.fsPath, + fileName: fileName // xxx + }; + + // generator + let out = path.dirname(this.uri.fsPath); + genDtsCppFile(rootInfo, out); + // progress.report({ increment: 100, message: GEN_COMPLETE + out }); + this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE + out); + + // show genarate path + const choice = await vscode.window.showInformationMessage( + 'outPath:', path.dirname(this.uri.fsPath), OPEN_IN_EXPLORER); + if (choice === OPEN_IN_EXPLORER) { + // open the folder + vscode.commands.executeCommand( + 'revealFileInOS', vscode.Uri.file(this.uri.fsPath)); + } + } else { + let errmsg = 'parse header file error with undefine uri'; + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } catch (e) { + let errmsg = 'parse header file error: ' + JSON.stringify(e); + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } + + async doStop(): Promise { + throw new Error("Method not implemented."); + } + + async doPause(): Promise { + throw new Error("Method not implemented."); + } + + async doResume(): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/model/h2dtsmod.ts b/src/vscode_plugin/src/model/h2dtsmod.ts index dbf24343..dbc1a1d6 100644 --- a/src/vscode_plugin/src/model/h2dtsmod.ts +++ b/src/vscode_plugin/src/model/h2dtsmod.ts @@ -20,68 +20,67 @@ import { GenInfo } from '../gen/datatype'; import { genDtsFile } from '../gen/gendts'; import { GEN_COMPLETE, PARSE_COMPLETE } from '../common/constants'; -import { - EVENT_ERROR, - EVENT_INFORMATION, - EVENT_PROGRESS, - EVENT_WARNING +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING } from '../common/eventtype'; export class H2dtsMod extends IModel { - name: string; - private static instance: H2dtsMod; - constructor() { - super(); - this.name = 'h2dtsmod'; - } + name: string; + private static instance: H2dtsMod; + constructor() { + super(); + this.name = 'h2dtsmod'; + } - static getInstance(): IModel { - if (!H2dtsMod.instance) { - H2dtsMod.instance = new H2dtsMod(); - } - return H2dtsMod.instance; + static getInstance(): IModel { + if (!H2dtsMod.instance) { + H2dtsMod.instance = new H2dtsMod(); } + return H2dtsMod.instance; + } - init(uri: vscode.Uri): void { - this.uri = uri; - } + init(uri: vscode.Uri): void { + this.uri = uri; + } - async doStart(): Promise { - try { - if (this.uri) { - // parse - let parseRes = await parseHeaderFile(this.uri.fsPath); - console.log('parse header file res: ', parseRes); - this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE); - - let rootInfo: GenInfo = { - parseObj: parseRes, - rawFilePath: this.uri.fsPath, // e://xxx.h - fileName: path.basename(this.uri.fsPath, '.h') // xxx - }; - // generator - let outPath = genDtsFile(rootInfo); - this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE); - } else { - console.error('parse header file error with undefine uri.'); - } - } catch (e) { - let errmsg = 'parse header file error: ' + JSON.stringify(e); - console.error(errmsg); - this.emmitEventForKey(EVENT_ERROR, -1, errmsg); - } - } + async doStart(): Promise { + try { + if (this.uri) { + // parse + let parseRes = await parseHeaderFile(this.uri.fsPath); + console.log('parse header file res: ', parseRes); + this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE); - async doStop(): Promise { - throw new Error("Method not implemented."); + let rootInfo: GenInfo = { + parseObj: parseRes, + rawFilePath: this.uri.fsPath, // e://xxx.h + fileName: path.basename(this.uri.fsPath, '.h') // xxx + }; + // generator + let outPath = genDtsFile(rootInfo); + this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE); + } else { + console.error('parse header file error with undefine uri.'); + } + } catch (e) { + let errmsg = 'parse header file error: ' + JSON.stringify(e); + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); } + } - async doPause(): Promise { - throw new Error("Method not implemented."); - } + async doStop(): Promise { + throw new Error("Method not implemented."); + } - async doResume(): Promise { - throw new Error("Method not implemented."); - } + async doPause(): Promise { + throw new Error("Method not implemented."); + } + async doResume(): Promise { + throw new Error("Method not implemented."); + } } \ No newline at end of file diff --git a/src/vscode_plugin/src/model/h2hdfmod.ts b/src/vscode_plugin/src/model/h2hdfmod.ts new file mode 100644 index 00000000..4fb7e5de --- /dev/null +++ b/src/vscode_plugin/src/model/h2hdfmod.ts @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import * as path from 'path'; +import { IModel } from "./imodel"; +import { parseHeaderFile } from '../parse/parsec'; +import { GenInfo } from '../gen/datatype'; +import { genDtsFile } from '../gen/gendts'; +import { GEN_COMPLETE, OPEN_IN_EXPLORER, PARSE_COMPLETE } from '../common/constants'; + +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; + +import { genHdfFile } from '../gen/genhdf'; + +export class H2hdfMod extends IModel { + name: string; + versionTag: string = '4.1'; + serviceId: string = '19000'; + private static instance: H2hdfMod; + + constructor() { + super(); + this.name = 'h2dtsmod'; + } + + static getInstance(): IModel { + if (!H2hdfMod.instance) { + H2hdfMod.instance = new H2hdfMod(); + } + return H2hdfMod.instance; + } + + setVersionTag(version: string) { + this.versionTag = version; + } + + setServiceId(id: string) { + this.serviceId = id; + } + + init(uri: vscode.Uri): void { + this.uri = uri; + } + + async generateHdf(hdfInputPath: string, versionTag: string) { + // analyze + let funDescList = await parseHeaderFile(hdfInputPath); + console.log('parse header file res: ', funDescList); + console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); + this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE); + // generator + let out = path.dirname(hdfInputPath); + let driverName = path.basename(hdfInputPath, '.h').toLocaleLowerCase(); + let rootInfo = { + driverName: driverName, + funcs: funDescList.funcs, + versionTag: versionTag + }; + genHdfFile(rootInfo, out); + // progress.report({ increment: 100, message: GEN_COMPLETE + out}); + this.emmitEventForKey(EVENT_PROGRESS, 100, GEN_COMPLETE + out); + + // toast the message of output dir + const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hdfInputPath), OPEN_IN_EXPLORER); + if (choice === OPEN_IN_EXPLORER) { + // open the output in folder + vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hdfInputPath)); + } + } + + async doStart(): Promise { + try { + if (this.uri) { + this.generateHdf(this.uri.fsPath, this.versionTag); + } else { + let errmsg = 'parse header file error with undefine uri.'; + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } catch (e) { + let errmsg = 'parse header file error: ' + JSON.stringify(e); + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } + + async doStop(): Promise { + throw new Error("Method not implemented."); + } + + async doPause(): Promise { + throw new Error("Method not implemented."); + } + + async doResume(): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/model/h2samod.ts b/src/vscode_plugin/src/model/h2samod.ts new file mode 100644 index 00000000..6ebb3318 --- /dev/null +++ b/src/vscode_plugin/src/model/h2samod.ts @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import * as path from 'path'; +import { IModel } from "./imodel"; +import { parseHeaderFile } from '../parse/parsec'; +import { GenInfo } from '../gen/datatype'; +import { genDtsFile } from '../gen/gendts'; +import { GEN_COMPLETE, OPEN_IN_EXPLORER, PARSE_COMPLETE } from '../common/constants'; +import { genServiceFile } from '../gen/gensa'; + +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; + +export class H2saMod extends IModel { + name: string; + private static instance: H2saMod; + versionTag: string = '3.2'; + serviceId: string = '19000'; + + constructor() { + super(); + this.name = 'h2dtsmod'; + } + + static getInstance(): IModel { + if (!H2saMod.instance) { + H2saMod.instance = new H2saMod(); + } + return H2saMod.instance; + } + + init(uri: vscode.Uri): void { + this.uri = uri; + } + + setVersionTag(version: string) { + this.versionTag = version; + } + + setServiceId(id: string) { + this.serviceId = id; + } + + async generateSa(hPath: string, versionTag: string, serviceId: string) { + // analyze + let funDescList = await parseHeaderFile(hPath); + console.log('parse header file res: ', funDescList); + console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); + + this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE); + + // generator + let out = path.dirname(hPath); + let serviceName = path.basename(hPath, '.h'); + let rootInfo = { + serviceName: serviceName, + funcs: funDescList.funcs, + serviceId: serviceId, + versionTag: versionTag + }; + genServiceFile(rootInfo, out); + // progress.report({ increment: 100, message: GEN_COMPLETE + out }); + this.emmitEventForKey(EVENT_PROGRESS, 100, GEN_COMPLETE + out); + + // select output dir + const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hPath), OPEN_IN_EXPLORER); + if (choice === OPEN_IN_EXPLORER) { + // open the folder + vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hPath)); + } + } + + async doStart(): Promise { + try { + if (this.uri) { + this.generateSa(this.uri.fsPath, this.versionTag, this.serviceId); + } else { + console.error('parse header file error with undefine uri.'); + } + } catch (e) { + let errmsg = 'parse header file error: ' + JSON.stringify(e); + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } + + async doStop(): Promise { + throw new Error("Method not implemented."); + } + + async doPause(): Promise { + throw new Error("Method not implemented."); + } + + async doResume(): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/model/welcomemod.ts b/src/vscode_plugin/src/model/welcomemod.ts new file mode 100644 index 00000000..7abf5335 --- /dev/null +++ b/src/vscode_plugin/src/model/welcomemod.ts @@ -0,0 +1,127 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import * as path from 'path'; +import { IModel } from "./imodel"; +import { parseHeaderFile } from '../parse/parsec'; +import { GenInfo } from '../gen/datatype'; +import { genDtsFile } from '../gen/gendts'; +import { GEN_COMPLETE, HDF_FRAMEWORK, NAPI_FRAMEWORK, PARSE_COMPLETE, SA_FRAMEWORK } from '../common/constants'; + +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { generateFuncTestCase } from '../gen/gentest'; +import { H2hdfMod } from './h2hdfmod'; +import { H2saMod } from './h2samod'; +import { Dts2cppMod } from './dts2cppmod'; + +export class WelcomeMod extends IModel { + name: string; + versionTag: string = '4.1'; + serviceId: string = '19000'; + genType: string = HDF_FRAMEWORK; + + private static instance: WelcomeMod; + constructor() { + super(); + this.name = 'welcomemod'; + } + + static getInstance(): IModel { + if (!WelcomeMod.instance) { + WelcomeMod.instance = new WelcomeMod(); + } + return WelcomeMod.instance; + } + + setVersionTag(version: string) { + this.versionTag = version; + } + + setServiceId(id: string) { + this.serviceId = id; + } + + setGenType(value: string) { + this.genType = value; + } + + init(uri: vscode.Uri): void { + this.uri = uri; + } + + async doStart(): Promise { + try { + if (this.uri) { + switch (this.genType) { + case NAPI_FRAMEWORK: + { + let dts2cppmod = Dts2cppMod.getInstance() as Dts2cppMod; + dts2cppmod.init(this.uri); + dts2cppmod.callbacks = this.callbacks; + dts2cppmod.doStart(); + } + // generateDtscpp(this.uri.fsPath); + break; + case SA_FRAMEWORK: + { + let samod = H2saMod.getInstance() as H2saMod; + samod.init(this.uri); + samod.callbacks = this.callbacks; + samod.setServiceId(this.serviceId); + samod.setVersionTag(this.versionTag); + samod.doStart(); + } + // generateSa(this.uri.fsPath, this.versionTag, this.serviceId); + break; + case HDF_FRAMEWORK: + let hdfmod = H2hdfMod.getInstance() as H2hdfMod; + hdfmod.init(this.uri); + hdfmod.callbacks = this.callbacks; + hdfmod.setServiceId(this.serviceId); + hdfmod.setVersionTag(this.versionTag); + hdfmod.doStart(); + // generateHdf(this.uri.fsPath, this.versionTag); + break; + default: + console.error('unknown gen type: ', this.genType); + break; + } + } else { + console.error('parse header file error with undefine uri.'); + } + } catch (e) { + let errmsg = 'parse header file error: ' + JSON.stringify(e); + console.error(errmsg); + this.emmitEventForKey(EVENT_ERROR, -1, errmsg); + } + } + + async doStop(): Promise { + throw new Error("Method not implemented."); + } + + async doPause(): Promise { + throw new Error("Method not implemented."); + } + + async doResume(): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file -- Gitee From f3ea4ef9cecbdf5f56943a704a9745056a86eb05 Mon Sep 17 00:00:00 2001 From: wangshi Date: Fri, 7 Feb 2025 17:08:51 +0800 Subject: [PATCH 3/4] refator h2dts,h2dtscpp,h2sa,h2hdf,dts2cpp Signed-off-by: wangshi --- .../src/view/crosscompileview.ts | 77 ++++++++++++ src/vscode_plugin/src/view/dts2cppview.ts | 77 ++++++++++++ src/vscode_plugin/src/view/h2dtscppview.ts | 76 ++++++++++++ src/vscode_plugin/src/view/h2dtsview.ts | 94 +++++++------- src/vscode_plugin/src/view/h2hdfview.ts | 99 +++++++++++++++ src/vscode_plugin/src/view/h2saview.ts | 112 +++++++++++++++++ src/vscode_plugin/src/view/welcomeview.ts | 117 ++++++++++++++++++ 7 files changed, 605 insertions(+), 47 deletions(-) create mode 100644 src/vscode_plugin/src/view/crosscompileview.ts create mode 100644 src/vscode_plugin/src/view/dts2cppview.ts create mode 100644 src/vscode_plugin/src/view/h2dtscppview.ts create mode 100644 src/vscode_plugin/src/view/h2hdfview.ts create mode 100644 src/vscode_plugin/src/view/h2saview.ts create mode 100644 src/vscode_plugin/src/view/welcomeview.ts diff --git a/src/vscode_plugin/src/view/crosscompileview.ts b/src/vscode_plugin/src/view/crosscompileview.ts new file mode 100644 index 00000000..a77c3453 --- /dev/null +++ b/src/vscode_plugin/src/view/crosscompileview.ts @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import { CrossCompileMod } from "../model/crosscompilemod"; +import { IModel } from "../model/imodel"; +import { IView } from "./iview"; +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { IController } from '../controller/icontroller'; +import { toastMsg } from '../common/widget'; + +export class CrossCompileView extends IView { + name: string; + model: IModel; + controller: IController | undefined; + progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; + constructor() { + super(); + this.name = 'crosscompileview'; + this.model = CrossCompileMod.getInstance(); + } + + init(controller: IController): void { + this.controller = controller; + + this.model.onEvent(EVENT_PROGRESS, (percent, info) => { + if (this.progress) { + this.progress.report({ increment: percent, message: info }) + } + }) + this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { + vscode.window.showErrorMessage(errmsg); + }) + this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { + vscode.window.showWarningMessage(errmsg); + }) + } + + showProgress(): void { + try { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: "Generating .d.ts ...", + cancellable: false + }, async (progress: vscode.Progress<{ message?: string; increment?: number; }>) => { + this.progress = progress; + if (this.controller) { + this.controller.start(); + } + }) + } catch (error) { + let errmsg = this.name + " showProgress error: " + JSON.stringify(error); + toastMsg(EVENT_ERROR, errmsg); + } + + } + + showMsg(event: string, msg: string): void { + toastMsg(event, msg); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/view/dts2cppview.ts b/src/vscode_plugin/src/view/dts2cppview.ts new file mode 100644 index 00000000..d3f4263e --- /dev/null +++ b/src/vscode_plugin/src/view/dts2cppview.ts @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import { Dts2cppMod } from "../model/dts2cppmod"; +import { IModel } from "../model/imodel"; +import { IView } from "./iview"; +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { IController } from '../controller/icontroller'; +import { toastMsg } from '../common/widget'; + +export class Dts2cppView extends IView { + name: string; + model: IModel; + controller: IController | undefined; + progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; + constructor() { + super(); + this.name = 'dts2cppview'; + this.model = Dts2cppMod.getInstance(); + } + + init(controller: IController): void { + this.controller = controller; + + this.model.onEvent(EVENT_PROGRESS, (percent, info) => { + if (this.progress) { + this.progress.report({ increment: percent, message: info }) + } + }) + this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { + vscode.window.showErrorMessage(errmsg); + }) + this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { + vscode.window.showWarningMessage(errmsg); + }) + } + + showProgress(): void { + try { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: "Generating CPP...", + cancellable: false + }, async (progress: vscode.Progress<{ message?: string; increment?: number; }>) => { + this.progress = progress; + if (this.controller) { + this.controller.start(); + } + }) + } catch (error) { + let errmsg = this.name + " showProgress error: " + JSON.stringify(error); + toastMsg(EVENT_ERROR, errmsg); + } + + } + + showMsg(event: string, msg: string): void { + toastMsg(event, msg); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/view/h2dtscppview.ts b/src/vscode_plugin/src/view/h2dtscppview.ts new file mode 100644 index 00000000..f4820ac8 --- /dev/null +++ b/src/vscode_plugin/src/view/h2dtscppview.ts @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import { IModel } from "../model/imodel"; +import { IView } from "./iview"; +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { IController } from '../controller/icontroller'; +import { toastMsg } from '../common/widget'; +import { H2dtscppMod } from '../model/h2dtscppmod'; + +export class H2dtscppView extends IView { + name: string; + model: IModel; + controller: IController | undefined; + progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; + constructor() { + super(); + this.name = 'h2dtscppview'; + this.model = H2dtscppMod.getInstance(); + } + + init(controller: IController): void { + this.controller = controller; + + this.model.onEvent(EVENT_PROGRESS, (percent, info) => { + if (this.progress) { + this.progress.report({ increment: percent, message: info }) + } + }) + this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { + vscode.window.showErrorMessage(errmsg); + }) + this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { + vscode.window.showWarningMessage(errmsg); + }) + } + + showProgress(): void { + try { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: 'Generating DTSCPP...', + cancellable: false + }, async (progress) => { + this.progress = progress; + if (this.controller) { + this.controller.start(); + } + }) + } catch (error) { + let errmsg = this.name + " showProgress error: " + JSON.stringify(error); + toastMsg(EVENT_ERROR, errmsg); + } + } + + showMsg(event: string, msg: string): void { + toastMsg(event, msg); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/view/h2dtsview.ts b/src/vscode_plugin/src/view/h2dtsview.ts index a414eec0..beb6318c 100644 --- a/src/vscode_plugin/src/view/h2dtsview.ts +++ b/src/vscode_plugin/src/view/h2dtsview.ts @@ -17,61 +17,61 @@ import { H2dtsMod } from "../model/h2dtsmod"; import { IModel } from "../model/imodel"; import { IView } from "./iview"; import { - EVENT_ERROR, - EVENT_INFORMATION, - EVENT_PROGRESS, - EVENT_WARNING + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING } from '../common/eventtype'; import { IController } from '../controller/icontroller'; import { toastMsg } from '../common/widget'; export class H2dtsView extends IView { - name: string; - model: IModel; - controller: IController | undefined; - progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; - constructor() { - super(); - this.name = 'h2dtsview'; - this.model = H2dtsMod.getInstance(); - } + name: string; + model: IModel; + controller: IController | undefined; + progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; + constructor() { + super(); + this.name = 'h2dtsview'; + this.model = H2dtsMod.getInstance(); + } - init(controller: IController): void { - this.controller = controller; + init(controller: IController): void { + this.controller = controller; - this.model.onEvent(EVENT_PROGRESS, (percent, info) => { - if (this.progress) { - this.progress.report({ increment: percent, message: info }) - } - }) - this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { - vscode.window.showErrorMessage(errmsg); - }) - this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { - vscode.window.showWarningMessage(errmsg); - }) - } + this.model.onEvent(EVENT_PROGRESS, (percent, info) => { + if (this.progress) { + this.progress.report({ increment: percent, message: info }) + } + }) + this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { + vscode.window.showErrorMessage(errmsg); + }) + this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { + vscode.window.showWarningMessage(errmsg); + }) + } - showProgress(): void { - try { - vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - title: "Generating .d.ts ...", - cancellable: false - }, async (progress: vscode.Progress<{ message?: string; increment?: number; }>) => { - this.progress = progress; - if (this.controller) { - this.controller.start(); - } - }) - } catch (error) { - let errmsg = this.name + " showProgress error: " + JSON.stringify(error); - toastMsg(EVENT_ERROR, errmsg); + showProgress(): void { + try { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: "Generating .d.ts ...", + cancellable: false + }, async (progress: vscode.Progress<{ message?: string; increment?: number; }>) => { + this.progress = progress; + if (this.controller) { + this.controller.start(); } - - } - - showMsg(event: string, msg: string): void { - toastMsg(event, msg); + }) + } catch (error) { + let errmsg = this.name + " showProgress error: " + JSON.stringify(error); + toastMsg(EVENT_ERROR, errmsg); } + + } + + showMsg(event: string, msg: string): void { + toastMsg(event, msg); + } } \ No newline at end of file diff --git a/src/vscode_plugin/src/view/h2hdfview.ts b/src/vscode_plugin/src/view/h2hdfview.ts new file mode 100644 index 00000000..c03d0df2 --- /dev/null +++ b/src/vscode_plugin/src/view/h2hdfview.ts @@ -0,0 +1,99 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import { H2hdfMod } from "../model/h2hdfmod"; +import { IModel } from "../model/imodel"; +import { IView } from "./iview"; +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { IController } from '../controller/icontroller'; +import { doAsyncQuickPick, toastMsg } from '../common/widget'; +import { SELECT_VERSION } from '../common/constants'; + +export class H2hdfView extends IView { + name: string; + model: IModel; + controller: IController | undefined; + progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; + constructor() { + super(); + this.name = 'h2hdfview'; + this.model = H2hdfMod.getInstance(); + } + + init(controller: IController): void { + this.controller = controller; + + this.model.onEvent(EVENT_PROGRESS, (percent, info) => { + if (this.progress) { + this.progress.report({ increment: percent, message: info }) + } + }) + this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { + vscode.window.showErrorMessage(errmsg); + }) + this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { + vscode.window.showWarningMessage(errmsg); + }) + } + + doAsyncCB = async (version: string) => { + let versionTag = '4.1'; + if (version === 'OpenHarmony 4.1 release') { + versionTag = '4.1' + } + // generateHdf(this.uri.fsPath, versionTag); + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: 'Generating HDF...', + cancellable: false + }, async (progress) => { + this.progress = progress; + if (this.model) { + let hdfmode = this.model as H2hdfMod; + hdfmode.setVersionTag(versionTag); + } + + if (this.controller) { + this.controller.start(); + } else { + let errmsg = this.name + " showProgress error: no controller"; + toastMsg(EVENT_ERROR, errmsg); + } + }) + } + + showProgress(): void { + try { + doAsyncQuickPick( + ['OpenHarmony 4.1 release'], + { placeHolder: SELECT_VERSION }, + this.doAsyncCB + ) + } catch (error) { + let errmsg = this.name + " showProgress error: " + JSON.stringify(error); + toastMsg(EVENT_ERROR, errmsg); + } + } + + showMsg(event: string, msg: string): void { + toastMsg(event, msg); + } +} + diff --git a/src/vscode_plugin/src/view/h2saview.ts b/src/vscode_plugin/src/view/h2saview.ts new file mode 100644 index 00000000..6373e804 --- /dev/null +++ b/src/vscode_plugin/src/view/h2saview.ts @@ -0,0 +1,112 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import { H2saMod } from "../model/h2samod"; +import { IModel } from "../model/imodel"; +import { IView } from "./iview"; +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { IController } from '../controller/icontroller'; +import { doAsyncQuickPick, toastMsg } from '../common/widget'; +import { INPUT_NO_EMPTY, INPUT_NUMBER, INPUT_SERVICEID, SELECT_VERSION } from '../common/constants'; + +export class H2saView extends IView { + name: string; + model: IModel; + controller: IController | undefined; + progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; + constructor() { + super(); + this.name = 'h2dtsview'; + this.model = H2saMod.getInstance(); + } + + init(controller: IController): void { + this.controller = controller; + + this.model.onEvent(EVENT_PROGRESS, (percent, info) => { + if (this.progress) { + this.progress.report({ increment: percent, message: info }); + } + }) + this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { + vscode.window.showErrorMessage(errmsg); + }) + this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { + vscode.window.showWarningMessage(errmsg); + }) + } + + doAsyncCB = async (version: string) => { + let versionTag = '3.2'; + if (version === 'OpenHarmony 4.1 release') { + versionTag = '4.1' + } else if (version === 'OpenHarmony 3.2 release') { + versionTag = '3.2' + } + const serviceId = await vscode.window.showInputBox({ + placeHolder: INPUT_SERVICEID, + value: "19000", // defaultֵ serviceID + validateInput: (input) => { + if (!input) { + return INPUT_NO_EMPTY; + } + if (!Number(input)) { + return INPUT_NUMBER; + } + } + }); + + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: 'Generating SA...', + cancellable: false + }, async (progress) => { + this.progress = progress; + if (this.model) { + let samode = this.model as H2saMod + if (serviceId) { + samode.setServiceId(serviceId); + } + samode.setVersionTag(versionTag); + } + if (this.controller) { + this.controller.start(); + } + } + ) + } + + showProgress(): void { + try { + doAsyncQuickPick( + ['OpenHarmony 4.1 release', 'OpenHarmony 3.2 release'], + { placeHolder: SELECT_VERSION }, + this.doAsyncCB + ); + } catch (error) { + let errmsg = this.name + " showProgress error: " + JSON.stringify(error); + toastMsg(EVENT_ERROR, errmsg); + } + } + + showMsg(event: string, msg: string): void { + toastMsg(event, msg); + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/view/welcomeview.ts b/src/vscode_plugin/src/view/welcomeview.ts new file mode 100644 index 00000000..06c37912 --- /dev/null +++ b/src/vscode_plugin/src/view/welcomeview.ts @@ -0,0 +1,117 @@ +/* +* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import * as vscode from 'vscode'; +import { WelcomeMod } from "../model/welcomemod"; +import { IModel } from "../model/imodel"; +import { IView } from "./iview"; +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_PROGRESS, + EVENT_WARNING +} from '../common/eventtype'; +import { IController } from '../controller/icontroller'; +import { doAsyncQuickPick, toastMsg } from '../common/widget'; +import { CONFIRM_SELECT, HDF_FRAMEWORK, INPUT_INCONSISTENT, INPUT_NO_EMPTY, INPUT_NUMBER, INPUT_SERVICEID, NAPI_FRAMEWORK, SA_FRAMEWORK, SELECT_FRAMWORK, SELECT_VERSION } from '../common/constants'; + +export class WelcomeView extends IView { + name: string; + model: IModel; + controller: IController | undefined; + progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; + constructor() { + super(); + this.name = 'h2dtsview'; + this.model = WelcomeMod.getInstance(); + } + + init(controller: IController): void { + this.controller = controller; + + this.model.onEvent(EVENT_PROGRESS, (percent, info) => { + if (this.progress) { + this.progress.report({ increment: percent, message: info }) + } + }) + this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { + vscode.window.showErrorMessage(errmsg); + }) + this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { + vscode.window.showWarningMessage(errmsg); + }) + } + + asyncCB = async (value: string) => { + await vscode.window.showInputBox({ + placeHolder: CONFIRM_SELECT, + validateInput: (input) => { + if (!input) { + return INPUT_NO_EMPTY; + } + if (input !== value) { + return INPUT_INCONSISTENT; + } + } + }); + + if (this.model) { + let welcomeMode = this.model as WelcomeMod; + welcomeMode.setGenType(value); + + const options: vscode.OpenDialogOptions = { + canSelectFiles: true, + canSelectFolders: true, + canSelectMany: false, + defaultUri: vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0].uri : undefined, + openLabel: 'Select' + }; + + vscode.window.showOpenDialog(options).then(fileUri => { + if (fileUri && fileUri[0]) { + const filePath = fileUri[0].fsPath; + console.log('Selected path:', filePath); + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: 'Generating DTSCPP...', + cancellable: false + }, async (progress) => { + this.progress = progress; + if (this.controller) { + this.controller.uri = fileUri[0]; + this.controller.start(); + } + }) + } + }); + } + } + + showProgress(): void { + try { + doAsyncQuickPick( + [HDF_FRAMEWORK, SA_FRAMEWORK, NAPI_FRAMEWORK], + { placeHolder: SELECT_FRAMWORK }, + this.asyncCB + ) + } catch (error) { + let errmsg = this.name + " showProgress error: " + JSON.stringify(error); + toastMsg(EVENT_ERROR, errmsg); + } + } + + showMsg(event: string, msg: string): void { + toastMsg(event, msg); + } +} \ No newline at end of file -- Gitee From c5d9043bba77fd3a75cd928df2beeaca2522a292 Mon Sep 17 00:00:00 2001 From: wangshi Date: Fri, 7 Feb 2025 17:09:00 +0800 Subject: [PATCH 4/4] refator h2dts,h2dtscpp,h2sa,h2hdf,dts2cpp Signed-off-by: wangshi --- src/vscode_plugin/src/common/tool.ts | 9 +- src/vscode_plugin/src/common/widget.ts | 35 +++++- src/vscode_plugin/src/extension.ts | 160 ++++++++++++++----------- src/vscode_plugin/src/gen/gendts.ts | 14 ++- src/vscode_plugin/src/gen/genhdf.ts | 11 +- 5 files changed, 144 insertions(+), 85 deletions(-) diff --git a/src/vscode_plugin/src/common/tool.ts b/src/vscode_plugin/src/common/tool.ts index 86ae0a83..070945cd 100644 --- a/src/vscode_plugin/src/common/tool.ts +++ b/src/vscode_plugin/src/common/tool.ts @@ -14,10 +14,13 @@ */ export function replaceAll(s: string, sfrom: string, sto: any) { + console.log('[replaceall] s:'+s+' sfrom:'+sfrom+' sto:'+sto); + if (s && sfrom && sto) { while (s.indexOf(sfrom) >= 0) { - s = s.replace(sfrom, sto); - } - return s; + s = s.replace(sfrom, sto); + } + } + return s; } export function getTab(tabLv: number) { diff --git a/src/vscode_plugin/src/common/widget.ts b/src/vscode_plugin/src/common/widget.ts index 4173c1a9..b160c013 100644 --- a/src/vscode_plugin/src/common/widget.ts +++ b/src/vscode_plugin/src/common/widget.ts @@ -17,7 +17,40 @@ // Import the module and reference it with the alias vscode in your code below import * as vscode from 'vscode'; -import { EVENT_ERROR, EVENT_INFORMATION, EVENT_WARNING } from './eventtype'; +import { + EVENT_ERROR, + EVENT_INFORMATION, + EVENT_WARNING +} from './eventtype'; +import { Callback } from './define'; + +export function doAsyncQuickPick(valueList: string[], options?: vscode.QuickPickOptions, cb?: Callback) { + vscode.window.showQuickPick(valueList, options).then((value) => { + if (cb) { + cb(value); + } else { + toastMsg(EVENT_ERROR, 'No cb in showQuickPick'); + } + }) +} + +export async function doSyncQuickPick(valueList: string[], options?: vscode.QuickPickOptions) { + return await vscode.window.showQuickPick(valueList, options); +} + +export function doAsyncInputBox(options?: vscode.InputBoxOptions, cb?: Callback) { + vscode.window.showInputBox(options).then((value) => { + if (cb) { + cb(value); + } else { + toastMsg(EVENT_ERROR, 'No cb in showInputBox'); + } + }) +} + +export async function doSyncInputBox(options?: vscode.InputBoxOptions) { + return await vscode.window.showInputBox(options); +} export function toastMsg(event: string, msg: string) { switch(event) { diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index a251b447..2f20dfde 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -29,6 +29,10 @@ import { genDtsFile } from './gen/gendts'; import { genHdfFile } from './gen/genhdf'; import { genDtsCppFile, genCppFile } from './gen/gendtscpp'; import { H2dtsCtrl } from './controller/h2dtsctrl'; +import { H2saCtrl } from './controller/h2sactrl'; +import { H2hdfCtrl } from './controller/h2hdfctrl'; +import { H2dtscppCtrl } from './controller/h2dtscppctrl'; +import { Dts2cppCtrl } from './controller/dts2cppctrl'; // ��ȡ���ػ��ַ��� const SELECTED_DIR = vscode.l10n.t('You selected a directory:'); @@ -429,43 +433,49 @@ export function activate(context: vscode.ExtensionContext) { // Now provide the implementation of the command with registerCommand // The commandId parameter must match the command field in package.json const h2sa = vscode.commands.registerCommand('extension.h2sa', async (uri) => { + let h2saCtrl = new H2saCtrl(uri); + h2saCtrl.init(); // The code you place here will be executed every time your command is executed - if (uri && uri.fsPath) { - let versionTag = '3.2'; - const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release', 'OpenHarmony 3.2 release'], { placeHolder: SELECT_VERSION }); - if (version === 'OpenHarmony 4.1 release') { - versionTag = '4.1' - } else if (version === 'OpenHarmony 3.2 release') { - versionTag = '3.2' - } - const serviceId = await vscode.window.showInputBox({ - placeHolder: INPUT_SERVICEID, - value: "19000", // ����Ĭ��ֵ - validateInput: (input) => { - if (!input) { - return INPUT_NO_EMPTY; - } - if (!Number(input)) { - return INPUT_NUMBER - } - } - }); - generateSa(uri.fsPath, versionTag, serviceId as string); - } + // if (uri && uri.fsPath) { + // let versionTag = '3.2'; + // const version = await vscode.window.showQuickPick( + // ['OpenHarmony 4.1 release', 'OpenHarmony 3.2 release'], + // { placeHolder: SELECT_VERSION } + // ); + // if (version === 'OpenHarmony 4.1 release') { + // versionTag = '4.1' + // } else if (version === 'OpenHarmony 3.2 release') { + // versionTag = '3.2' + // } + // const serviceId = await vscode.window.showInputBox({ + // placeHolder: INPUT_SERVICEID, + // value: "19000", // ����Ĭ��ֵ + // validateInput: (input) => { + // if (!input) { + // return INPUT_NO_EMPTY; + // } + // if (!Number(input)) { + // return INPUT_NUMBER + // } + // } + // }); + // generateSa(uri.fsPath, versionTag, serviceId as string); + // } }); - context.subscriptions.push(h2sa); const h2hdf = vscode.commands.registerCommand('extension.h2hdf', async (uri) => { - // The code you place here will be executed every time your command is executed - if (uri && uri.fsPath) { - let versionTag = '4.1'; - const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: SELECT_VERSION }); - if (version === 'OpenHarmony 4.1 release') { - versionTag = '4.1' - } - generateHdf(uri.fsPath, versionTag); - } + let h2hdfCtrl = new H2hdfCtrl(uri); + h2hdfCtrl.init(); + // // The code you place here will be executed every time your command is executed + // if (uri && uri.fsPath) { + // let versionTag = '4.1'; + // const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: SELECT_VERSION }); + // if (version === 'OpenHarmony 4.1 release') { + // versionTag = '4.1' + // } + // generateHdf(uri.fsPath, versionTag); + // } }); context.subscriptions.push(h2hdf); @@ -499,45 +509,49 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(h2dts); const h2dtscpp = vscode.commands.registerCommand('extension.h2dtscpp', async (uri) => { - // The code you place here will be executed every time your command is executed - if (uri && uri.fsPath) { - generateDtscpp(uri.fsPath); - } + let h2dtscppCtrl = new H2dtscppCtrl(uri); + h2dtscppCtrl.init(); + // // The code you place here will be executed every time your command is executed + // if (uri && uri.fsPath) { + // generateDtscpp(uri.fsPath); + // } }); context.subscriptions.push(h2dtscpp); const dts2cpp = vscode.commands.registerCommand('extension.dts2cpp', (uri) => { - // The code you place here will be executed every time your command is executed - console.log('uri is : ' + uri.fsPath ); - if (uri && uri.fsPath) { - vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - title: "Generating CPP...", - cancellable: false - }, async (progress) => { - const filename = path.basename(uri.fsPath); - console.log('get filename ' ); - if (filename.endsWith('.d.ts')) { - // Display a message box to the user - // analyze - let res = parseTsFile(uri.fsPath); - console.info('res: ' + JSON.stringify(res)); - progress.report({ increment: 50, message: PARSE_COMPLETE }); - // generator - let out = path.dirname(uri.fsPath); - genCppFile(res, uri.fsPath, out); - progress.report({ increment: 100, message: GEN_COMPLETE + out }); - } else { - console.log('not dts uri is : ' + uri.fsPath ); - // Display a message box to the user - vscode.window.showInformationMessage(`${uri.fsPath} is not a .d.ts file!`); - } - }); - } + let dts2cppCtrl = new Dts2cppCtrl(uri); + dts2cppCtrl.init(); + // The code you place here will be executed every time your command is executed + // console.log('uri is : ' + uri.fsPath ); + // if (uri && uri.fsPath) { + // vscode.window.withProgress({ + // location: vscode.ProgressLocation.Notification, + // title: "Generating CPP...", + // cancellable: false + // }, async (progress) => { + // const filename = path.basename(uri.fsPath); + // console.log('get filename ' ); + // if (filename.endsWith('.d.ts')) { + // // Display a message box to the user + // // analyze + // let res = parseTsFile(uri.fsPath); + // console.info('res: ' + JSON.stringify(res)); + // progress.report({ increment: 50, message: PARSE_COMPLETE }); + // // generator + // let out = path.dirname(uri.fsPath); + // genCppFile(res, uri.fsPath, out); + // progress.report({ increment: 100, message: GEN_COMPLETE + out }); + // } else { + // console.log('not dts uri is : ' + uri.fsPath ); + // // Display a message box to the user + // vscode.window.showInformationMessage(`${uri.fsPath} is not a .d.ts file!`); + // } + // }); + // } }); context.subscriptions.push(dts2cpp); - // ��ӭ�˵�ҳ�� + // welcome page in vscode when no file or dir is opened const ohGenerator = vscode.commands.registerCommand('extension.ohGenerator', async () => { // The code you place here will be executed every time your command is executed let hPath = path.join(__dirname, '../test/test.h'); @@ -552,10 +566,10 @@ export function activate(context: vscode.ExtensionContext) { if (input !== value) { return INPUT_INCONSISTENT; } - } + } }); if (value === HDF_FRAMEWORK) { - // ����汾 + // input the version of oh let versionTag = '4.1'; const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: SELECT_VERSION }) if (version === 'OpenHarmony 4.1 release') { @@ -563,7 +577,7 @@ export function activate(context: vscode.ExtensionContext) { } generateHdf(hdfInputPath, versionTag); } else if (value === SA_FRAMEWORK) { - // ����汾 + // input the version of oh let versionTag = '3.2'; const version = await vscode.window.showQuickPick(['OpenHarmony 3.2 release', 'OpenHarmony 4.1 release'], { placeHolder: SELECT_VERSION }) if (version === 'OpenHarmony 4.1 release') { @@ -613,10 +627,10 @@ async function generateHdf(hdfInputPath: string, versionTag: string) { genHdfFile(rootInfo, out); progress.report({ increment: 100, message: GEN_COMPLETE + out}); }); - // ��ʾ������·�� + // show output path const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hdfInputPath), OPEN_IN_EXPLORER); if (choice === OPEN_IN_EXPLORER) { - // ���ļ����ڵ�Ŀ¼ + // open the output folder vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hdfInputPath)); } } @@ -646,10 +660,10 @@ async function generateSa(hPath: string, versionTag: string, serviceId: string) genServiceFile(rootInfo, out); progress.report({ increment: 100, message: GEN_COMPLETE + out }); }); - // ��ʾ������·�� + // show the output path const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hPath), OPEN_IN_EXPLORER); if (choice === OPEN_IN_EXPLORER) { - // ���ļ����ڵ�Ŀ¼ + // open output dir vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hPath)); } } @@ -679,10 +693,10 @@ async function generateDtscpp(hFilePath: string) { genDtsCppFile(rootInfo, out); progress.report({ increment: 100, message: GEN_COMPLETE + out }); }); - // ��ʾ������·�� + // show genarate path const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hFilePath), OPEN_IN_EXPLORER); if (choice === OPEN_IN_EXPLORER) { - // ���ļ����ڵ�Ŀ¼ + // open the folder vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hFilePath)); } } diff --git a/src/vscode_plugin/src/gen/gendts.ts b/src/vscode_plugin/src/gen/gendts.ts index e229a0f4..7260baff 100644 --- a/src/vscode_plugin/src/gen/gendts.ts +++ b/src/vscode_plugin/src/gen/gendts.ts @@ -112,6 +112,9 @@ function getInterFuncName(str: string) { } export function getJsTypeFromC(cType: string) { + if (!cType) { + return ''; + } let basicCtype = cType; let matchs = re.match('(std::)?vector<([\x21-\x7e ]+)>', basicCtype); let isArray = 0; @@ -179,11 +182,14 @@ function isJsBasicType(type: string) { function removeMarco(type: string) { // 去掉宏定义 - let leftCraftIndex = type.indexOf('('); - let rightCraftIndex = type.indexOf(')'); - if (leftCraftIndex >= 0 && rightCraftIndex > 0) { - type = removeTab(type.substring(leftCraftIndex + 1, rightCraftIndex)); + if (type) { + let leftCraftIndex = type.indexOf('('); + let rightCraftIndex = type.indexOf(')'); + if (leftCraftIndex >= 0 && rightCraftIndex > 0) { + type = removeTab(type.substring(leftCraftIndex + 1, rightCraftIndex)); + } } + return type; } diff --git a/src/vscode_plugin/src/gen/genhdf.ts b/src/vscode_plugin/src/gen/genhdf.ts index 5e29de43..1d8fbd4d 100644 --- a/src/vscode_plugin/src/gen/genhdf.ts +++ b/src/vscode_plugin/src/gen/genhdf.ts @@ -101,10 +101,13 @@ function getIdlType(cType: string) { } function isReturn(type: string) { - if (type.indexOf('&')>0 || type.indexOf('**')>0) { - return true; - } - return false; + console.log('isReturn in type: ', type); + if (type) { + if (type.indexOf('&')>0 || type.indexOf('**')>0) { + return true; + } + } + return false; } function getIdlFuncParamStr(funcObj: FuncObj) { -- Gitee