From f0a5765bbcb3e6d54dcc85c609659263d5286bb3 Mon Sep 17 00:00:00 2001 From: Ron B <35236981+ronb54@users.noreply.github.com> Date: Tue, 3 Dec 2024 09:31:11 -0800 Subject: [PATCH] copilot updates Signed-off-by: Ron B <35236981+ronb54@users.noreply.github.com> --- nvim/lua/plug-config/copilot.lua | 261 +++++--------------- nvim/lua/plug-config/which-key-mappings.lua | 24 +- 2 files changed, 84 insertions(+), 201 deletions(-) diff --git a/nvim/lua/plug-config/copilot.lua b/nvim/lua/plug-config/copilot.lua index 229926f..20b5ee2 100644 --- a/nvim/lua/plug-config/copilot.lua +++ b/nvim/lua/plug-config/copilot.lua @@ -1,212 +1,20 @@ --- require("copilot").setup({ --- panel = { --- enabled = true, --- auto_refresh = true, --- keymap = { --- jump_prev = "[[", --- jump_next = "]]", --- accept = "", --- refresh = "gr", --- open = "", --- }, --- layout = { --- position = "bottom", -- | top | left | right --- ratio = 0.4, --- }, --- }, --- suggestion = { --- enabled = true, --- auto_trigger = true, --- debounce = 75, --- keymap = { --- accept = "", --- accept_word = false, --- accept_line = false, --- next = "", --- prev = "", --- dismiss = "", --- }, --- }, --- filetypes = { --- yaml = false, --- markdown = false, --- help = false, --- gitcommit = false, --- gitrebase = false, --- hgcommit = false, --- svn = false, --- cvs = false, --- ["."] = false, --- }, --- copilot_node_command = "node", -- Node.js version must be > 16.x --- server_opts_overrides = {}, --- }) - --- local prompts = require("CopilotChat.prompts") --- local select = require("CopilotChat.select") --- require("CopilotChat").setup({ --- debug = false, -- Enable debug logging --- proxy = nil, -- [protocol://]host[:port] Use this proxy --- allow_insecure = false, -- Allow insecure server connections - --- system_prompt = prompts.COPILOT_INSTRUCTIONS, -- System prompt to use --- model = "gpt-4o", -- GPT model to use, 'gpt-3.5-turbo' or 'gpt-4' --- temperature = 0.1, -- GPT temperature - --- question_header = "## User ", -- Header to use for user questions --- answer_header = "## Copilot ", -- Header to use for AI answers --- error_header = "## Error ", -- Header to use for errors --- separator = "───", -- Separator to use in chat - --- show_folds = true, -- Shows folds for sections in chat --- show_help = true, -- Shows help message as virtual lines when waiting for user input --- auto_follow_cursor = true, -- Auto-follow cursor in chat --- auto_insert_mode = false, -- Automatically enter insert mode when opening window and if auto follow cursor is enabled on new prompt --- clear_chat_on_new_prompt = false, -- Clears chat on every new prompt --- highlight_selection = true, -- Highlight selection in the source buffer when in the chat window - --- context = nil, -- Default context to use, 'buffers', 'buffer' or none (can be specified manually in prompt via @). --- history_path = vim.fn.stdpath("data") .. "/copilotchat_history", -- Default path to stored history --- callback = nil, -- Callback to use when ask response is received - --- -- default selection (visual or line) --- selection = function(source) --- return select.visual(source) or select.line(source) --- end, - --- -- default prompts --- prompts = { --- Explain = { --- mapping = "ae", --- prompt = "/COPILOT_EXPLAIN Write an explanation for the active selection as paragraphs of text.", --- }, --- Review = { --- mapping = "ar", --- prompt = "/COPILOT_REVIEW Review the selected code.", --- -- callback = function(response, source) --- -- -- see config.lua for implementation --- -- end, --- }, --- Fix = { --- mapping = "af", --- prompt = "/COPILOT_GENERATE There is a problem in this code. Rewrite the code to show it with the bug fixed.", --- }, --- Optimize = { --- mapping = "ao", --- prompt = "/COPILOT_GENERATE Optimize the selected code to improve performance and readablilty.", --- }, --- Docs = { --- mapping = "ad", --- prompt = "/COPILOT_GENERATE Please add documentation comment for the selection.", --- }, --- Tests = { --- mapping = "at", --- prompt = "/COPILOT_GENERATE Please generate tests for my code.", --- }, --- FixDiagnostic = { --- mapping = "afd", --- prompt = "Please assist with the following diagnostic issue in file:", --- selection = select.diagnostics, --- }, --- Commit = { --- mapping = "ac", --- prompt = --- "Write commit message for the change with commitizen convention. Make sure the title has maximum 50 characters and message is wrapped at 72 characters. Wrap the whole message in code block with language gitcommit.", --- selection = select.gitdiff, --- }, --- CommitStaged = { --- mapping = "acs", --- prompt = --- "Write commit message for the change with commitizen convention. Make sure the title has maximum 50 characters and message is wrapped at 72 characters. Wrap the whole message in code block with language gitcommit.", --- selection = function(source) --- return select.gitdiff(source, true) --- end, --- }, --- }, - --- -- default window options --- window = { --- layout = "float", -- 'vertical', 'horizontal', 'float', 'replace' --- width = 0.5, -- fractional width of parent, or absolute width in columns when > 1 --- height = 0.5, -- fractional height of parent, or absolute height in rows when > 1 --- -- Options below only apply to floating windows --- relative = "editor", -- 'editor', 'win', 'cursor', 'mouse' --- border = "single", -- 'none', single', 'double', 'rounded', 'solid', 'shadow' --- row = nil, -- row position of the window, default is centered --- col = nil, -- column position of the window, default is centered --- title = "Copilot Chat", -- title of chat window --- footer = nil, -- footer of chat window --- zindex = 1, -- determines if window is on top or below other floating windows --- }, - --- -- default mappings --- mappings = { --- complete = { --- detail = "Use @ or / for options.", --- insert = "", --- }, --- close = { --- normal = "q", --- insert = "", --- }, --- reset = { --- normal = "", --- insert = "", --- }, --- submit_prompt = { --- normal = "", --- insert = "", --- }, --- accept_diff = { --- normal = "", --- insert = "", --- }, --- yank_diff = { --- normal = "gy", --- }, --- show_diff = { --- normal = "gd", --- }, --- show_system_prompt = { --- normal = "gp", --- }, --- show_user_selection = { --- normal = "gs", --- }, --- }, --- }) - -- Copilot autosuggestions +vim.g.copilot_no_tab_map = true vim.g.copilot_hide_during_completion = 0 vim.g.copilot_proxy_strict_ssl = 0 - vim.keymap.set("i", "", 'copilot#Accept("\\")', { expr = true, replace_keycodes = false, }) -vim.g.copilot_no_tab_map = true - -vim.keymap.set("i", "", "(copilot-accept-word)") -vim.keymap.set("i", "", "(copilot-accept-line)") local chat = require("CopilotChat") +local select = require("CopilotChat.select") chat.setup({ - model = "gpt-4o-2024-08-06", debug = true, - question_header = "", - answer_header = "", - error_header = "", - allow_insecure = true, - mappings = { - submit_prompt = { - insert = "", - }, - reset = { - normal = "", - insert = "", - }, - }, + log_level = "debug", + model = "gpt-4o", + selection = select.visual, prompts = { Explain = { mapping = "ae", @@ -237,4 +45,63 @@ chat.setup({ description = "AI Generate Commit", }, }, + + -- default mappings + mappings = { + complete = { + insert = "", + }, + close = { + normal = "q", + insert = "", + }, + reset = { + normal = "", + insert = "", + }, + submit_prompt = { + normal = "", + insert = "", + }, + toggle_sticky = { + detail = "Makes line under cursor sticky or deletes sticky line.", + normal = "gr", + }, + accept_diff = { + normal = "", + insert = "", + }, + jump_to_diff = { + normal = "gj", + }, + quickfix_diffs = { + normal = "gq", + }, + yank_diff = { + normal = "gy", + register = '"', + }, + show_diff = { + normal = "gd", + }, + show_info = { + normal = "gi", + }, + show_context = { + normal = "gc", + }, + show_help = { + normal = "gh", + }, + }, }) + +vim.keymap.set({ "n", "v" }, "aq", function() + vim.ui.input({ + prompt = "AI Question> ", + }, function(input) + if input and input ~= "" then + chat.ask(input) + end + end) +end, { desc = "AI Question" }) diff --git a/nvim/lua/plug-config/which-key-mappings.lua b/nvim/lua/plug-config/which-key-mappings.lua index 1a7d0ef..a120047 100644 --- a/nvim/lua/plug-config/which-key-mappings.lua +++ b/nvim/lua/plug-config/which-key-mappings.lua @@ -1,13 +1,29 @@ local wk = require("which-key") -local vmaps = {} +local vmaps = { + { "aa", "CopilotChatOpen", desc = "AI Open", remap = false }, +} + local nmaps = { { "/", "Commentary", desc = "Comment/uncomment line", remap = false }, { "G", "RG", desc = "RipGrep", remap = false }, + { "a", group = "AI - Copilot", remap = false }, - { "aa", "CopilotChatToggle", desc = "CopilotChat - toggle", remap = false }, - { "aq", "", desc = "CopilotChat - quick chat", remap = false }, - { "ax", "CopilotChatReset", desc = "CopilotChat - reset", remap = false }, + { "aa", "CopilotChatToggle", desc = "AI Toggle", remap = false }, + { "ax", "CopilotChatReset", desc = "AI Reset", remap = false }, + { "as", "CopilotChatStop", desc = "AI Stop", remap = false }, + { "am", "CopilotChatModels", desc = "AI Select Models", remap = false }, + { + "aq", + function() + local input = vim.fn.input("Quick Chat: ") + if input ~= "" then + require("CopilotChat").ask(input, { selection = require("CopilotChat.select").buffer }) + end + end, + desc = "CopilotChat - Quick chat", + }, + { "b", group = "Buffer", remap = false }, { "b", "Buffers", desc = "Buffers", remap = false }, { "bl", "BLines", desc = "Search by line in buffer", remap = false },