From 97b938b47bf1e0ed2d005fedbcd980b81b726683 Mon Sep 17 00:00:00 2001 From: Hanchin Hsieh Date: Wed, 19 Feb 2025 13:50:24 +0800 Subject: [PATCH] feat(sidebar): add "commit" command (#1304) - Extend AvanteSlashCommandType to include "commit" - Add new command entry for "commit" with description "Commit the changes" - Implement callback function for "commit" command - Update input container logic to handle "commit" command - Set request to "Please commit the changes" when "commit" command is used Hanchin Hsieh --- lua/avante/sidebar.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index 078d20f..dbc5903 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -1969,7 +1969,7 @@ function Sidebar:reset_memory(args, cb) end end ----@alias AvanteSlashCommandType "clear" | "help" | "lines" | "reset" +---@alias AvanteSlashCommandType "clear" | "help" | "lines" | "reset" | "commit" ---@alias AvanteSlashCommandCallback fun(args: string, cb?: fun(args: string): nil): nil ---@alias AvanteSlashCommand {description: string, command: AvanteSlashCommandType, details: string, shorthelp?: string, callback?: AvanteSlashCommandCallback} ---@return AvanteSlashCommand[] @@ -1994,6 +1994,7 @@ function Sidebar:get_commands() description = "/lines - ", command = "lines", }, + { description = "Commit the changes", command = "commit" }, } ---@type {[AvanteSlashCommandType]: AvanteSlashCommandCallback} @@ -2008,6 +2009,10 @@ function Sidebar:get_commands() lines = function(args, cb) if cb then cb(args) end end, + commit = function(_, cb) + local question = "Please commit the changes" + if cb then cb(question) end + end, } return vim @@ -2219,6 +2224,8 @@ function Sidebar:create_input_container(opts) local _, _, question = args_:match("(%d+)-(%d+)%s+(.*)") request = question end) + elseif command == "commit" then + cmd.callback(args, function(question) request = question end) else cmd.callback(args) return