diff --git a/src/vscode_plugin/src/common/constants.ts b/src/vscode_plugin/src/common/constants.ts new file mode 100644 index 0000000000000000000000000000000000000000..3a7fd62bb6bb29d3eb3ddcc6ca4f0229396b84de --- /dev/null +++ b/src/vscode_plugin/src/common/constants.ts @@ -0,0 +1,68 @@ +/* +* 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. +*/ + +// The module 'vscode' contains the VS Code extensibility API +// Import the module and reference it with the alias vscode in your code below + +import * as vscode from 'vscode'; + +export const SELECTED_DIR = vscode.l10n.t('You selected a directory:'); +export const SELECTE_DIR = vscode.l10n.t('Please select a directory.'); +export const NO_RES_SELECTED = vscode.l10n.t('No resource selected.'); +export const HDF_FRAMEWORK = vscode.l10n.t('Hdf Framework'); +export const SA_FRAMEWORK = vscode.l10n.t('SystemAbility Framework'); +export const NAPI_FRAMEWORK = vscode.l10n.t('N-API Framework'); +export const SELECT_VERSION = vscode.l10n.t('Please select the version...'); +export const INPUT_SERVICEID = vscode.l10n.t('Please input serviceId like 19000...'); +export const INPUT_NO_EMPTY = vscode.l10n.t('Input cannot be empty'); +export const INPUT_NUMBER = vscode.l10n.t('Please input a number...'); +export const SELECT_FRAMWORK = vscode.l10n.t('Please select framework...'); +export const CONFIRM_SELECT = vscode.l10n.t('Please confirm your selection...'); +export const INPUT_INCONSISTENT = vscode.l10n.t('Inconsistent input'); +export const PARSE_COMPLETE = vscode.l10n.t('Parse complete.'); +export const GEN_COMPLETE = vscode.l10n.t('Generation complete:'); +export const OPEN_IN_EXPLORER = vscode.l10n.t('Open in Explorer'); +export const PICK_MAKE = vscode.l10n.t('Use Makefile for compilation.'); +export const PICK_CMAKE = vscode.l10n.t('Use CMakeLists.txt for compilation.'); +export const TOOL_PICK_PLACEHOLDER = vscode.l10n.t('Please select the way you want to compile: '); +export const OH_CROSS_COMPILE_TITLE = vscode.l10n.t('OpenHarmony Cross Compile'); +export const COMPILATION_METHOD_LOST = vscode.l10n.t('Unable to comfirm the compilation method, compilation aborted.'); +export const ARCH_PICK_64 = vscode.l10n.t('To compile 64-bit third-party library.'); +export const ARCH_PICK_32 = vscode.l10n.t('To compile 32-bit third-party library.'); +export const ARCH_PICK_PLACEHOLDER = vscode.l10n.t('Please select the target system architecture for compilation: '); +export const ARCHITECTURE_LOST = vscode.l10n.t('Unable to comfirm target system architecture, compilation aborted.'); +export const LOCAL = vscode.l10n.t('Local'); +export const LOCAL_DESCRIPTION = vscode.l10n.t('Please select the \'native\' folder in local OpenHarmony SDK files.'); +export const DOWNLOAD = vscode.l10n.t('Download'); +export const DOWNLOAD_DESCRIPTION = vscode.l10n.t('Download a specified version of OpenHarmony SDK from internet.'); +export const SOURCE_PICK_PLACEHOLDER = vscode.l10n.t('Please select the SDK you want to use: '); +export const NATIVE_CHECK_FAILED = vscode.l10n.t('Unable to verify the integrity of the native tools in OpenHarmony SDK, please try again and select a correct path of the \'native\' folder.'); +export const FOLDER_LOST = vscode.l10n.t('No folder selected, compilation aborted.'); +export const API9_LABEL = vscode.l10n.t('API Version 9'); +export const API9_DETAIL = vscode.l10n.t('Please select a folder to install this SDK. It is compatible with OpenHarmony 3.2 Release.'); +export const API10_LABEL = vscode.l10n.t('API Version 10'); +export const API10_DETAIL = vscode.l10n.t('Please select a folder to install this SDK. It is compatible with OpenHarmony 4.0 Release.'); +export const API11_LABEL = vscode.l10n.t('API Version 11'); +export const API11_DETAIL = vscode.l10n.t('Please select a folder to install this SDK. It is compatible with OpenHarmony 4.1 Release.'); +export const API12_LABEL = vscode.l10n.t('API Version 12'); +export const API12_DETAIL = vscode.l10n.t('Please select a folder to install this SDK. It is compatible with OpenHarmony 5.0.0 Release.'); +export const VERSION_PICK_PLACEHOLDER = vscode.l10n.t('Please specify the SDK version: '); +export const DOWNLOADING_TITLE = vscode.l10n.t('Downloading and installing SDK'); +export const DOWNLOADING_START = vscode.l10n.t('Start downloading...'); +export const DOWNLOADING_COMPLETE = vscode.l10n.t('Download complete. Extracting .tar.gz files... '); +export const SDK_INSTALLED = vscode.l10n.t('SDK installation complete.'); +export const SDK_VERSION_LOST = vscode.l10n.t('Unable to specify the version of OpenHarmony SDK, compilation aborted.'); +export const SDK_SOURCE_LOST = vscode.l10n.t('Unable to comfirm the source of OpenHarmony SDK, compilation aborted.'); +export const CMAKE_MAKE_LOST = vscode.l10n.t('Cannot detect CMakeLists.txt or Makefile!'); \ No newline at end of file diff --git a/src/vscode_plugin/src/test/test.h b/src/vscode_plugin/src/common/define.ts similarity index 86% rename from src/vscode_plugin/src/test/test.h rename to src/vscode_plugin/src/common/define.ts index 6b945d076d561db5dd194c4a960d42c48c39e3da..eabd9a9a9b86162c2ba8d38071935c388a5a5e44 100644 --- a/src/vscode_plugin/src/test/test.h +++ b/src/vscode_plugin/src/common/define.ts @@ -13,10 +13,4 @@ * limitations under the License. */ -#ifndef TEST_H -#define TEST_H - -namespace OHOS { - int testFunc(int v1, int v2, bool v3); -} -#endif \ No newline at end of file +export type Callback = (...args: any[]) => void; \ No newline at end of file diff --git a/src/vscode_plugin/src/test/hello.h b/src/vscode_plugin/src/common/error.ts similarity index 65% rename from src/vscode_plugin/src/test/hello.h rename to src/vscode_plugin/src/common/error.ts index c251f379b6ae4835fa39e67cc233c2b9452de47b..902eda450795c0bbabf404f18ed33fe0ae375f23 100644 --- a/src/vscode_plugin/src/test/hello.h +++ b/src/vscode_plugin/src/common/error.ts @@ -13,11 +13,13 @@ * limitations under the License. */ -#ifndef HELLO_H -#define HELLO_H -#include +// The module 'vscode' contains the VS Code extensibility API +// Import the module and reference it with the alias vscode in your code below -namespace OHOS { - std::string Helloworld(std::string sendMsg); -} -#endif \ No newline at end of file +import * as vscode from 'vscode'; + +export const ERROR_UNKNOW = -1; +export const ERROR_NOEXIST = -2; +export const ERROR_NET = -3; +export const ERROR_FILE = -4; +export const ERROR_PARSE = -5; \ No newline at end of file diff --git a/src/vscode_plugin/src/test/testdts.d.ts b/src/vscode_plugin/src/common/eventtype.ts similarity index 65% rename from src/vscode_plugin/src/test/testdts.d.ts rename to src/vscode_plugin/src/common/eventtype.ts index a773eeca8606e91e9fd4aa1d5b3863b087a4ec68..6ae5eba42ca460371816a6d29416155093e953b5 100644 --- a/src/vscode_plugin/src/test/testdts.d.ts +++ b/src/vscode_plugin/src/common/eventtype.ts @@ -13,11 +13,12 @@ * limitations under the License. */ -type MyType = number; -export class test -{ - a: string; - b: number; - c: boolean; -} -export function testFunc(v1: string, v2: boolean, v3: MyType): test; \ No newline at end of file +// The module 'vscode' contains the VS Code extensibility API +// Import the module and reference it with the alias vscode in your code below + +import * as vscode from 'vscode'; + +export const EVENT_PROGRESS = "progress"; +export const EVENT_ERROR = "error"; +export const EVENT_WARNING = "warn"; +export const EVENT_INFORMATION = "info"; \ No newline at end of file diff --git a/src/vscode_plugin/src/common/widget.ts b/src/vscode_plugin/src/common/widget.ts new file mode 100644 index 0000000000000000000000000000000000000000..4173c1a9cfacb8493f0d49d15fe7b74706673518 --- /dev/null +++ b/src/vscode_plugin/src/common/widget.ts @@ -0,0 +1,41 @@ +/* +* 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. +*/ + +// The module 'vscode' contains the VS Code extensibility API +// 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'; + +export function toastMsg(event: string, msg: string) { + switch(event) { + case EVENT_ERROR: + console.error(msg); + vscode.window.showErrorMessage(msg); + break; + case EVENT_INFORMATION: + console.info(msg); + vscode.window.showInformationMessage(msg); + break; + case EVENT_WARNING: + console.warn(msg); + vscode.window.showWarningMessage(msg); + break; + default: + console.log(msg); + vscode.window.showInformationMessage(msg); + break; + } +} \ No newline at end of file diff --git a/src/vscode_plugin/src/controller/h2dtsctrl.ts b/src/vscode_plugin/src/controller/h2dtsctrl.ts new file mode 100644 index 0000000000000000000000000000000000000000..7e92f669e79ab008ea9a2b8431d4f8773282fa76 --- /dev/null +++ b/src/vscode_plugin/src/controller/h2dtsctrl.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 { H2dtsMod } from "../model/h2dtsmod"; +import { IModel } from "../model/imodel"; +import { H2dtsView } from "../view/h2dtsview"; + +import { IView } from "../view/iview"; +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; + } + + 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/icontroller.ts b/src/vscode_plugin/src/controller/icontroller.ts new file mode 100644 index 0000000000000000000000000000000000000000..8b934084351cb71b009d464c8153e8015858949d --- /dev/null +++ b/src/vscode_plugin/src/controller/icontroller.ts @@ -0,0 +1,47 @@ +/* +* 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 { IView } from "../view/iview"; +import { IModel } from "../model/imodel"; +import { Callback } from "../common/define"; + +export abstract class IController { + abstract name: string; + abstract view: IView; + abstract model: IModel; + abstract uri: vscode.Uri; + + private callbacks: Map = new Map(); + + constructor() { + } + + public abstract init(): void; + + public abstract start(): void; + + public abstract stop(): void; + + public abstract pause(): void; + + public abstract resume(): void; + + public onEvent(event: string, cb: Callback): void { + this.callbacks.set(event, cb); + }; + public offEvent(event: string): void { + this.callbacks.delete(event); + }; +} \ No newline at end of file diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index 825cf96319409b45b7b89d2810be2d99d6e2d4f8..a251b4478909d4e80ec6dafdd464fe2de5dce403 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -28,6 +28,7 @@ import { genServiceFile } from './gen/gensa'; import { genDtsFile } from './gen/gendts'; import { genHdfFile } from './gen/genhdf'; import { genDtsCppFile, genCppFile } from './gen/gendtscpp'; +import { H2dtsCtrl } from './controller/h2dtsctrl'; // ��ȡ���ػ��ַ��� const SELECTED_DIR = vscode.l10n.t('You selected a directory:'); @@ -468,29 +469,32 @@ export function activate(context: vscode.ExtensionContext) { }); context.subscriptions.push(h2hdf); - const h2dts = vscode.commands.registerCommand('extension.h2dts', async (uri) => { - // The code you place here will be executed every time your command is executed - if (uri && uri.fsPath) { - vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - title: "Generating .d.ts ...", - cancellable: false - }, async (progress) => { - // parse - let parseRes = await parseHeaderFile(uri.fsPath); - console.log('parse header file res: ', parseRes); - progress.report({ increment: 50, message: PARSE_COMPLETE }); + const h2dts = vscode.commands.registerCommand('extension.h2dts', async (uri: vscode.Uri) => { + let h2dtsCtrl = new H2dtsCtrl(uri); + h2dtsCtrl.init(); + + // // The code you place here will be executed every time your command is executed + // if (uri && uri.fsPath) { + // vscode.window.withProgress({ + // location: vscode.ProgressLocation.Notification, + // title: "Generating .d.ts ...", + // cancellable: false + // }, async (progress) => { + // // parse + // let parseRes = await parseHeaderFile(uri.fsPath); + // console.log('parse header file res: ', parseRes); + // progress.report({ increment: 50, message: PARSE_COMPLETE }); - let rootInfo: GenInfo = { - parseObj: parseRes, - rawFilePath: uri.fsPath, // e://xxx.h - fileName: path.basename(uri.fsPath, '.h') // xxx - }; - // generator - let outPath = genDtsFile(rootInfo); - progress.report({ increment: 100, message: GEN_COMPLETE + outPath }); - }); - } + // let rootInfo: GenInfo = { + // parseObj: parseRes, + // rawFilePath: uri.fsPath, // e://xxx.h + // fileName: path.basename(uri.fsPath, '.h') // xxx + // }; + // // generator + // let outPath = genDtsFile(rootInfo); + // progress.report({ increment: 100, message: GEN_COMPLETE + outPath }); + // }); + // } }); context.subscriptions.push(h2dts); diff --git a/src/vscode_plugin/l10n/bundle.l10n.zh-cn.json b/src/vscode_plugin/src/l10n/bundle.l10n.zh-cn.json similarity index 100% rename from src/vscode_plugin/l10n/bundle.l10n.zh-cn.json rename to src/vscode_plugin/src/l10n/bundle.l10n.zh-cn.json diff --git a/src/vscode_plugin/src/model/h2dtsmod.ts b/src/vscode_plugin/src/model/h2dtsmod.ts new file mode 100644 index 0000000000000000000000000000000000000000..dbf24343beb5c46d38dbb32dcbce7ceff20f3992 --- /dev/null +++ b/src/vscode_plugin/src/model/h2dtsmod.ts @@ -0,0 +1,87 @@ +/* +* 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 H2dtsMod extends IModel { + name: string; + private static instance: H2dtsMod; + constructor() { + super(); + this.name = 'h2dtsmod'; + } + + static getInstance(): IModel { + if (!H2dtsMod.instance) { + H2dtsMod.instance = new H2dtsMod(); + } + return H2dtsMod.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/imodel.ts b/src/vscode_plugin/src/model/imodel.ts new file mode 100644 index 0000000000000000000000000000000000000000..88005a3291293e77e2f6a5048aa4952be4bcd13c --- /dev/null +++ b/src/vscode_plugin/src/model/imodel.ts @@ -0,0 +1,49 @@ +/* +* 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 { Callback } from "../common/define" + +export abstract class IModel { + abstract name: string; + uri: vscode.Uri | undefined = undefined; + callbacks: Map = new Map(); + + abstract init(uri: vscode.Uri): void; + abstract doStart(): void; + abstract doStop(): void; + abstract doPause(): void; + abstract doResume(): void; + + public onEvent(event: string, cb: Callback): void { + this.callbacks.set(event, cb); + }; + + public offEvent(event: string): void { + this.callbacks.delete(event); + }; + + public emmitAllEvent(...args: any[]): void { + this.callbacks.forEach(callback => callback(...args)); + } + + public emmitEventForKey(event: string, ...args: any[]): void { + const callback = this.callbacks.get(event); + if (callback) { + callback(...args); + } else { + console.error(`No callback found with key "${event}".`); + } + } +} \ No newline at end of file diff --git a/src/vscode_plugin/snippets/aki_class_snippets.json b/src/vscode_plugin/src/snippets/aki_class_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/aki_class_snippets.json rename to src/vscode_plugin/src/snippets/aki_class_snippets.json diff --git a/src/vscode_plugin/snippets/aki_enum_snippets.json b/src/vscode_plugin/src/snippets/aki_enum_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/aki_enum_snippets.json rename to src/vscode_plugin/src/snippets/aki_enum_snippets.json diff --git a/src/vscode_plugin/snippets/aki_function_snippets.json b/src/vscode_plugin/src/snippets/aki_function_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/aki_function_snippets.json rename to src/vscode_plugin/src/snippets/aki_function_snippets.json diff --git a/src/vscode_plugin/snippets/aki_struct_snippets.json b/src/vscode_plugin/src/snippets/aki_struct_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/aki_struct_snippets.json rename to src/vscode_plugin/src/snippets/aki_struct_snippets.json diff --git a/src/vscode_plugin/snippets/napi_asyncwork_snippets.json b/src/vscode_plugin/src/snippets/napi_asyncwork_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_asyncwork_snippets.json rename to src/vscode_plugin/src/snippets/napi_asyncwork_snippets.json diff --git a/src/vscode_plugin/snippets/napi_callback_snippets.json b/src/vscode_plugin/src/snippets/napi_callback_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_callback_snippets.json rename to src/vscode_plugin/src/snippets/napi_callback_snippets.json diff --git a/src/vscode_plugin/snippets/napi_class_snippets.json b/src/vscode_plugin/src/snippets/napi_class_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_class_snippets.json rename to src/vscode_plugin/src/snippets/napi_class_snippets.json diff --git a/src/vscode_plugin/snippets/napi_enum_snippets.json b/src/vscode_plugin/src/snippets/napi_enum_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_enum_snippets.json rename to src/vscode_plugin/src/snippets/napi_enum_snippets.json diff --git a/src/vscode_plugin/snippets/napi_error_snippets.json b/src/vscode_plugin/src/snippets/napi_error_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_error_snippets.json rename to src/vscode_plugin/src/snippets/napi_error_snippets.json diff --git a/src/vscode_plugin/snippets/napi_external_snippets.json b/src/vscode_plugin/src/snippets/napi_external_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_external_snippets.json rename to src/vscode_plugin/src/snippets/napi_external_snippets.json diff --git a/src/vscode_plugin/snippets/napi_promise_snippets.json b/src/vscode_plugin/src/snippets/napi_promise_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_promise_snippets.json rename to src/vscode_plugin/src/snippets/napi_promise_snippets.json diff --git a/src/vscode_plugin/snippets/napi_struct_snippets.json b/src/vscode_plugin/src/snippets/napi_struct_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_struct_snippets.json rename to src/vscode_plugin/src/snippets/napi_struct_snippets.json diff --git a/src/vscode_plugin/snippets/napi_thread_snippets.json b/src/vscode_plugin/src/snippets/napi_thread_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_thread_snippets.json rename to src/vscode_plugin/src/snippets/napi_thread_snippets.json diff --git a/src/vscode_plugin/snippets/napi_variable_snippets.json b/src/vscode_plugin/src/snippets/napi_variable_snippets.json similarity index 100% rename from src/vscode_plugin/snippets/napi_variable_snippets.json rename to src/vscode_plugin/src/snippets/napi_variable_snippets.json diff --git a/src/vscode_plugin/src/view/h2dtsview.ts b/src/vscode_plugin/src/view/h2dtsview.ts new file mode 100644 index 0000000000000000000000000000000000000000..a414eec04ca7ae098fc3f29638d9e9f2ea323362 --- /dev/null +++ b/src/vscode_plugin/src/view/h2dtsview.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 { H2dtsMod } from "../model/h2dtsmod"; +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 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(); + } + + 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/iview.ts b/src/vscode_plugin/src/view/iview.ts new file mode 100644 index 0000000000000000000000000000000000000000..ea4f7292067a64a17353b36c450edecc460da4ea --- /dev/null +++ b/src/vscode_plugin/src/view/iview.ts @@ -0,0 +1,27 @@ +/* +* 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 { IController } from "../controller/icontroller"; +import { IModel } from "../model/imodel"; + +export abstract class IView { + abstract name: string; + abstract model: IModel; + abstract controller: IController | undefined; + + abstract init(controller: IController): void; + abstract showProgress(): void; + abstract showMsg(event: string, msg: string): void; +} \ No newline at end of file