From b6cdc1cc94389b9548946c20fbed7b2c6a3d4d77 Mon Sep 17 00:00:00 2001 From: guoyanwen Date: Wed, 1 Jun 2022 17:55:22 +0800 Subject: [PATCH] add vscode Signed-off-by: guoyanwen --- src/extension.js | 81 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/src/extension.js b/src/extension.js index 78f98f54..0e4dec7f 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 } + -- Gitee