!475 vscode插件生成框架增加欢迎菜单里的按钮(workbench.explorer.emptyView)

Merge pull request !475 from 苟晶晶/master
This commit is contained in:
openharmony_ci 2024-10-30 08:36:56 +00:00 committed by Gitee
commit b4bc89ebe3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 294 additions and 152 deletions

View File

@ -0,0 +1,18 @@
{
"Hdf Framework": "Hdf框架",
"SystemAbility Framework": "SystemAbility框架",
"N-API Framework": "N-API框架",
"Please input serviceId like 19000...": "请输入serviceId... 如: 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.": "未选择资源"
}

View File

@ -21,6 +21,7 @@
"onCommand:extension.h2hdf"
],
"main": "./out/extension.js",
"l10n":"./l10n",
"contributes": {
"commands": [
{
@ -46,9 +47,19 @@
},
{
"command": "extension.ohcrosscompile",
"title": "OH_CrossCompile"
"title": "%extension.ohcrosscompile.title%"
},
{
"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",
@ -112,6 +123,7 @@
},
"dependencies": {
"vsce": "^2.15.0",
"typescript": "^4.7.2"
"typescript": "^4.7.2",
"@vscode/l10n": "^0.0.10"
}
}

View File

@ -1,7 +1,10 @@
{
"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",
"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)"
}

View File

@ -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)": "为OpenHarmony生成NAPI定义和框架代码。 \n[OHGenerator](command:extension.ohGenerator)"
}

View File

@ -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,65 +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 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';
}
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
}
}
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();
});
generateSa(uri.fsPath, versionTag, serviceId as string);
}
// Display a message box to the user
vscode.window.showInformationMessage('h2sa!');
});
context.subscriptions.push(h2sa);
@ -121,62 +102,13 @@ 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(['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);
@ -191,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,
@ -200,7 +132,7 @@ 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 });
});
}
});
@ -209,36 +141,8 @@ 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!');
});
context.subscriptions.push(h2dtscpp);
@ -253,7 +157,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 );
@ -264,4 +168,154 @@ 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([HDF_FRAMEWORK, SA_FRAMEWORK, NAPI_FRAMEWORK], { placeHolder: SELECT_FRAMWORK });
await vscode.window.showInputBox({
placeHolder: CONFIRM_SELECT,
validateInput: (input) => {
if (!input) {
return INPUT_NO_EMPTY;
}
if (input !== value) {
return INPUT_INCONSISTENT;
}
}
});
if (value === HDF_FRAMEWORK) {
// 输入版本
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(hdfInputPath, versionTag);
} else if (value === SA_FRAMEWORK) {
// 输入版本
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') {
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(hPath, versionTag, serviceId as string);
} else if (value === NAPI_FRAMEWORK) {
generateDtscpp(hPath);
}
});
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: 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});
});
// 显示出生成路径
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));
}
}
async function generateSa(hPath: string, versionTag: string, serviceId: 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: 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 });
});
// 显示出生成路径
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 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: PARSE_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: GEN_COMPLETE + out });
});
// 显示出生成路径
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));
}
}

View File

@ -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.
*/
#ifndef HELLO_H
#define HELLO_H
#include <string>
namespace OHOS {
std::string Helloworld(std::string sendMsg);
}
#endif

View File

@ -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