From c5f91f63f139b2ead5987e700a590ac9d6ce8ec7 Mon Sep 17 00:00:00 2001 From: m3tam3re Date: Mon, 14 Oct 2024 13:39:31 +0200 Subject: [PATCH] companion config --- nvim/init.lua | 79 ++++-- nvim/lua/custom/plugins/chatgpt.lua | 384 ++++++++++++++-------------- 2 files changed, 245 insertions(+), 218 deletions(-) diff --git a/nvim/init.lua b/nvim/init.lua index 791e605..ae7845a 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -282,22 +282,22 @@ require('lazy').setup({ require('which-key').setup() -- Document existing key chains - require('which-key').register + require('which-key').add { - { "c", group = "[C]ode" }, - { "c_", hidden = true }, - { "d", group = "[D]ocument" }, - { "d_", hidden = true }, - { "l", group = "[L]LM assistants" }, - { "l_", hidden = true }, - { "r", group = "[R]ename" }, - { "r_", hidden = true }, - { "s", group = "[S]earch" }, - { "s_", hidden = true }, - { "t", group = "[T]oggle" }, - { "t_", hidden = true }, - { "w", group = "[W]orkspace" }, - { "w_", hidden = true }, + { "", group = "[C]ode" }, + { "", group = "[S]earch" }, + { "", desc = "r_", hidden = true }, + { "", desc = "s_", hidden = true }, + { "", desc = "t_", hidden = true }, + { "", group = "[T]oggle" }, + { "", group = "[W]orkspace" }, + { "", group = "[R]ename" }, + { "", group = "[L]LM assistants" }, + { "", desc = "c_", hidden = true }, + { "", desc = "l_", hidden = true }, + { "", group = "[D]ocument" }, + { "", desc = "d_", hidden = true }, + { "", desc = "w_", hidden = true }, } end, }, @@ -852,19 +852,44 @@ require('lazy').setup({ -- setting the keybinding for LazyGit with 'keys' is recommended in -- order to load the plugin when the command is run for the first time keys = { - vim.keymap.set('n', 'lg', 'LazyGit', { desc = 'LazyGit' }) + vim.keymap.set('n', 'g', 'LazyGit', { desc = 'LazyGit' }) } - }, { - "olimorris/codecompanion.nvim", - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-treesitter/nvim-treesitter", - "hrsh7th/nvim-cmp", -- Optional: For using slash commands and variables in the chat buffer - "nvim-telescope/telescope.nvim", -- Optional: For using slash commands - { "stevearc/dressing.nvim", opts = {} }, -- Optional: Improves `vim.ui.select` }, - config = true -}, + { + "olimorris/codecompanion.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "hrsh7th/nvim-cmp", -- Optional: For using slash commands and variables in the chat buffer + "nvim-telescope/telescope.nvim", -- Optional: For using slash commands + { "stevearc/dressing.nvim", opts = {} }, -- Optional: Improves `vim.ui.select` + }, + config = function() + vim.keymap.set('n', 'lc', vim.cmd.CodeCompanion, { desc = '[C]ode Companion' }) + vim.keymap.set('n', 'lca', 'CodeCompanionActions', { desc = 'ChatGPT [D]ocstring' }) + vim.keymap.set('v', 'lca', 'CodeCompanionActions', { desc = 'ChatGPT [D]ocstring' }) + vim.keymap.set('n', 'lct', 'CodeCompanionChat Toggle', + { desc = 'ChatGPT [T]oggle Companion Chat' }) + vim.keymap.set('v', 'lct', 'CodeCompanionChat Toggle', + { desc = 'ChatGPT [T]oggle Companion Chat' }) + vim.keymap.set('n', 'lca', 'CodeCompanionChat Add', { desc = '[A]dd Companion Chat' }) + + require("codecompanion").setup({ + strategies = { + chat = { + adapter = "anthropic", + }, + inline = { + adapter = "anthropic", + }, + agent = { + adapter = "anthropic", + }, + }, + + }) + end, + }, { 'folke/noice.nvim', event = 'VeryLazy', @@ -905,7 +930,7 @@ require('lazy').setup({ }, }, - require('which-key').register { + require('which-key').add { { "", desc = "n_", hidden = true }, { "", group = "[N]oice" }, }, diff --git a/nvim/lua/custom/plugins/chatgpt.lua b/nvim/lua/custom/plugins/chatgpt.lua index 067a77e..001fdb0 100644 --- a/nvim/lua/custom/plugins/chatgpt.lua +++ b/nvim/lua/custom/plugins/chatgpt.lua @@ -1,196 +1,198 @@ -- File: lua/custom/plugins/chatgpt.lua return { - 'jackMort/ChatGPT.nvim', - event = 'VeryLazy', - config = function() - vim.keymap.set('n', 'lc', vim.cmd.ChatGPT, { desc = '[C]hatGPT' }) - vim.keymap.set('n', 'lca', vim.cmd.ChatGPTActAs, { desc = 'ChatGPT [A]ct As' }) - vim.keymap.set('n', 'lcc', vim.cmd.ChatGPTCompleteCode, { desc = 'ChatGPT [C]omplete Code' }) - vim.keymap.set('n', 'lce', vim.cmd.ChatGPTEditWithInstructions, { desc = 'ChatGPT [E]dit With Instructions' }) - vim.keymap.set('v', 'lce', vim.cmd.ChatGPTEditWithInstructions, { desc = 'ChatGPT [E]dit With Instructions' }) - vim.keymap.set('n', 'lcd', 'ChatGPTRun docstring', { desc = 'ChatGPT [D]ocstring' }) - vim.keymap.set('n', 'lco', 'ChatGPTRun optimize_code', { desc = 'ChatGPT [o]ptimize code' }) - vim.keymap.set('n', 'lce', 'ChatGPTRun explain_code', { desc = 'ChatGPT [e]xplain code' }) - vim.keymap.set('n', 'lcs', 'ChatGPTRun summarize', { desc = 'ChatGPT [s]ummarize' }) - vim.keymap.set('n', 'lct', 'ChatGPTRun translate', { desc = 'ChatGPT [t]ranslate' }) - require('chatgpt').setup { - yank_register = '+', - edit_with_instructions = { - diff = false, - keymaps = { - close = '', - accept = '', - toggle_diff = '', - toggle_settings = '', - toggle_help = '', - cycle_windows = '', - use_output_as_input = '', - }, - }, - chat = { - welcome_message = 'Welcome Human!', - loading_text = 'Loading, please wait ...', - question_sign = '', -- 🙂 - answer_sign = 'ﮧ', -- 🤖 - border_left_sign = '', - border_right_sign = '', - max_line_length = 120, - sessions_window = { - active_sign = '  ', - inactive_sign = '  ', - current_line_sign = '', - border = { - style = 'rounded', - text = { - top = ' Sessions ', + 'jackMort/ChatGPT.nvim', + event = 'VeryLazy', + config = function() + vim.keymap.set('n', 'lg', vim.cmd.ChatGPT, { desc = 'Chat[G]PT' }) + vim.keymap.set('n', 'lga', vim.cmd.ChatGPTActAs, { desc = 'ChatGPT [A]ct As' }) + vim.keymap.set('n', 'lgc', vim.cmd.ChatGPTCompleteCode, { desc = 'ChatGPT [C]omplete Code' }) + vim.keymap.set('n', 'lge', vim.cmd.ChatGPTEditWithInstructions, + { desc = 'ChatGPT [E]dit With Instructions' }) + vim.keymap.set('v', 'lge', vim.cmd.ChatGPTEditWithInstructions, + { desc = 'ChatGPT [E]dit With Instructions' }) + vim.keymap.set('n', 'lgd', 'ChatGPTRun docstring', { desc = 'ChatGPT [D]ocstring' }) + vim.keymap.set('n', 'lgo', 'ChatGPTRun optimize_code', { desc = 'ChatGPT [o]ptimize code' }) + vim.keymap.set('n', 'lge', 'ChatGPTRun explain_code', { desc = 'ChatGPT [e]xplain code' }) + vim.keymap.set('n', 'lgs', 'ChatGPTRun summarize', { desc = 'ChatGPT [s]ummarize' }) + vim.keymap.set('n', 'lgt', 'ChatGPTRun translate', { desc = 'ChatGPT [t]ranslate' }) + require('chatgpt').setup { + yank_register = '+', + edit_with_instructions = { + diff = false, + keymaps = { + close = '', + accept = '', + toggle_diff = '', + toggle_settings = '', + toggle_help = '', + cycle_windows = '', + use_output_as_input = '', + }, }, - }, - win_options = { - winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', - }, - }, - keymaps = { - close = '', - yank_last = '', - yank_last_code = '', - scroll_up = '', - scroll_down = '', - new_session = '', - cycle_windows = '', - cycle_modes = '', - next_message = '', - prev_message = '', - select_session = '', - rename_session = 'r', - delete_session = 'd', - draft_message = '', - edit_message = 'e', - delete_message = 'd', - toggle_settings = '', - toggle_sessions = '', - toggle_help = '', - toggle_message_role = '', - toggle_system_role_open = '', - stop_generating = '', - }, - }, - popup_layout = { - default = 'center', - center = { - width = '80%', - height = '80%', - }, - right = { - width = '30%', - width_settings_open = '50%', - }, - }, - popup_window = { - border = { - highlight = 'FloatBorder', - style = 'rounded', - text = { - top = ' ChatGPT ', - }, - }, - win_options = { - wrap = true, - linebreak = true, - foldcolumn = '1', - winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', - }, - buf_options = { - filetype = 'markdown', - }, - }, - system_window = { - border = { - highlight = 'FloatBorder', - style = 'rounded', - text = { - top = ' SYSTEM ', - }, - }, - win_options = { - wrap = true, - linebreak = true, - foldcolumn = '2', - winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', - }, - }, - popup_input = { - prompt = '  ', - border = { - highlight = 'FloatBorder', - style = 'rounded', - text = { - top_align = 'center', - top = ' Prompt ', - }, - }, - win_options = { - winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', - }, - submit = '', - submit_n = '', - max_visible_lines = 20, - }, - settings_window = { - setting_sign = '  ', - border = { - style = 'rounded', - text = { - top = ' Settings ', - }, - }, - win_options = { - winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', - }, - }, - help_window = { - setting_sign = '  ', - border = { - style = 'rounded', - text = { - top = ' Help ', - }, - }, - win_options = { - winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', - }, - }, - openai_params = { - model = 'gpt-3.5-turbo-0125', - frequency_penalty = 0, - presence_penalty = 0, - max_tokens = 1000, - temperature = 0, - top_p = 1, - n = 1, - }, - openai_edit_params = { - model = 'gpt-3.5-turbo-0125', - frequency_penalty = 0, - presence_penalty = 0, - temperature = 0, - top_p = 1, - n = 1, - }, - use_openai_functions_for_edits = false, - actions_paths = {}, - show_quickfixes_cmd = 'Trouble quickfix', - predefined_chat_gpt_prompts = 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv', - highlights = { - help_key = '@symbol', - help_description = '@comment', - }, - } - end, - dependencies = { - 'MunifTanjim/nui.nvim', - 'nvim-lua/plenary.nvim', - 'folke/trouble.nvim', - 'nvim-telescope/telescope.nvim', - }, + chat = { + welcome_message = 'Welcome Human!', + loading_text = 'Loading, please wait ...', + question_sign = '', -- 🙂 + answer_sign = 'ﮧ', -- 🤖 + border_left_sign = '', + border_right_sign = '', + max_line_length = 120, + sessions_window = { + active_sign = '  ', + inactive_sign = '  ', + current_line_sign = '', + border = { + style = 'rounded', + text = { + top = ' Sessions ', + }, + }, + win_options = { + winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', + }, + }, + keymaps = { + close = '', + yank_last = '', + yank_last_code = '', + scroll_up = '', + scroll_down = '', + new_session = '', + cycle_windows = '', + cycle_modes = '', + next_message = '', + prev_message = '', + select_session = '', + rename_session = 'r', + delete_session = 'd', + draft_message = '', + edit_message = 'e', + delete_message = 'd', + toggle_settings = '', + toggle_sessions = '', + toggle_help = '', + toggle_message_role = '', + toggle_system_role_open = '', + stop_generating = '', + }, + }, + popup_layout = { + default = 'center', + center = { + width = '80%', + height = '80%', + }, + right = { + width = '30%', + width_settings_open = '50%', + }, + }, + popup_window = { + border = { + highlight = 'FloatBorder', + style = 'rounded', + text = { + top = ' ChatGPT ', + }, + }, + win_options = { + wrap = true, + linebreak = true, + foldcolumn = '1', + winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', + }, + buf_options = { + filetype = 'markdown', + }, + }, + system_window = { + border = { + highlight = 'FloatBorder', + style = 'rounded', + text = { + top = ' SYSTEM ', + }, + }, + win_options = { + wrap = true, + linebreak = true, + foldcolumn = '2', + winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', + }, + }, + popup_input = { + prompt = '  ', + border = { + highlight = 'FloatBorder', + style = 'rounded', + text = { + top_align = 'center', + top = ' Prompt ', + }, + }, + win_options = { + winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', + }, + submit = '', + submit_n = '', + max_visible_lines = 20, + }, + settings_window = { + setting_sign = '  ', + border = { + style = 'rounded', + text = { + top = ' Settings ', + }, + }, + win_options = { + winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', + }, + }, + help_window = { + setting_sign = '  ', + border = { + style = 'rounded', + text = { + top = ' Help ', + }, + }, + win_options = { + winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', + }, + }, + openai_params = { + model = 'gpt-3.5-turbo-0125', + frequency_penalty = 0, + presence_penalty = 0, + max_tokens = 1000, + temperature = 0, + top_p = 1, + n = 1, + }, + openai_edit_params = { + model = 'gpt-3.5-turbo-0125', + frequency_penalty = 0, + presence_penalty = 0, + temperature = 0, + top_p = 1, + n = 1, + }, + use_openai_functions_for_edits = false, + actions_paths = {}, + show_quickfixes_cmd = 'Trouble quickfix', + predefined_chat_gpt_prompts = 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv', + highlights = { + help_key = '@symbol', + help_description = '@comment', + }, + } + end, + dependencies = { + 'MunifTanjim/nui.nvim', + 'nvim-lua/plenary.nvim', + 'folke/trouble.nvim', + 'nvim-telescope/telescope.nvim', + }, }