2019-12-26 17:47:37 +08:00
|
|
|
/*
|
|
|
|
* Author : OBKoro1
|
|
|
|
* Date : 2019-12-25 17:13:30
|
|
|
|
* LastEditors : OBKoro1
|
2020-01-08 14:08:09 +08:00
|
|
|
* LastEditTime : 2020-01-08 09:59:48
|
2019-12-26 17:47:37 +08:00
|
|
|
* FilePath : /autoCommit/src/util/vscodeUtil.ts
|
|
|
|
* Description : vscode 相关的公共方法
|
|
|
|
* https://github.com/OBKoro1
|
|
|
|
*/
|
2019-12-30 21:13:08 +08:00
|
|
|
import * as vscode from 'vscode';
|
2019-12-26 17:47:37 +08:00
|
|
|
|
2020-01-08 14:08:09 +08:00
|
|
|
let extensionContext: vscode.ExtensionContext;
|
2019-12-30 21:13:08 +08:00
|
|
|
let webview: any;
|
2019-12-26 17:47:37 +08:00
|
|
|
|
|
|
|
// 存储插件上下午文
|
|
|
|
function setExtensionContext(context: any) {
|
2019-12-30 21:13:08 +08:00
|
|
|
extensionContext = context;
|
2019-12-26 17:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 获取插件上下文
|
2020-01-08 14:08:09 +08:00
|
|
|
function getExtensionContext(): vscode.ExtensionContext {
|
2019-12-30 21:13:08 +08:00
|
|
|
return extensionContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 存储webview
|
|
|
|
function setPanelWebview(webviewClass: any) {
|
|
|
|
webview = webviewClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取webview
|
|
|
|
function getPanelWebview() {
|
|
|
|
return webview;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 输出日志
|
|
|
|
function outputLog(...arr: any) {
|
|
|
|
console.log('日志', ...arr);
|
|
|
|
webview.postMessage('console-log', arr);
|
2019-12-26 17:47:37 +08:00
|
|
|
}
|
|
|
|
|
2019-12-31 18:01:35 +08:00
|
|
|
// 是否生产环境
|
|
|
|
function isProduction() {
|
2020-01-08 14:08:09 +08:00
|
|
|
return process.env.NODE_ENV === 'production'; // production时 为打包安装版本
|
2019-12-31 18:01:35 +08:00
|
|
|
}
|
|
|
|
|
2019-12-26 17:47:37 +08:00
|
|
|
// vscode 消息通知
|
|
|
|
function showMessage(message: string, type = 'error') {
|
2019-12-30 21:13:08 +08:00
|
|
|
const actions: any = {
|
|
|
|
info: () => {
|
|
|
|
vscode.window.showInformationMessage(message);
|
|
|
|
},
|
|
|
|
alert: () => {
|
|
|
|
vscode.window.showWarningMessage(message);
|
|
|
|
},
|
|
|
|
error: () => {
|
|
|
|
vscode.window.showErrorMessage(message);
|
2020-12-10 20:02:10 +08:00
|
|
|
},
|
2019-12-30 21:13:08 +08:00
|
|
|
};
|
2019-12-26 17:47:37 +08:00
|
|
|
|
2019-12-30 21:13:08 +08:00
|
|
|
actions[type]();
|
|
|
|
}
|
2019-12-26 17:47:37 +08:00
|
|
|
|
|
|
|
export {
|
2019-12-31 18:01:35 +08:00
|
|
|
isProduction, // 是否生产环境
|
2019-12-30 21:13:08 +08:00
|
|
|
outputLog, // 打印日志
|
|
|
|
getPanelWebview, // 获取webview
|
|
|
|
setPanelWebview, // 存储webview
|
|
|
|
showMessage, // vscode 消息通知
|
|
|
|
setExtensionContext, // 存储插件上下文
|
2020-12-10 20:02:10 +08:00
|
|
|
getExtensionContext, // 获取插件上下文
|
2019-12-30 21:13:08 +08:00
|
|
|
};
|