diff --git a/src/vscode_plugin/.vscode/launch.json b/src/vscode_plugin/.vscode/launch.json new file mode 100644 index 0000000000000000000000000000000000000000..a875ceadf220c72d9703b8c13502674ed707cd2c --- /dev/null +++ b/src/vscode_plugin/.vscode/launch.json @@ -0,0 +1,21 @@ +// A launch configuration that compiles the extension and then opens it inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [{ + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ], + "outFiles": [ + "${workspaceFolder}/out/**/*.js" + ], + "preLaunchTask": "npm: watch" + } + ] +} diff --git a/src/vscode_plugin/.vscode/tasks.json b/src/vscode_plugin/.vscode/tasks.json new file mode 100644 index 0000000000000000000000000000000000000000..241aa6d9964539ad0cc7baeaf36dbef3c205e386 --- /dev/null +++ b/src/vscode_plugin/.vscode/tasks.json @@ -0,0 +1,20 @@ +// See https://go.microsoft.com/fwlink/?LinkId=733558 +// for the documentation about the tasks.json format +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "watch", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/src/vscode_plugin/package.json b/src/vscode_plugin/package.json index c2c3d231968eb3901a0e56a31ea44b438ffa9114..44440281f4ea912cc42b061a0ec61540c71fe6a2 100644 --- a/src/vscode_plugin/package.json +++ b/src/vscode_plugin/package.json @@ -13,28 +13,15 @@ "Other" ], "activationEvents": [ - "onCommand:extension.h2sa3-2", - "onCommand:extension.h2sa4-1", - "onCommand:extension.h2hdf4-1", "onCommand:extension.h2dts", "onCommand:extension.h2dtscpp", - "onCommand:extension.dts2cpp" + "onCommand:extension.dts2cpp", + "onCommand:extension.h2sa", + "onCommand:extension.h2hdf" ], "main": "./out/extension.js", "contributes": { "commands": [ - { - "command": "extension.h2sa3-2", - "title": "h2sa3-2" - }, - { - "command": "extension.h2sa4-1", - "title": "h2sa4-1" - }, - { - "command": "extension.h2hdf4-1", - "title": "h2hdf4-1" - }, { "command": "extension.h2dts", "title": "h2dts" @@ -46,33 +33,33 @@ { "command": "extension.dts2cpp", "title": "dts2cpp" + }, + { + "command": "extension.h2sa", + "title": "h2sa" + }, + { + "command": "extension.h2hdf", + "title": "h2hdf" } ], "submenus": [ { "id": "gen-menulist", "label": "OHOS_Gen" - }, - { - "id": "gen-h2sa", - "label": "gen_sa" - }, - { - "id": "gen-h2hdf", - "label": "gen_hdf" } ], "menus": { "gen-menulist": [ { - "submenu": "gen-h2sa", - "when": "resourceExtname == .h", - "group": "2_workspace" + "command": "extension.h2sa", + "when": "resourceExtname == .h", + "group": "2_workspace" }, { - "submenu": "gen-h2hdf", - "when": "resourceExtname == .h", - "group": "2_workspace" + "command": "extension.h2hdf", + "when": "resourceExtname == .h", + "group": "2_workspace" }, { "command": "extension.h2dts", @@ -96,25 +83,6 @@ "when": "resourceExtname == .h || resourceExtname == .ts", "group": "2_workspace" } - ], - "gen-h2sa": [ - { - "command": "extension.h2sa3-2", - "when": "resourceExtname == .h", - "group": "2_workspace" - }, - { - "command": "extension.h2sa4-1", - "when": "resourceExtname == .h", - "group": "2_workspace" - } - ], - "gen-h2hdf": [ - { - "command": "extension.h2hdf4-1", - "when": "resourceExtname == .h", - "group": "2_workspace" - } ] } }, diff --git a/src/vscode_plugin/src/extension.ts b/src/vscode_plugin/src/extension.ts index 5c7a8f294e60f3e47aa0dfaf15e7b2bc77bc8bc2..0dfd802ab2313f744ca58af7f8d4799a98b5a494 100644 --- a/src/vscode_plugin/src/extension.ts +++ b/src/vscode_plugin/src/extension.ts @@ -25,7 +25,6 @@ import { genServiceFile } from './gensa'; import { genDtsFile } from './gendts'; import { genHdfFile } from './genhdf'; import { genDtsCppFile } from './gendtscpp'; -import fs = require('fs'); // this method is called when your extension is activated // your extension is activated the very first time the command is executed @@ -37,125 +36,204 @@ export function activate(context: vscode.ExtensionContext) { // The command has been defined in the package.json file // Now provide the implementation of the command with registerCommand // The commandId parameter must match the command field in package.json - const h2sa3_2 = vscode.commands.registerCommand('extension.h2sa3-2', async (uri) => { - // The code you place here will be executed every time your command is executed - if (uri && uri.fsPath) { - // parse - let funDescList = await parseHeaderFile(uri.fsPath); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - // generator - let out = path.dirname(uri.fsPath); - let serviceName = path.basename(uri.fsPath, '.h'); - let rootInfo = { - serviceName: serviceName, - funcs: funDescList.funcs, - serviceId: '19000', - versionTag: '3.2' - }; - genServiceFile(rootInfo, out); - } - // Display a message box to the user - vscode.window.showInformationMessage('h2sa3_2!'); - }); - - context.subscriptions.push(h2sa3_2); - - const h2sa4_1 = vscode.commands.registerCommand('extension.h2sa4-1', async (uri) => { + 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) { - // parse - let funDescList = await parseHeaderFile(uri.fsPath); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - // generator - let out = path.dirname(uri.fsPath); - let serviceName = path.basename(uri.fsPath, '.h'); - let rootInfo = { - serviceName: serviceName, - funcs: funDescList.funcs, - serviceId: '19000', - versionTag: '4.1' - }; - genServiceFile(rootInfo, out); + 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(); } // Display a message box to the user - vscode.window.showInformationMessage('h2sa4_1!'); + vscode.window.showInformationMessage('h2sa!'); }); - context.subscriptions.push(h2sa4_1); + context.subscriptions.push(h2sa); - const h2hdf4_1 = vscode.commands.registerCommand('extension.h2hdf4-1', async (uri) => { + 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) { - // analyze - let funDescList = await parseHeaderFile(uri.fsPath); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); + + let versionTag = '4.1'; + const quickPick = vscode.window.createQuickPick(); + quickPick.title = "h2hdf"; + quickPick.items = [ + { label: 'h2hdf4-1'} + ]; + quickPick.canSelectMany = false; - // generator - let out = path.dirname(uri.fsPath); - let driverName = path.basename(uri.fsPath, '.h').toLocaleLowerCase(); - let rootInfo = { - driverName: driverName, - funcs: funDescList.funcs, - versionTag: '4.1' - }; - genHdfFile(rootInfo, out); + 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(); } // Display a message box to the user - vscode.window.showInformationMessage('h2hdf4_1!'); + vscode.window.showInformationMessage('h2hdf!'); }); - - context.subscriptions.push(h2hdf4_1); + 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) { - // parse - let funDescList = await parseHeaderFile(uri.fsPath); - console.log('parse header file res: ', funDescList); - console.log('parse header file jsonstr: ', JSON.stringify(funDescList)); - let fileName = path.basename(uri.fsPath, '.h'); - let rootInfo: DtscppRootInfo = { - funcs: funDescList.funcs, - rawFilePath: uri.fsPath, // e://xxx.h - fileName: fileName // xxx - }; - // generator - let out = path.dirname(uri.fsPath); - genDtsFile(rootInfo, out); + 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." }); + }); } // Display a message box to the user vscode.window.showInformationMessage('h2dts!'); }); - context.subscriptions.push(h2dts); const h2dtscpp = vscode.commands.registerCommand('extension.h2dtscpp', async (uri) => { // The code you place here will be executed every time your command is executed if (uri && uri.fsPath) { - // let rawContent = fs.readFileSync(uri.fsPath); - // 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)); - 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); + 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." }); + }); } // Display a message box to the user vscode.window.showInformationMessage('h2dtscpp!'); }); - context.subscriptions.push(h2dtscpp); const dts2cpp = vscode.commands.registerCommand('extension.dts2cpp', (uri) => { @@ -179,6 +257,5 @@ export function activate(context: vscode.ExtensionContext) { // generator } }); - context.subscriptions.push(dts2cpp); }