check dependence only once

This commit is contained in:
bobo.yang 2023-05-11 10:27:54 +08:00
parent 93714a2255
commit eca629b4f3
2 changed files with 29 additions and 24 deletions

View File

@ -32,22 +32,24 @@ function checkOpenAIKey() {
return true;
}
function checkDependencyPackage() {
const dependencyInstalled = checkDependency();
if (!dependencyInstalled) {
// 依赖程序未安装,显示提示信息
logger.channel()?.error('devchat package is not installed.');
logger.channel()?.info('Please install devchat package first. Use command: pip install devchat');
logger.channel()?.show();
vscode.window.showErrorMessage('devchat package is not installed.');
return;
}
if (!checkOpenAIKey()) {
return;
}
}
function registerOpenChatPanelCommand(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('devchat.openChatPanel', () => {
const dependencyInstalled = checkDependency();
if (!dependencyInstalled) {
// 依赖程序未安装,显示提示信息
logger.channel()?.error('devchat package is not installed.');
logger.channel()?.info('Please install devchat package first. Use command: pip install devchat');
logger.channel()?.show();
vscode.window.showErrorMessage('devchat package is not installed.');
return;
}
if (!checkOpenAIKey()) {
return;
}
if (vscode.workspace.workspaceFolders) {
ChatPanel.createOrShow(context.extensionUri);
} else {
@ -110,6 +112,7 @@ function registerAskForFileCommand(context: vscode.ExtensionContext) {
}
export {
checkDependencyPackage,
registerOpenChatPanelCommand,
registerAddContextCommand,
registerAskForCodeCommand,

View File

@ -2,10 +2,11 @@ import * as vscode from 'vscode';
import {
registerOpenChatPanelCommand,
registerAddContextCommand,
registerAskForCodeCommand,
registerAskForFileCommand,
checkDependencyPackage,
registerOpenChatPanelCommand,
registerAddContextCommand,
registerAskForCodeCommand,
registerAskForFileCommand,
} from './contributes/commands';
import ExtensionContextHolder from './util/extensionContext';
@ -13,12 +14,13 @@ import { logger } from './util/logger';
function activate(context: vscode.ExtensionContext) {
ExtensionContextHolder.context = context;
logger.init(context);
ExtensionContextHolder.context = context;
logger.init(context);
registerOpenChatPanelCommand(context);
registerAddContextCommand(context);
registerAskForCodeCommand(context);
registerAskForFileCommand(context);
checkDependencyPackage();
registerOpenChatPanelCommand(context);
registerAddContextCommand(context);
registerAskForCodeCommand(context);
registerAskForFileCommand(context);
}
exports.activate = activate;