From 32f078bac2a548d6839c0ee2b700855b627a0a53 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 2 Dec 2024 14:38:39 +0800 Subject: [PATCH 1/5] style: Add semicolons and improve code formatting - Add missing semicolons to all statements in prebuild.js - Adjust indentation and spacing for consistency - Remove trailing whitespace at end of file --- prebuild.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/prebuild.js b/prebuild.js index 8dbff20..0c3fd26 100644 --- a/prebuild.js +++ b/prebuild.js @@ -1,26 +1,26 @@ -require('dotenv').config() +require('dotenv').config(); -const fs = require('fs') -const path = require('path') +const fs = require('fs'); +const path = require('path'); function copyIcon(src, dst) { if (!src) { - console.warn(`Icon path for ${dst} is not defined in your environment variables`) - return + console.warn(`Icon path for ${dst} is not defined in your environment variables`); + return; } - console.log(`Replacing icon ${dst} by ${src}`) + console.log(`Replacing icon ${dst} by ${src}`); if (!fs.existsSync(src)) { - console.warn(`Icon file ${src} does not exist.`) - return + console.warn(`Icon file ${src} does not exist.`); + return; } - const destPath = path.join(__dirname, 'assets', dst) + const destPath = path.join(__dirname, 'assets', dst); try { - fs.copyFileSync(src, destPath) - fs.chmodSync(destPath, 0o644) + fs.copyFileSync(src, destPath); + fs.chmodSync(destPath, 0o644); } catch(e) { - console.warn(`Failed to copy logo ${e}`) + console.warn(`Failed to copy logo ${e}`); } } @@ -31,7 +31,7 @@ function updatePackageJson() { ASSISTANT_NAME_EN: process.env.ASSISTANT_NAME_EN || "DevChat", ASSISTANT_NAME_ZH: process.env.ASSISTANT_NAME_ZH || "DevChat" } - console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`) + console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`); let packageJson = fs.readFileSync('package.json', 'utf8'); @@ -44,8 +44,8 @@ function updatePackageJson() { fs.writeFileSync('package.json', packageJson); } -copyIcon(process.env.EXTENSION_ICON, 'devchat.png') -copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg') -copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg') +copyIcon(process.env.EXTENSION_ICON, 'devchat.png'); +copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg'); +copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg'); -updatePackageJson() \ No newline at end of file +updatePackageJson(); \ No newline at end of file From c25ef505b024223d059a9453b503757f7e0a6bf2 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 2 Dec 2024 14:39:13 +0800 Subject: [PATCH 2/5] feat: Improve file path handling in contextCodeSelected - Add fallback for relative path calculation - Handle cases where workspaceDir is undefined - Ensure fileSelected is used when no workspace folder exists --- src/context/contextCodeSelected.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/context/contextCodeSelected.ts b/src/context/contextCodeSelected.ts index 0f5d435..3d390ed 100644 --- a/src/context/contextCodeSelected.ts +++ b/src/context/contextCodeSelected.ts @@ -16,7 +16,9 @@ export async function handleCodeSelected(fileSelected: string, codeSelected: str // get relative path of workspace const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath(); - const relativePath = path.relative(workspaceDir!, fileSelected); + const relativePath = workspaceDir + ? path.relative(workspaceDir, fileSelected) + : fileSelected; // convert fileContent to markdown code block with languageId and file path const data = { From 54b49389c536ac980c2004c1250664b0c93e92c0 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 2 Dec 2024 14:39:50 +0800 Subject: [PATCH 3/5] feat: Improve file path handling in contextFileSelected - Add fallback for relative path calculation - Handle cases where workspaceDir is undefined - Ensure fileSelected is always used as a fallback --- src/context/contextFileSelected.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/context/contextFileSelected.ts b/src/context/contextFileSelected.ts index 94c1a8f..d7f09a8 100644 --- a/src/context/contextFileSelected.ts +++ b/src/context/contextFileSelected.ts @@ -19,7 +19,9 @@ export async function handleFileSelected(fileSelected: string) { // get relative path of workspace const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath(); - const relativePath = path.relative(workspaceDir!, fileSelected); + const relativePath = workspaceDir + ? path.relative(workspaceDir, fileSelected) + : fileSelected; // convert fileContent to markdown code block with languageId and file path const data = { From fd7c2edbbcd20288647e574e0fa731c58e7e13ca Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 2 Dec 2024 14:40:19 +0800 Subject: [PATCH 4/5] refactor: Optimize workflow update and command list process - Introduce copiedDirectory flag to track directory creation - Restructure conditional logic for better flow control - Improve error handling and logging for directory operations --- src/contributes/commands.ts | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index 4319715..2dc2085 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -216,31 +216,38 @@ export function registerInstallCommandsCommand( const currentVersion = UiUtilWrapper.extensionPath(); const previousVersion = devchatConfig.get("last_devchat_version", ""); + let copiedDirectory = false; if (!fs.existsSync(sysMericoDirPath) || (updatePublicWorkflow === false && currentVersion !== previousVersion)) { logger.channel()?.debug("Creating directory: " + sysMericoDirPath); await copyDirectory(pluginDirPath, sysDirPath); + copiedDirectory = true; } devchatConfig.set("last_devchat_version", currentVersion); - // Check if ~/.chat/scripts directory exists - if (!fs.existsSync(sysMericoDirPath)) { - // Directory does not exist, wait for updateWorkflows to finish - logger.channel()?.debug("Update workflows..."); - await dcClient.updateWorkflows(); - await dcClient.updateCustomWorkflows(); + if (copiedDirectory) { + logger.channel()?.debug("Directory copied successfully."); sendCommandListByDevChatRun(); } else { - // Directory exists, execute sendCommandListByDevChatRun immediately - logger.channel()?.debug("Sending and updating workflows..."); - await sendCommandListByDevChatRun(); + // Check if ~/.chat/scripts directory exists + if (!fs.existsSync(sysMericoDirPath)) { + // Directory does not exist, wait for updateWorkflows to finish + logger.channel()?.debug("Update workflows..."); + await dcClient.updateWorkflows(); + await dcClient.updateCustomWorkflows(); + sendCommandListByDevChatRun(); + } else { + // Directory exists, execute sendCommandListByDevChatRun immediately + logger.channel()?.debug("Sending and updating workflows..."); + await sendCommandListByDevChatRun(); - // Then asynchronously execute updateWorkflows - await dcClient.updateWorkflows(); - await dcClient.updateCustomWorkflows(); - - await sendCommandListByDevChatRun(); + // Then asynchronously execute updateWorkflows + await dcClient.updateWorkflows(); + await dcClient.updateCustomWorkflows(); + + await sendCommandListByDevChatRun(); + } } - + // Ensure the panel is activated await ensureChatPanel(context); } From 825e8c7b537aa075dacfb5a40bbe8e9e68716af4 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 2 Dec 2024 14:40:40 +0800 Subject: [PATCH 5/5] update submodules --- gui | 2 +- workflowsCommands | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui b/gui index 66c9115..c883677 160000 --- a/gui +++ b/gui @@ -1 +1 @@ -Subproject commit 66c9115f69ad90eea993cee16dcf93e280673201 +Subproject commit c8836777f0d09ce1328166abec5cebc480a2590a diff --git a/workflowsCommands b/workflowsCommands index ed9898d..f4a4dbc 160000 --- a/workflowsCommands +++ b/workflowsCommands @@ -1 +1 @@ -Subproject commit ed9898d038e09732bbcaba0ef655efc1f89ef9a8 +Subproject commit f4a4dbc529e4fc80f67a0492674854c6fb8a29d3