From cab4cfab9f72cd5ebd5e12d9f97f6dad2c2404fd Mon Sep 17 00:00:00 2001 From: Quang Tran Minh Date: Sat, 21 Jun 2025 05:28:05 +0700 Subject: [PATCH] Improve custom command handling with deduplication - Add command deduplication using Map to prevent duplicate commands - Project commands now take precedence over user commands - Remove redundant prefixes (project:/user:) for cleaner command names - Add descriptive icons to distinguish command sources - Fix newline at end of file --- src/service/customCommandService.ts | 34 +++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/service/customCommandService.ts b/src/service/customCommandService.ts index 82e5119..925d449 100644 --- a/src/service/customCommandService.ts +++ b/src/service/customCommandService.ts @@ -38,28 +38,34 @@ export class CustomCommandService { */ public getCustomCommands(): SlashCommand[] { const commands: SlashCommand[] = []; + const commandMap = new Map(); - // Add project commands + // Add project commands first (they take precedence) for (const cmd of this.projectCommands) { - commands.push({ - command: `/project:${cmd.name}`, - description: cmd.description || `Project command: ${cmd.name}`, + const command = { + command: `/${cmd.name}`, + description: `📄 ${cmd.description || cmd.name}`, icon: '📄', // Document icon for project commands isCustom: true - }); + }; + commandMap.set(cmd.name, command); } - // Add user commands + // Add user commands only if no project command with the same name exists for (const cmd of this.userCommands) { - commands.push({ - command: `/user:${cmd.name}`, - description: cmd.description || `User command: ${cmd.name}`, - icon: '👤', // User icon for user commands - isCustom: true - }); + if (!commandMap.has(cmd.name)) { + const command = { + command: `/${cmd.name}`, + description: `👤 ${cmd.description || cmd.name}`, + icon: '👤', // User icon for user commands + isCustom: true + }; + commandMap.set(cmd.name, command); + } } - return commands; + // Convert map to array + return Array.from(commandMap.values()); } /** @@ -185,4 +191,4 @@ export class CustomCommandService { } // Create a singleton instance -export const customCommandService = new CustomCommandService(); \ No newline at end of file +export const customCommandService = new CustomCommandService();