From 8f846e2d62e8f12548ade2c01a19d4a14caac41f Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Thu, 6 Jul 2023 07:42:44 +0800 Subject: [PATCH] Refactor checkDevChatDependency function in commandsBase.ts - Imported path module for handling file paths. - Added pipxBinPath variable to store the pipx environment path. - Changed error logging level from error to warn. - Updated the way DevChat command is run and its path is updated. --- src/contributes/commandsBase.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/contributes/commandsBase.ts b/src/contributes/commandsBase.ts index f1b0d12..3dffe10 100644 --- a/src/contributes/commandsBase.ts +++ b/src/contributes/commandsBase.ts @@ -3,6 +3,7 @@ import { UiUtilWrapper } from "../util/uiUtil"; import { runCommand } from "../util/commonUtil"; import { logger } from "../util/logger"; +import path from "path"; let pipxPathStatus = ''; let devchatStatus = ''; @@ -23,8 +24,10 @@ function locateCommand(command): string | undefined { } export function checkDevChatDependency(pythonCommand: string): boolean { + let pipxBinPath: string | undefined = undefined; try { const binPath = getPipxEnvironmentPath(pythonCommand); + pipxBinPath = binPath; if (binPath) { updateEnvironmentPath(binPath); @@ -37,31 +40,32 @@ export function checkDevChatDependency(pythonCommand: string): boolean { } else { const error_status = `Failed to obtain the pipx environment path.`; if (pipxPathStatus !== error_status) { - logger.channel()?.error(error_status); + logger.channel()?.warn(error_status); logger.channel()?.show(); pipxPathStatus = error_status; } + + return false; } } catch (error) { // DevChat dependency check failed // log out detail error message const error_status = `Failed to check DevChat dependency due to error: ${error}`; if (pipxPathStatus !== error_status) { - logger.channel()?.error(error_status); + logger.channel()?.warn(error_status); logger.channel()?.show(); pipxPathStatus = error_status; } + + return false; } try { // Check if DevChat is installed - runCommand('devchat --help'); - - const devchatCommand = locateCommand('devchat'); - if (devchatCommand) { - UiUtilWrapper.updateConfiguration('DevChat', 'DevChatPath', devchatCommand); - } + const pipxDevChat = path.join(pipxBinPath!, 'devchat'); + runCommand(`${pipxDevChat} --help`); + UiUtilWrapper.updateConfiguration('DevChat', 'DevChatPath', pipxDevChat); const error_status = `DevChat has installed.`; if (devchatStatus !== error_status) { logger.channel()?.info(error_status); @@ -72,7 +76,7 @@ export function checkDevChatDependency(pythonCommand: string): boolean { } catch(error) { const error_status = `Failed to check DevChat dependency due to error: ${error}`; if (devchatStatus !== error_status) { - logger.channel()?.error(error_status); + logger.channel()?.warn(error_status); logger.channel()?.show(); devchatStatus = error_status; }