diff --git a/src/extension.js b/src/extension.js index 78f98f548408dbcafc778a43438b56a25260e78c..0e4dec7fce43b682c744192e95339eda496e814d 100644 --- a/src/extension.js +++ b/src/extension.js @@ -31,6 +31,20 @@ function activate(context) { // Use the console to output diagnostic information (console.log) and errors (console.error) // This line of code will only be executed once when your extension is activated console.log('Congratulations, your extension "gnapi" is now active!'); + const panel = vscode.window.createWebviewPanel( + 'generate', // 标识webview的类型 + 'Generate Napi Frame', // 展示给用户的面板的标题 + vscode.ViewColumn.One, // 显示webview面板以编辑器新列的方式. + { + enableScripts: true, // 启用JS,默认禁用 + retainContextWhenHidden: true, // webview被隐藏时保持状态,避免被重置 + } + ); + panel.webview.html = getWebviewContent(); + panel.webview.onDidReceiveMessage(message => { + vscode.window.showInformationMessage('插件收到的消息:' + message); + }, undefined, context.subscriptions); + let disposable = vscode.commands.registerCommand('generate_napi', function (uri) { // The code you place here will be executed every time your command is executed @@ -40,13 +54,13 @@ function activate(context) { vscode.window.showInformationMessage("正在生成" + uri.fsPath); NapiLog.init(1, path.join("" + path.dirname(uri.fsPath), "napi_gen.log")) xgen.doGenerate(uri.fsPath, path.dirname(uri.fsPath)); - let ret=NapiLog.getResult(); - if(ret[0]) { - vscode.window.showInformationMessage("生成成功"); - } - else { - vscode.window.showInformationMessage(""+ret[1]); - } + let ret = NapiLog.getResult(); + if (ret[0]) { + vscode.window.showInformationMessage("生成成功"); + } + else { + vscode.window.showInformationMessage("" + ret[1]); + } } else { vscode.window.showErrorMessage("" + result[1]); @@ -59,7 +73,60 @@ function activate(context) { // this method is called when your extension is deactivated function deactivate() { } +function getWebviewContent() { + return ` + + + + + + + Napi + +
+ 选择方式: + .d.ts文件 + 文件夹 +
+
+
+ 选择接口文件: + + +
+ +
+ 生成框架路径: + +
+ +
+ 编译脚本路径: + +
+
+ + + + + +
+ + ` +} + module.exports = { activate, deactivate } +