From fd011ee2656fb2b08191ab0d2ba66ace4797fc2f Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 21 Aug 2023 11:52:00 +0800 Subject: [PATCH] Added AskCode functionality to DevChat - Added new settings for Python virtual environment and supported file types in package.json. - Added new commands for starting and stopping AskCode Index in package.json. - Registered new 'ask-code' command in CommandManager. - Registered AskCode Index start and stop commands in extension.ts. - Added 'askCode' handler in loadHandlers.ts and messageHandler.ts. - Updated messageHandler to check for '/ask-code' in message text and call 'askCode' command. --- package.json | 20 ++++++++++++++++++++ src/command/commandManager.ts | 9 +++++++++ src/extension.ts | 4 ++++ src/handler/loadHandlers.ts | 4 +++- src/handler/messageHandler.ts | 5 +++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2abd3b9..709ef13 100644 --- a/package.json +++ b/package.json @@ -155,6 +155,16 @@ "default": false, "description": "Enable/Disable function calling for GPT.", "when": "DevChat.llmModel == 'OpenAI'" + }, + "DevChat.PythonVirtualEnv": { + "type": "string", + "default": "", + "description": "Path to the Python virtual environment for AskCode." + }, + "DevChat.askcode.supportedFileTypes": { + "type": "string", + "default": ".+\\.js$, .+\\.ts$, .+\\.jsx$, .+\\.tsx$, .+\\.java$, .+\\.py$, .+\\.go$, .+\\.rb$, .+\\.php$, .+\\.cpp$, .+\\.c$, .+\\.cs$, .+\\.swift$, .+\\.rs$, .+\\.sh$, .+\\.bash$, .+\\.zsh$, .+\\.m$, .+\\.mm$, .+\\.h$, .+\\.hpp$, .+\\.hh$, .+\\.html$, .+\\.htm$, .+\\.xhtml$, .+\\.xml$, .+\\.css$, .+\\.scss$, .+\\.sass$, .+\\.less$, .+\\.json$, .+\\.yaml$, .+\\.yml$, .+\\.toml$, .+\\.ini$, .+\\.md$, .+\\.markdown$, .+\\.txt$, .+\\.csv$, .+\\.sql$, .+\\.sqlite$, .+\\.db$, .+\\.hql$, .+\\.psql$, .+\\.pgsql$, .+\\.plpgsql$", + "description": "Comma-separated list of regular expressions for supported file types for analysis." } } }, @@ -257,6 +267,16 @@ { "command": "devchat.askForFile_chinese", "title": "添加到DevChat" + }, + { + "command": "DevChat.AskCodeIndexStart", + "title": "Start AskCode Index", + "category": "DevChat" + }, + { + "command": "DevChat.AskCodeIndexStop", + "title": "Stop AskCode Index", + "category": "DevChat" } ], "menus": { diff --git a/src/command/commandManager.ts b/src/command/commandManager.ts index 0a892f1..54c4fa9 100644 --- a/src/command/commandManager.ts +++ b/src/command/commandManager.ts @@ -17,6 +17,15 @@ class CommandManager { public static getInstance(): CommandManager { if (!CommandManager.instance) { CommandManager.instance = new CommandManager(); + CommandManager.instance.registerCommand({ + name: 'ask-code', + pattern: 'ask-code', + description: 'ask code', + args: 0, + handler: async (commandName: string, userInput: string) => { + return; + } + }); } return CommandManager.instance; diff --git a/src/extension.ts b/src/extension.ts index b1a4eb6..70cad2d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -15,6 +15,8 @@ import { regApplyDiffResultCommand, registerStatusBarItemClickCommand, regPythonPathCommand, + registerAskCodeIndexStartCommand, + registerAskCodeIndexStopCommand, } from './contributes/commands'; import { regLanguageContext } from './contributes/context'; import { regDevChatView, regTopicView } from './contributes/views'; @@ -56,5 +58,7 @@ function activate(context: vscode.ExtensionContext) { regApplyDiffResultCommand(context); regPythonPathCommand(context); + registerAskCodeIndexStartCommand(context); + registerAskCodeIndexStopCommand(context); } exports.activate = activate; diff --git a/src/handler/loadHandlers.ts b/src/handler/loadHandlers.ts index 8e91075..982e634 100644 --- a/src/handler/loadHandlers.ts +++ b/src/handler/loadHandlers.ts @@ -6,7 +6,7 @@ import { doCommit } from './doCommit'; import { historyMessages } from './historyMessages'; import { regCommandList } from './regCommandList'; import { regContextList } from './regContextList'; -import { sendMessage, stopDevChat, regeneration, deleteChatMessage } from './sendMessage'; +import { sendMessage, stopDevChat, regeneration, deleteChatMessage, askCode } from './sendMessage'; import { blockApply } from './showDiff'; import { showDiff } from './showDiff'; import { addConext } from './addContext'; @@ -76,3 +76,5 @@ messageHandler.registerHandler('applyAction', applyAction); // Delete chat message // Response: { command: 'deletedChatMessage', result: } messageHandler.registerHandler('deleteChatMessage', deleteChatMessage); + +messageHandler.registerHandler('askCode', askCode); diff --git a/src/handler/messageHandler.ts b/src/handler/messageHandler.ts index aafb298..0502cd5 100644 --- a/src/handler/messageHandler.ts +++ b/src/handler/messageHandler.ts @@ -52,6 +52,11 @@ export class MessageHandler { if (message.text.indexOf('/autox') !== -1) { autox = true; } + // if "/ask-code" in message.text, then call devchat-ask to get result + if (message.text.indexOf('/ask-code') !== -1) { + message.command = 'askCode'; + message.text = message.text.replace('/ask-code', ''); + } } const handler = this.handlers[message.command];