From 508d78de1538511979a5d5a24d7b9e6b02ccc8cd Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Tue, 29 Oct 2024 15:56:48 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E7=94=9F=E6=88=90=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AC=A2=E8=BF=8E=E8=8F=9C=E5=8D=95=E9=87=8C?= =?UTF-8?q?=E7=9A=84=E6=8C=89=E9=92=AE=EF=BC=88workbench.explorer.emptyVie?= =?UTF-8?q?w=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/package.json | 10 + src/vscode_plugin/package.nls.json | 7 +- src/vscode_plugin/src/extension.ts | 345 +++++++++++++++-------------- 3 files changed, 197 insertions(+), 165 deletions(-) diff --git a/src/vscode_plugin/package.json b/src/vscode_plugin/package.json index 09955203..9483235e 100644 --- a/src/vscode_plugin/package.json +++ b/src/vscode_plugin/package.json @@ -47,8 +47,18 @@ { "command": "extension.ohcrosscompile", "title": "OH_CrossCompile" + }, + { + "command": "extension.ohGenerator", + "title": "%extension.ohGenerator.title%" } ], + "viewsWelcome": [ + { + "view": "workbench.explorer.emptyView", + "contents": "Generate NAPI definition code and framework code for OpenHarmony. \n[OHGenerator](command:extension.ohGenerator)" + } + ], "submenus": [ { "id": "gen-menulist", diff --git a/src/vscode_plugin/package.nls.json b/src/vscode_plugin/package.nls.json index 755d0190..8315205e 100644 --- a/src/vscode_plugin/package.nls.json +++ b/src/vscode_plugin/package.nls.json @@ -1,7 +1,8 @@ { - "extension.h2sa.title": "h2sa", + "extension.h2sa.title": "h2sa", "extension.h2hdf.title": "h2hdf", - "extension.h2dts.title": "h2dts", + "extension.h2dts.title": "h2dts", "extension.h2dtscpp.title": "h2dtscpp", - "extension.dts2cpp.title": "dts2cpp" + "extension.dts2cpp.title": "dts2cpp", + "extension.ohGenerator.title": "OHGenerator" } \ No newline at end of file diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index 4c54108e..7d9101d9 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -56,61 +56,13 @@ export function activate(context: vscode.ExtensionContext) { // The code you place here will be executed every time your command is executed if (uri && uri.fsPath) { let versionTag = '3.2'; - const quickPick = vscode.window.createQuickPick(); - quickPick.title = "h2sa"; - quickPick.items = [ - { label: 'h2sa3-2' }, - { label: 'h2sa4-1'} - ]; - quickPick.canSelectMany = false; - - quickPick.onDidAccept(async () => { - const selectedItems = quickPick.selectedItems; - if (selectedItems.length > 0) { - const selectedItem = selectedItems[0].label; - if (selectedItem === 'h2sa3-2') { - versionTag = '3.2'; - } else if (selectedItem === 'h2sa4-1') { - versionTag = '4.1'; - } - } - - vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - title: "Generating SA...", - cancellable: false - }, async (progress) => { - // progress.report({ increment: 0, message: "Starting..." }); - - // analyze - let funDescList = await parseHeaderFile(uri.fsPath); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - - progress.report({ increment: 50, message: "Analyze complete." }); - - // generator - let out = path.dirname(uri.fsPath); - let serviceName = path.basename(uri.fsPath, '.h'); - let rootInfo = { - serviceName: serviceName, - funcs: funDescList.funcs, - serviceId: '19000', - versionTag: versionTag - }; - genServiceFile(rootInfo, out); - - progress.report({ increment: 100, message: "Generation complete." }); - }); - - quickPick.hide(); - }) - - quickPick.onDidHide(() => { - quickPick.dispose(); - }) - - quickPick.show(); + const version = await vscode.window.showQuickPick(['h2sa4-1', 'h2sa3-2'], { placeHolder: 'Please select the version...' }); + if (version === 'h2sa4-1') { + versionTag = '4.1' + } else if (version === 'h2sa3-2') { + versionTag = '3.2' + } + generateSa(uri.fsPath, versionTag); } // Display a message box to the user vscode.window.showInformationMessage('h2sa!'); @@ -121,59 +73,12 @@ export function activate(context: vscode.ExtensionContext) { 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 quickPick = vscode.window.createQuickPick(); - quickPick.title = "h2hdf"; - quickPick.items = [ - { label: 'h2hdf4-1'} - ]; - quickPick.canSelectMany = false; - - quickPick.onDidAccept(async () => { - const selectedItems = quickPick.selectedItems; - if (selectedItems.length > 0) { - const selectedItem = selectedItems[0].label; - if (selectedItem === 'h2hdf4-1') { - versionTag = '4.1'; - } - } - - vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - title: "Generating DTS...", - cancellable: false - }, async (progress) => { - // progress.report({ increment: 0, message: "Starting..." }); - - // analyze - let funDescList = await parseHeaderFile(uri.fsPath); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - - progress.report({ increment: 50, message: "Analyze complete." }); - - // generator - let out = path.dirname(uri.fsPath); - let driverName = path.basename(uri.fsPath, '.h').toLocaleLowerCase(); - let rootInfo = { - driverName: driverName, - funcs: funDescList.funcs, - versionTag: versionTag - }; - genHdfFile(rootInfo, out); - - progress.report({ increment: 100, message: "Generation complete." }); - }); - - quickPick.hide(); - }) - - quickPick.onDidHide(() => { - quickPick.dispose(); - }) - - quickPick.show(); + let versionTag = '4.1'; + const version = await vscode.window.showQuickPick(['h2hdf4-1'], { placeHolder: 'Please select the version...' }); + if (version === 'h2hdf4-1') { + versionTag = '4.1' + } + generateHdf(uri.fsPath, versionTag); } // Display a message box to the user vscode.window.showInformationMessage('h2hdf!'); @@ -183,33 +88,7 @@ export function activate(context: vscode.ExtensionContext) { 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 DTS...", - cancellable: false - }, async (progress) => { - // progress.report({ increment: 0, message: "Starting..." }); - - // parse - let funDescList = await parseHeaderFile(uri.fsPath); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - - progress.report({ increment: 50, message: "Analyze complete." }); - - let fileName = path.basename(uri.fsPath, '.h'); - let rootInfo = { - funcs: funDescList.funcs, - rawFilePath: uri.fsPath, - fileName: fileName - }; - // generator - let out = path.dirname(uri.fsPath); - genDtsFile(rootInfo, out); - - progress.report({ increment: 100, message: "Generation complete." }); - }); - + generateDts(uri.fsPath); } // Display a message box to the user vscode.window.showInformationMessage('h2dts!'); @@ -219,33 +98,7 @@ export function activate(context: vscode.ExtensionContext) { 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) { - vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - title: "Generating DTS...", - cancellable: false - }, async (progress) => { - // progress.report({ increment: 0, message: "Starting..." }); - - // parse - let funDescList = await parseHeaderFile(uri.fsPath); - let fileName = path.basename(uri.fsPath, '.h'); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - - progress.report({ increment: 50, message: "Analyze complete." }); - - let rootInfo: DtscppRootInfo = { - funcs: funDescList.funcs, - rawFilePath: uri.fsPath, // e://xxx.h - fileName: fileName // xxx - }; - - // generator - let out = path.dirname(uri.fsPath); - genDtsCppFile(rootInfo, out); - - progress.report({ increment: 100, message: "Generation complete." }); - }); + generateDtscpp(uri.fsPath); } // Display a message box to the user vscode.window.showInformationMessage('h2dtscpp!'); @@ -274,4 +127,172 @@ export function activate(context: vscode.ExtensionContext) { } }); context.subscriptions.push(dts2cpp); + + // 欢迎菜单页面 + 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'); + let hdfInputPath = path.join(__dirname, '../test/hello.h'); + const value = await vscode.window.showQuickPick(['h2hdf', 'h2sa', 'h2dtscpp', 'h2dts'], { placeHolder: 'Please select...' }); + const what = await vscode.window.showInputBox({ placeHolder: 'please input...' }); + if (value === what && value === 'h2hdf') { + // 输入版本 + let versionTag = '4.1'; + const version = await vscode.window.showQuickPick(['h2hdf4-1'], { placeHolder: 'Please select the version...' }) + if (version === 'h2hdf4-1') { + versionTag === '4.1' + } + generateHdf(hdfInputPath, versionTag); + } else if (value === what && value === 'h2sa') { + // 输入版本 + let versionTag = '3.2'; + const version = await vscode.window.showQuickPick(['h2sa3-2', 'h2sa4-1'], { placeHolder: 'Please select the version...' }) + if (version === 'h2sa4-1') { + versionTag = '4.1'; + } else if (version === 'h2sa3-2') { + versionTag = '3.2'; + } + generateSa(hPath, versionTag); + } else if (value === what && value === 'h2dts') { + generateDts(hPath); + } else if (value === what && value === 'h2dtscpp') { + generateDtscpp(hPath); + } else if (value === what && value === 'aki') { + vscode.window.showInformationMessage('待支持...'); + } else { + vscode.window.showInformationMessage('请重新输入...'); + } + + }); + context.subscriptions.push(ohGenerator); } + +async function generateHdf(hdfInputPath: string, versionTag: string) { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: "Generating HDF...", + cancellable: false + }, async (progress) => { + // analyze + let funDescList = await parseHeaderFile(hdfInputPath); + console.log('parse header file res: ', funDescList); + console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); + progress.report({ increment: 50, message: "Analyze 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: "Generation complete." }); + }); + // 显示出生成路径 + const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hdfInputPath), 'Open in Explorer'); + if (choice === 'Open in Explorer') { + // 打开文件所在的目录 + vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hdfInputPath)); + } +} + +async function generateSa(hPath: string, versionTag: string) { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: "Generating SA...", + cancellable: false + }, async (progress) => { + // analyze + let funDescList = await parseHeaderFile(hPath); + console.log('parse header file res: ', funDescList); + console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); + + progress.report({ increment: 50, message: "Analyze complete." }); + + // generator + let out = path.dirname(hPath); + let serviceName = path.basename(hPath, '.h'); + let rootInfo = { + serviceName: serviceName, + funcs: funDescList.funcs, + serviceId: '19000', + versionTag: versionTag + }; + genServiceFile(rootInfo, out); + progress.report({ increment: 100, message: "Generation complete." }); + }); + // 显示出生成路径 + const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hPath), 'Open in Explorer'); + if (choice === 'Open in Explorer') { + // 打开文件所在的目录 + vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hPath)); + } +} + +async function generateDts(hPath: string) { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: "Generating DTS...", + cancellable: false + }, async (progress) => { + // analyze + let funDescList = await parseHeaderFile(hPath); + console.log('parse header file res: ', funDescList); + console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); + + progress.report({ increment: 50, message: "Analyze complete." }); + + let fileName = path.basename(hPath, '.h'); + let rootInfo = { + funcs: funDescList.funcs, + rawFilePath: hPath, + fileName: fileName + }; + // generator + let out = path.dirname(hPath); + genDtsFile(rootInfo, out); + progress.report({ increment: 100, message: "Generation complete." }); + }); + // 显示出生成路径 + const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hPath), 'Open in Explorer'); + if (choice === 'Open in Explorer') { + // 打开文件所在的目录 + vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hPath)); + } +} + +async function generateDtscpp(hFilePath: string) { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: "Generating DTSCPP...", + cancellable: false + }, async (progress) => { + // analyze + let funDescList = await parseHeaderFile(hFilePath); + let fileName = path.basename(hFilePath, '.h'); + console.log('parse header file res: ', funDescList); + console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); + + progress.report({ increment: 50, message: "Analyze complete." }); + + let rootInfo: DtscppRootInfo = { + funcs: funDescList.funcs, + rawFilePath: hFilePath, + fileName: fileName // xxx + }; + + // generator + let out = path.dirname(hFilePath); + genDtsCppFile(rootInfo, out); + progress.report({ increment: 100, message: "Generation complete." }); + }); + // 显示出生成路径 + const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hFilePath), 'Open in Explorer'); + if (choice === 'Open in Explorer') { + // 打开文件所在的目录 + vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hFilePath)); + } +} + -- Gitee From f1be507822b2716e2de0697b5af5774608352d31 Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Tue, 29 Oct 2024 17:02:31 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E7=9A=84.h=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/test/hello.h | 23 +++++++++++++++++++++++ src/vscode_plugin/test/test.h | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/vscode_plugin/test/hello.h create mode 100644 src/vscode_plugin/test/test.h diff --git a/src/vscode_plugin/test/hello.h b/src/vscode_plugin/test/hello.h new file mode 100644 index 00000000..a320f0ab --- /dev/null +++ b/src/vscode_plugin/test/hello.h @@ -0,0 +1,23 @@ +/* +* 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. +*/ + +#include +#ifndef HELLO_H +#define HELLO_H + +namespace OHOS { + std::string Helloworld(std::string sendMsg); +} +#endif \ No newline at end of file diff --git a/src/vscode_plugin/test/test.h b/src/vscode_plugin/test/test.h new file mode 100644 index 00000000..6b945d07 --- /dev/null +++ b/src/vscode_plugin/test/test.h @@ -0,0 +1,22 @@ +/* +* 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. +*/ + +#ifndef TEST_H +#define TEST_H + +namespace OHOS { + int testFunc(int v1, int v2, bool v3); +} +#endif \ No newline at end of file -- Gitee From f4c8aeaf0307898e8ea9db0e44dbc4e5357b27ac Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Tue, 29 Oct 2024 17:11:41 +0800 Subject: [PATCH 3/7] fix codecheck Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/test/hello.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vscode_plugin/test/hello.h b/src/vscode_plugin/test/hello.h index a320f0ab..c251f379 100644 --- a/src/vscode_plugin/test/hello.h +++ b/src/vscode_plugin/test/hello.h @@ -13,11 +13,11 @@ * limitations under the License. */ -#include #ifndef HELLO_H #define HELLO_H +#include namespace OHOS { std::string Helloworld(std::string sendMsg); } -#endif \ No newline at end of file +#endif \ No newline at end of file -- Gitee From b6ca5e34f50f79208edae6828c78b8a2de2bab55 Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Tue, 29 Oct 2024 20:08:33 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/src/extension.ts | 73 ++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index 7d9101d9..fbfc5bd1 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -56,13 +56,24 @@ export function activate(context: vscode.ExtensionContext) { // 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(['h2sa4-1', 'h2sa3-2'], { placeHolder: 'Please select the version...' }); - if (version === 'h2sa4-1') { + const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release', 'OpenHarmony 3.2 release'], { placeHolder: 'Please select the version...' }); + if (version === 'OpenHarmony 4.1 release') { versionTag = '4.1' - } else if (version === 'h2sa3-2') { + } else if (version === 'OpenHarmony 3.2 release') { versionTag = '3.2' } - generateSa(uri.fsPath, versionTag); + const serviceId = await vscode.window.showInputBox({ + placeHolder: 'Please input serviceId...', + validateInput: (input) => { + if (!input) { + return "Input cannot be empty"; + } + if (!Number(input)) { + return "Input a number" + } + } + }); + generateSa(uri.fsPath, versionTag, serviceId as string); } // Display a message box to the user vscode.window.showInformationMessage('h2sa!'); @@ -74,8 +85,8 @@ export function activate(context: vscode.ExtensionContext) { // 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(['h2hdf4-1'], { placeHolder: 'Please select the version...' }); - if (version === 'h2hdf4-1') { + const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: 'Please select the version...' }); + if (version === 'OpenHarmony 4.1 release') { versionTag = '4.1' } generateHdf(uri.fsPath, versionTag); @@ -131,39 +142,51 @@ export function activate(context: vscode.ExtensionContext) { // 欢迎菜单页面 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'); let hdfInputPath = path.join(__dirname, '../test/hello.h'); - const value = await vscode.window.showQuickPick(['h2hdf', 'h2sa', 'h2dtscpp', 'h2dts'], { placeHolder: 'Please select...' }); - const what = await vscode.window.showInputBox({ placeHolder: 'please input...' }); - if (value === what && value === 'h2hdf') { + const value = await vscode.window.showQuickPick(['Hdf Framework', 'SystemAbility Framework', 'N-API Framework'], { placeHolder: 'Please select...' }); + const what = await vscode.window.showInputBox({ + placeHolder: 'Please input...', + validateInput: (input) => { + if (!input) { + return "Input cannot be empty"; + } + } + }); + if (value === what && value === 'Hdf Framework') { // 输入版本 let versionTag = '4.1'; - const version = await vscode.window.showQuickPick(['h2hdf4-1'], { placeHolder: 'Please select the version...' }) - if (version === 'h2hdf4-1') { + const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: 'Please select the version...' }) + if (version === 'OpenHarmony 4.1 release') { versionTag === '4.1' } generateHdf(hdfInputPath, versionTag); - } else if (value === what && value === 'h2sa') { + } else if (value === what && value === 'SystemAbility Framework') { // 输入版本 let versionTag = '3.2'; - const version = await vscode.window.showQuickPick(['h2sa3-2', 'h2sa4-1'], { placeHolder: 'Please select the version...' }) - if (version === 'h2sa4-1') { + const version = await vscode.window.showQuickPick(['OpenHarmony 3.2 release', 'OpenHarmony 4.1 release'], { placeHolder: 'Please select the version...' }) + if (version === 'OpenHarmony 4.1 release') { versionTag = '4.1'; - } else if (version === 'h2sa3-2') { + } else if (version === 'OpenHarmony 3.2 release') { versionTag = '3.2'; } - generateSa(hPath, versionTag); - } else if (value === what && value === 'h2dts') { - generateDts(hPath); - } else if (value === what && value === 'h2dtscpp') { + const serviceId = await vscode.window.showInputBox({ + placeHolder: 'Please input serviceId...', + validateInput: (input) => { + if (!input) { + return "Input cannot be empty"; + } + if (!Number(input)) { + return "Input a number" + } + } + }); + generateSa(hPath, versionTag, serviceId as string); + } else if (value === what && value === 'N-API Framework') { generateDtscpp(hPath); - } else if (value === what && value === 'aki') { - vscode.window.showInformationMessage('待支持...'); } else { vscode.window.showInformationMessage('请重新输入...'); } - }); context.subscriptions.push(ohGenerator); } @@ -198,7 +221,7 @@ async function generateHdf(hdfInputPath: string, versionTag: string) { } } -async function generateSa(hPath: string, versionTag: string) { +async function generateSa(hPath: string, versionTag: string, serviceId: string) { vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "Generating SA...", @@ -217,7 +240,7 @@ async function generateSa(hPath: string, versionTag: string) { let rootInfo = { serviceName: serviceName, funcs: funDescList.funcs, - serviceId: '19000', + serviceId: serviceId, versionTag: versionTag }; genServiceFile(rootInfo, out); -- Gitee From 4dff021267d280f887c24f848f55a79d53fd43a2 Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Tue, 29 Oct 2024 20:25:47 +0800 Subject: [PATCH 5/7] =?UTF-8?q?showInputBox=E8=BE=93=E5=85=A5=E6=9C=89?= =?UTF-8?q?=E6=95=88=E6=80=A7=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/src/extension.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index fbfc5bd1..1ba11720 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -149,11 +149,14 @@ export function activate(context: vscode.ExtensionContext) { placeHolder: 'Please input...', validateInput: (input) => { if (!input) { - return "Input cannot be empty"; + return "Input cannot be empty"; + } + if (input !== value) { + return "Inconsistent input" } } }); - if (value === what && value === 'Hdf Framework') { + if (value === 'Hdf Framework') { // 输入版本 let versionTag = '4.1'; const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: 'Please select the version...' }) @@ -161,7 +164,7 @@ export function activate(context: vscode.ExtensionContext) { versionTag === '4.1' } generateHdf(hdfInputPath, versionTag); - } else if (value === what && value === 'SystemAbility Framework') { + } else if (value === 'SystemAbility Framework') { // 输入版本 let versionTag = '3.2'; const version = await vscode.window.showQuickPick(['OpenHarmony 3.2 release', 'OpenHarmony 4.1 release'], { placeHolder: 'Please select the version...' }) @@ -182,10 +185,8 @@ export function activate(context: vscode.ExtensionContext) { } }); generateSa(hPath, versionTag, serviceId as string); - } else if (value === what && value === 'N-API Framework') { + } else if (value === 'N-API Framework') { generateDtscpp(hPath); - } else { - vscode.window.showInformationMessage('请重新输入...'); } }); context.subscriptions.push(ohGenerator); -- Gitee From 3ae8ffbe38a13b874b1572304aa13cf6f066b4fd Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Tue, 29 Oct 2024 20:36:47 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=8F=8C=E5=BC=95=E5=8F=B7=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=8D=95=E5=BC=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/src/extension.ts | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index 1ba11720..d9a0200a 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -66,10 +66,10 @@ export function activate(context: vscode.ExtensionContext) { placeHolder: 'Please input serviceId...', validateInput: (input) => { if (!input) { - return "Input cannot be empty"; + return 'Input cannot be empty'; } if (!Number(input)) { - return "Input a number" + return 'Input a number' } } }); @@ -127,7 +127,7 @@ export function activate(context: vscode.ExtensionContext) { // Display a message box to the user // parseTsFile(uri.fsPath) let res = parseTsFile(uri.fsPath); - console.info("res: " + JSON.stringify(res)); + console.info('res: ' + JSON.stringify(res)); vscode.window.showInformationMessage('dts2cpp!'); } else { console.log('not dts uri is : ' + uri.fsPath ); @@ -149,10 +149,10 @@ export function activate(context: vscode.ExtensionContext) { placeHolder: 'Please input...', validateInput: (input) => { if (!input) { - return "Input cannot be empty"; + return 'Input cannot be empty'; } if (input !== value) { - return "Inconsistent input" + return 'Inconsistent input' } } }); @@ -177,10 +177,10 @@ export function activate(context: vscode.ExtensionContext) { placeHolder: 'Please input serviceId...', validateInput: (input) => { if (!input) { - return "Input cannot be empty"; + return 'Input cannot be empty'; } if (!Number(input)) { - return "Input a number" + return 'Input a number' } } }); @@ -195,14 +195,14 @@ export function activate(context: vscode.ExtensionContext) { async function generateHdf(hdfInputPath: string, versionTag: string) { vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, - title: "Generating HDF...", + title: 'Generating HDF...', cancellable: false }, async (progress) => { // analyze let funDescList = await parseHeaderFile(hdfInputPath); console.log('parse header file res: ', funDescList); console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - progress.report({ increment: 50, message: "Analyze complete." }); + progress.report({ increment: 50, message: 'Analyze complete.' }); // generator let out = path.dirname(hdfInputPath); let driverName = path.basename(hdfInputPath, '.h').toLocaleLowerCase(); @@ -212,7 +212,7 @@ async function generateHdf(hdfInputPath: string, versionTag: string) { versionTag: versionTag }; genHdfFile(rootInfo, out); - progress.report({ increment: 100, message: "Generation complete." }); + progress.report({ increment: 100, message: 'Generation complete.' }); }); // 显示出生成路径 const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hdfInputPath), 'Open in Explorer'); @@ -225,7 +225,7 @@ async function generateHdf(hdfInputPath: string, versionTag: string) { async function generateSa(hPath: string, versionTag: string, serviceId: string) { vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, - title: "Generating SA...", + title: 'Generating SA...', cancellable: false }, async (progress) => { // analyze @@ -233,7 +233,7 @@ async function generateSa(hPath: string, versionTag: string, serviceId: string) console.log('parse header file res: ', funDescList); console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - progress.report({ increment: 50, message: "Analyze complete." }); + progress.report({ increment: 50, message: 'Analyze complete.' }); // generator let out = path.dirname(hPath); @@ -245,7 +245,7 @@ async function generateSa(hPath: string, versionTag: string, serviceId: string) versionTag: versionTag }; genServiceFile(rootInfo, out); - progress.report({ increment: 100, message: "Generation complete." }); + progress.report({ increment: 100, message: 'Generation complete.' }); }); // 显示出生成路径 const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hPath), 'Open in Explorer'); @@ -258,7 +258,7 @@ async function generateSa(hPath: string, versionTag: string, serviceId: string) async function generateDts(hPath: string) { vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, - title: "Generating DTS...", + title: 'Generating DTS...', cancellable: false }, async (progress) => { // analyze @@ -266,7 +266,7 @@ async function generateDts(hPath: string) { console.log('parse header file res: ', funDescList); console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - progress.report({ increment: 50, message: "Analyze complete." }); + progress.report({ increment: 50, message: 'Analyze complete.' }); let fileName = path.basename(hPath, '.h'); let rootInfo = { @@ -277,7 +277,7 @@ async function generateDts(hPath: string) { // generator let out = path.dirname(hPath); genDtsFile(rootInfo, out); - progress.report({ increment: 100, message: "Generation complete." }); + progress.report({ increment: 100, message: 'Generation complete.' }); }); // 显示出生成路径 const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hPath), 'Open in Explorer'); @@ -290,7 +290,7 @@ async function generateDts(hPath: string) { async function generateDtscpp(hFilePath: string) { vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, - title: "Generating DTSCPP...", + title: 'Generating DTSCPP...', cancellable: false }, async (progress) => { // analyze @@ -299,7 +299,7 @@ async function generateDtscpp(hFilePath: string) { console.log('parse header file res: ', funDescList); console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - progress.report({ increment: 50, message: "Analyze complete." }); + progress.report({ increment: 50, message: 'Analyze complete.' }); let rootInfo: DtscppRootInfo = { funcs: funDescList.funcs, @@ -310,7 +310,7 @@ async function generateDtscpp(hFilePath: string) { // generator let out = path.dirname(hFilePath); genDtsCppFile(rootInfo, out); - progress.report({ increment: 100, message: "Generation complete." }); + progress.report({ increment: 100, message: 'Generation complete.' }); }); // 显示出生成路径 const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hFilePath), 'Open in Explorer'); -- Gitee From 06f86a7c8611660ac88606b84971fa1b55a7e81a Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Wed, 30 Oct 2024 15:49:25 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=94=AF=E6=8C=81extension=E4=B8=AD?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=9B=BD=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/l10n/bundle.l10n.zh-cn.json | 18 +++ src/vscode_plugin/package.json | 8 +- src/vscode_plugin/package.nls.json | 4 +- src/vscode_plugin/package.nls.zh-cn.json | 10 ++ src/vscode_plugin/src/extension.ts | 132 ++++++++---------- 5 files changed, 93 insertions(+), 79 deletions(-) create mode 100644 src/vscode_plugin/l10n/bundle.l10n.zh-cn.json create mode 100644 src/vscode_plugin/package.nls.zh-cn.json diff --git a/src/vscode_plugin/l10n/bundle.l10n.zh-cn.json b/src/vscode_plugin/l10n/bundle.l10n.zh-cn.json new file mode 100644 index 00000000..68db9450 --- /dev/null +++ b/src/vscode_plugin/l10n/bundle.l10n.zh-cn.json @@ -0,0 +1,18 @@ +{ + "Hdf Framework": "Hdf妗嗘灦", + "SystemAbility Framework": "SystemAbility妗嗘灦", + "N-API Framework": "N-API妗嗘灦", + "Please input serviceId like 19000...": "璇疯緭鍏erviceId... 濡: 19000", + "Input cannot be empty": "杈撳叆涓嶈兘涓虹┖", + "Please input a number...": "璇疯緭鍏ヤ竴涓暟瀛", + "Inconsistent input": "鎵閫夐」涓庤緭鍏ヤ笉涓鑷", + "Please select the version...": "璇烽夋嫨鐗堟湰...", + "Please select framework...": "璇烽夋嫨妗嗘灦...", + "Please confirm your selection...": "璇风‘璁ゆ偍鐨勯夋嫨...", + "Open in Explorer": "鍦ㄦ祻瑙堝櫒涓墦寮", + "Parse complete.": "杞崲瀹屾垚", + "Generation complete:": "鐢熸垚瀹屾垚", + "You selected a directory:": "鎮ㄩ夋嫨浜嗕竴涓洰褰", + "Please select a directory.": "璇烽夋嫨涓涓洰褰", + "No resource selected.": "鏈夋嫨璧勬簮" +} \ No newline at end of file diff --git a/src/vscode_plugin/package.json b/src/vscode_plugin/package.json index 9483235e..47638629 100644 --- a/src/vscode_plugin/package.json +++ b/src/vscode_plugin/package.json @@ -21,6 +21,7 @@ "onCommand:extension.h2hdf" ], "main": "./out/extension.js", + "l10n":"./l10n", "contributes": { "commands": [ { @@ -46,7 +47,7 @@ }, { "command": "extension.ohcrosscompile", - "title": "OH_CrossCompile" + "title": "%extension.ohcrosscompile.title%" }, { "command": "extension.ohGenerator", @@ -56,7 +57,7 @@ "viewsWelcome": [ { "view": "workbench.explorer.emptyView", - "contents": "Generate NAPI definition code and framework code for OpenHarmony. \n[OHGenerator](command:extension.ohGenerator)" + "contents": "%Generate NAPI definition code and framework code for OpenHarmony. \n[OHGenerator](command:extension.ohGenerator)%" } ], "submenus": [ @@ -122,6 +123,7 @@ }, "dependencies": { "vsce": "^2.15.0", - "typescript": "^4.7.2" + "typescript": "^4.7.2", + "@vscode/l10n": "^0.0.10" } } diff --git a/src/vscode_plugin/package.nls.json b/src/vscode_plugin/package.nls.json index 8315205e..47b1df82 100644 --- a/src/vscode_plugin/package.nls.json +++ b/src/vscode_plugin/package.nls.json @@ -4,5 +4,7 @@ "extension.h2dts.title": "h2dts", "extension.h2dtscpp.title": "h2dtscpp", "extension.dts2cpp.title": "dts2cpp", - "extension.ohGenerator.title": "OHGenerator" + "extension.ohGenerator.title": "OHGenerator", + "extension.ohcrosscompile.title": "OH_CrossCompile", + "Generate NAPI definition code and framework code for OpenHarmony. \n[OHGenerator](command:extension.ohGenerator)": "Generate NAPI definition code and framework code for OpenHarmony. \n[OHGenerator](command:extension.ohGenerator)" } \ No newline at end of file diff --git a/src/vscode_plugin/package.nls.zh-cn.json b/src/vscode_plugin/package.nls.zh-cn.json new file mode 100644 index 00000000..ebc93369 --- /dev/null +++ b/src/vscode_plugin/package.nls.zh-cn.json @@ -0,0 +1,10 @@ +{ + "extension.h2sa.title": "h2sa", + "extension.h2hdf.title": "h2hdf", + "extension.h2dts.title": "h2dts", + "extension.h2dtscpp.title": "h2dtscpp", + "extension.dts2cpp.title": "dts2cpp", + "extension.ohGenerator.title": "OHGenerator", + "extension.ohcrosscompile.title": "OH_CrossCompile", + "Generate NAPI definition code and framework code for OpenHarmony. \n[OHGenerator](command:extension.ohGenerator)": "涓篛penHarmony鐢熸垚NAPI瀹氫箟鍜屾鏋朵唬鐮併 \n[OHGenerator](command:extension.ohGenerator)" +} \ No newline at end of file diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index d04d5bc7..8efd6bfb 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -26,6 +26,25 @@ import { genDtsFile } from './gendts'; import { genHdfFile } from './genhdf'; import { genDtsCppFile } from './gendtscpp'; +// 获取本地化字符串 +const SELECTED_DIR = vscode.l10n.t('You selected a directory:'); +const SELECTE_DIR = vscode.l10n.t('Please select a directory.'); +const NO_RES_SELECTED = vscode.l10n.t('No resource selected.'); +const HDF_FRAMEWORK = vscode.l10n.t('Hdf Framework'); +const SA_FRAMEWORK = vscode.l10n.t('SystemAbility Framework'); +const NAPI_FRAMEWORK = vscode.l10n.t('N-API Framework'); +const SELECT_VERSION = vscode.l10n.t('Please select the version...'); +const INPUT_SERVICEID = vscode.l10n.t('Please input serviceId like 19000...'); +const INPUT_NO_EMPTY = vscode.l10n.t('Input cannot be empty'); +const INPUT_NUMBER = vscode.l10n.t('Please input a number...'); +const SELECT_FRAMWORK = vscode.l10n.t('Please select framework...'); +const CONFIRM_SELECT = vscode.l10n.t('Please confirm your selection...'); +const INPUT_INCONSISTENT = vscode.l10n.t('Inconsistent input'); +const PARSE_COMPLETE = vscode.l10n.t('Parse complete.'); +const GEN_COMPLETE = vscode.l10n.t('Generation complete:'); +const OPEN_IN_EXPLORER = vscode.l10n.t('Open in Explorer'); + + // this method is called when your extension is activated // your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { @@ -38,12 +57,12 @@ export function activate(context: vscode.ExtensionContext) { if (uri && uri.fsPath) { const stat = await vscode.workspace.fs.stat(uri); if (stat.type === vscode.FileType.Directory) { - vscode.window.showInformationMessage(`You selected a directory: ${uri.fsPath}`); + vscode.window.showInformationMessage(SELECTED_DIR + uri.fsPath); } else { - vscode.window.showWarningMessage('Please select a directory.'); + vscode.window.showWarningMessage(SELECTE_DIR); } } else { - vscode.window.showWarningMessage('No resource selected.'); + vscode.window.showWarningMessage(NO_RES_SELECTED); } // Display a message box to the user vscode.window.showInformationMessage('ohcrosscompile!'); @@ -55,28 +74,27 @@ export function activate(context: vscode.ExtensionContext) { const h2sa = vscode.commands.registerCommand('extension.h2sa', async (uri) => { // 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: 'Please select the version...' }); + 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: 'Please input serviceId...', + placeHolder: INPUT_SERVICEID, + value: "19000", // 设置默认值 validateInput: (input) => { if (!input) { - return 'Input cannot be empty'; + return INPUT_NO_EMPTY; } if (!Number(input)) { - return 'Input a number' + return INPUT_NUMBER } } }); generateSa(uri.fsPath, versionTag, serviceId as string); } - // Display a message box to the user - vscode.window.showInformationMessage('h2sa!'); }); context.subscriptions.push(h2sa); @@ -85,14 +103,12 @@ export function activate(context: vscode.ExtensionContext) { // 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: 'Please select the version...' }); + 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); } - // Display a message box to the user - vscode.window.showInformationMessage('h2hdf!'); }); context.subscriptions.push(h2hdf); @@ -107,7 +123,7 @@ export function activate(context: vscode.ExtensionContext) { // parse let parseRes = await parseHeaderFile(uri.fsPath); console.log('parse header file res: ', parseRes); - progress.report({ increment: 50, message: "Parse complete." }); + progress.report({ increment: 50, message: PARSE_COMPLETE }); let rootInfo: GenInfo = { parseObj: parseRes, @@ -116,10 +132,9 @@ export function activate(context: vscode.ExtensionContext) { }; // generator let outPath = genDtsFile(rootInfo); - progress.report({ increment: 100, message: `Generation complete: ${outPath}.` }); + progress.report({ increment: 100, message: GEN_COMPLETE + outPath }); }); } - }); context.subscriptions.push(h2dts); @@ -128,8 +143,6 @@ export function activate(context: vscode.ExtensionContext) { if (uri && uri.fsPath) { generateDtscpp(uri.fsPath); } - // Display a message box to the user - vscode.window.showInformationMessage('h2dtscpp!'); }); context.subscriptions.push(h2dtscpp); @@ -161,48 +174,49 @@ export function activate(context: vscode.ExtensionContext) { // The code you place here will be executed every time your command is executed let hPath = path.join(__dirname, '../test/test.h'); let hdfInputPath = path.join(__dirname, '../test/hello.h'); - const value = await vscode.window.showQuickPick(['Hdf Framework', 'SystemAbility Framework', 'N-API Framework'], { placeHolder: 'Please select...' }); - const what = await vscode.window.showInputBox({ - placeHolder: 'Please input...', + const value = await vscode.window.showQuickPick([HDF_FRAMEWORK, SA_FRAMEWORK, NAPI_FRAMEWORK], { placeHolder: SELECT_FRAMWORK }); + await vscode.window.showInputBox({ + placeHolder: CONFIRM_SELECT, validateInput: (input) => { if (!input) { - return 'Input cannot be empty'; + return INPUT_NO_EMPTY; } if (input !== value) { - return 'Inconsistent input' + return INPUT_INCONSISTENT; } } }); - if (value === 'Hdf Framework') { + if (value === HDF_FRAMEWORK) { // 输入版本 let versionTag = '4.1'; - const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: 'Please select the version...' }) + const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: SELECT_VERSION }) if (version === 'OpenHarmony 4.1 release') { versionTag === '4.1' } generateHdf(hdfInputPath, versionTag); - } else if (value === 'SystemAbility Framework') { + } else if (value === SA_FRAMEWORK) { // 输入版本 let versionTag = '3.2'; - const version = await vscode.window.showQuickPick(['OpenHarmony 3.2 release', 'OpenHarmony 4.1 release'], { placeHolder: 'Please select the version...' }) + const version = await vscode.window.showQuickPick(['OpenHarmony 3.2 release', 'OpenHarmony 4.1 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: 'Please input serviceId...', + placeHolder: INPUT_SERVICEID, + value: "19000", validateInput: (input) => { if (!input) { - return 'Input cannot be empty'; + return INPUT_NO_EMPTY; } if (!Number(input)) { - return 'Input a number' + return INPUT_NUMBER } } }); generateSa(hPath, versionTag, serviceId as string); - } else if (value === 'N-API Framework') { + } else if (value === NAPI_FRAMEWORK) { generateDtscpp(hPath); } }); @@ -219,7 +233,7 @@ async function generateHdf(hdfInputPath: string, versionTag: string) { let funDescList = await parseHeaderFile(hdfInputPath); console.log('parse header file res: ', funDescList); console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - progress.report({ increment: 50, message: 'Analyze complete.' }); + progress.report({ increment: 50, message: PARSE_COMPLETE }); // generator let out = path.dirname(hdfInputPath); let driverName = path.basename(hdfInputPath, '.h').toLocaleLowerCase(); @@ -229,11 +243,11 @@ async function generateHdf(hdfInputPath: string, versionTag: string) { versionTag: versionTag }; genHdfFile(rootInfo, out); - progress.report({ increment: 100, message: 'Generation complete.' }); + progress.report({ increment: 100, message: GEN_COMPLETE + out}); }); // 显示出生成路径 - const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hdfInputPath), 'Open in Explorer'); - if (choice === 'Open in Explorer') { + const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hdfInputPath), OPEN_IN_EXPLORER); + if (choice === OPEN_IN_EXPLORER) { // 打开文件所在的目录 vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hdfInputPath)); } @@ -250,7 +264,7 @@ async function generateSa(hPath: string, versionTag: string, serviceId: string) console.log('parse header file res: ', funDescList); console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - progress.report({ increment: 50, message: 'Analyze complete.' }); + progress.report({ increment: 50, message: PARSE_COMPLETE }); // generator let out = path.dirname(hPath); @@ -262,48 +276,16 @@ async function generateSa(hPath: string, versionTag: string, serviceId: string) versionTag: versionTag }; genServiceFile(rootInfo, out); - progress.report({ increment: 100, message: 'Generation complete.' }); + progress.report({ increment: 100, message: GEN_COMPLETE + out }); }); // 显示出生成路径 - const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hPath), 'Open in Explorer'); - if (choice === 'Open in Explorer') { + const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hPath), OPEN_IN_EXPLORER); + if (choice === OPEN_IN_EXPLORER) { // 打开文件所在的目录 vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hPath)); } } -async function generateDts(hPath: string) { - vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - title: 'Generating DTS...', - cancellable: false - }, async (progress) => { - // analyze - let funDescList = await parseHeaderFile(hPath); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - - progress.report({ increment: 50, message: 'Analyze complete.' }); - - let fileName = path.basename(hPath, '.h'); - let rootInfo = { - funcs: funDescList.funcs, - rawFilePath: hPath, - fileName: fileName - }; - // generator - let out = path.dirname(hPath); - genDtsFile(rootInfo, out); - progress.report({ increment: 100, message: 'Generation complete.' }); - }); - // 显示出生成路径 - const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hPath), 'Open in Explorer'); - if (choice === 'Open in Explorer') { - // 打开文件所在的目录 - vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hPath)); - } -} - async function generateDtscpp(hFilePath: string) { vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, @@ -316,7 +298,7 @@ async function generateDtscpp(hFilePath: string) { console.log('parse header file res: ', funDescList); console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - progress.report({ increment: 50, message: 'Analyze complete.' }); + progress.report({ increment: 50, message: PARSE_COMPLETE }); let rootInfo: DtscppRootInfo = { funcs: funDescList.funcs, @@ -327,11 +309,11 @@ async function generateDtscpp(hFilePath: string) { // generator let out = path.dirname(hFilePath); genDtsCppFile(rootInfo, out); - progress.report({ increment: 100, message: 'Generation complete.' }); + progress.report({ increment: 100, message: GEN_COMPLETE + out }); }); // 显示出生成路径 - const choice = await vscode.window.showInformationMessage('生成路径:', path.dirname(hFilePath), 'Open in Explorer'); - if (choice === 'Open in Explorer') { + const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hFilePath), OPEN_IN_EXPLORER); + if (choice === OPEN_IN_EXPLORER) { // 打开文件所在的目录 vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hFilePath)); } -- Gitee