aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/config/copilot.lua92
-rw-r--r--lua/config/icons.lua65
-rw-r--r--lua/config/init.lua1
-rw-r--r--lua/config/utils.lua73
-rw-r--r--lua/plugins/copilot-chat.lua224
5 files changed, 240 insertions, 215 deletions
diff --git a/lua/config/copilot.lua b/lua/config/copilot.lua
new file mode 100644
index 0000000..9b9b6fc
--- /dev/null
+++ b/lua/config/copilot.lua
@@ -0,0 +1,92 @@
+local utils = require('config.utils')
+local icons = require('config.icons')
+utils.desc('<leader>a', 'AI')
+
+-- 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', '<S-Tab>', 'copilot#Accept("\\<S-Tab>")', { expr = true, replace_keycodes = false })
+
+-- Copilot chat
+local chat = require('CopilotChat')
+local actions = require('CopilotChat.actions')
+local select = require('CopilotChat.select')
+local integration = require('CopilotChat.integrations.fzflua')
+
+chat.setup({
+ model = 'claude-3.5-sonnet',
+ question_header = ' ' .. icons.ui.User .. ' ',
+ answer_header = ' ' .. icons.ui.Bot .. ' ',
+ error_header = '> ' .. icons.diagnostics.Warn .. ' ',
+ selection = select.visual,
+ mappings = {
+ reset = {
+ normal = '',
+ insert = '',
+ },
+ },
+ prompts = {
+ Yarrr = {
+ system_prompt = 'You are fascinated by pirates, so please respond in pirate speak.',
+ },
+ Explain = {
+ mapping = '<leader>ae',
+ description = 'AI Explain',
+ },
+ Review = {
+ mapping = '<leader>ar',
+ description = 'AI Review',
+ },
+ Tests = {
+ mapping = '<leader>at',
+ description = 'AI Tests',
+ },
+ Fix = {
+ mapping = '<leader>af',
+ description = 'AI Fix',
+ },
+ Optimize = {
+ mapping = '<leader>ao',
+ description = 'AI Optimize',
+ },
+ Docs = {
+ mapping = '<leader>ad',
+ description = 'AI Documentation',
+ },
+ Commit = {
+ mapping = '<leader>ac',
+ description = 'AI Generate Commit',
+ },
+ },
+})
+
+utils.au('BufEnter', {
+ pattern = 'copilot-*',
+ callback = function()
+ vim.opt_local.relativenumber = false
+ vim.opt_local.number = false
+ end,
+})
+
+vim.keymap.set({ 'n' }, '<leader>aa', chat.toggle, { desc = 'AI Toggle' })
+vim.keymap.set({ 'v' }, '<leader>aa', chat.open, { desc = 'AI Open' })
+vim.keymap.set({ 'n' }, '<leader>ax', chat.reset, { desc = 'AI Reset' })
+vim.keymap.set({ 'n' }, '<leader>as', chat.stop, { desc = 'AI Stop' })
+vim.keymap.set({ 'n' }, '<leader>am', chat.select_model, { desc = 'AI Model' })
+vim.keymap.set({ 'n', 'v' }, '<leader>ap', function()
+ integration.pick(actions.prompt_actions(), {
+ fzf_tmux_opts = {
+ ['-d'] = '45%',
+ },
+ })
+end, { desc = 'AI Prompts' })
+vim.keymap.set({ 'n', 'v' }, '<leader>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/lua/config/icons.lua b/lua/config/icons.lua
new file mode 100644
index 0000000..f4134a7
--- /dev/null
+++ b/lua/config/icons.lua
@@ -0,0 +1,65 @@
+return {
+ fold = {
+ Closed = '',
+ Open = '',
+ },
+ ui = {
+ User = ' ',
+ Bot = ' ',
+ Wiki = '󰈙',
+ Hunk = '󰏚',
+ },
+ dap = {
+ Stopped = { '󰁕 ', 'DiagnosticWarn' },
+ Breakpoint = ' ',
+ BreakpointCondition = ' ',
+ BreakpointRejected = { ' ', 'DiagnosticError' },
+ LogPoint = '.>',
+ },
+ diagnostics = {
+ Error = ' ',
+ Warn = ' ',
+ Hint = ' ',
+ Info = ' ',
+ },
+ kinds = {
+ Array = ' ',
+ Boolean = '󰨙 ',
+ Class = ' ',
+ Codeium = '󰘦 ',
+ Color = ' ',
+ Control = ' ',
+ Collapsed = ' ',
+ Constant = '󰏿 ',
+ Constructor = ' ',
+ Enum = ' ',
+ EnumMember = ' ',
+ Event = ' ',
+ Field = ' ',
+ File = ' ',
+ Folder = ' ',
+ Function = '󰊕 ',
+ Interface = ' ',
+ Key = ' ',
+ Keyword = ' ',
+ Method = '󰊕 ',
+ Module = ' ',
+ Namespace = '󰦮 ',
+ Null = ' ',
+ Number = '󰎠 ',
+ Object = ' ',
+ Operator = ' ',
+ Package = ' ',
+ Property = ' ',
+ Reference = ' ',
+ Snippet = ' ',
+ String = ' ',
+ Struct = '󰆼 ',
+ TabNine = '󰏚 ',
+ Text = ' ',
+ TypeParameter = ' ',
+ Unit = ' ',
+ Value = ' ',
+ Variable = '󰀫 ',
+ },
+}
diff --git a/lua/config/init.lua b/lua/config/init.lua
index 74e9c00..b84221f 100644
--- a/lua/config/init.lua
+++ b/lua/config/init.lua
@@ -9,6 +9,7 @@ vim.api.nvim_create_autocmd("User", {
require "config.keymaps"
require "config.diagnostic"
require "config.composer"
+ require "config.copilot"
end,
})
require "config.lazy"
diff --git a/lua/config/utils.lua b/lua/config/utils.lua
new file mode 100644
index 0000000..ea8a5c9
--- /dev/null
+++ b/lua/config/utils.lua
@@ -0,0 +1,73 @@
+local wk = require('which-key')
+local group = vim.api.nvim_create_augroup('NeoVimRc', { clear = true })
+
+local M = {}
+
+M.dot = function(callback)
+ return function()
+ _G.dot_repeat_callback = callback
+ vim.go.operatorfunc = 'v:lua.dot_repeat_callback'
+ vim.cmd('normal! g@l')
+ end
+end
+
+M.map = function(mode, keys, func, desc, buffer, dot)
+ if dot then
+ if func then
+ local f = func
+ func = M.dot(function()
+ f()
+ end)
+ end
+ if desc then
+ desc = desc .. ' [R]'
+ end
+ end
+
+ vim.keymap.set(mode, keys, func, { buffer = buffer, desc = desc, remap = true, nowait = true })
+end
+
+M.nmap = function(keys, func, desc, buffer)
+ M.map('n', keys, func, desc, buffer)
+end
+
+M.rnmap = function(keys, func, desc, buffer)
+ M.map('n', keys, func, desc, buffer, true)
+end
+
+M.vmap = function(keys, func, desc, buffer)
+ M.map('v', keys, func, desc, buffer)
+end
+
+M.rvmap = function(keys, func, desc, buffer)
+ M.map('v', keys, func, desc, buffer, true)
+end
+
+M.nvmap = function(keys, func, desc, buffer)
+ M.map({ 'n', 'v' }, keys, func, desc, buffer)
+end
+
+M.rnvmap = function(keys, func, desc, buffer)
+ M.map({ 'n', 'v' }, keys, func, desc, buffer, true)
+end
+
+M.au = function(event, opts)
+ opts['group'] = group
+ return vim.api.nvim_create_autocmd(event, opts)
+end
+
+M.desc = function(key, desc, icon)
+ local opts = { key, desc = desc }
+ if icon then
+ opts.icon = icon
+ end
+ wk.add(opts)
+end
+
+M.make_capabilities = function()
+ local capabilities = vim.lsp.protocol.make_client_capabilities()
+ capabilities = vim.tbl_deep_extend('force', capabilities, require('autocomplete.capabilities'))
+ return capabilities
+end
+
+return M
diff --git a/lua/plugins/copilot-chat.lua b/lua/plugins/copilot-chat.lua
index 0ae500d..dc31b32 100644
--- a/lua/plugins/copilot-chat.lua
+++ b/lua/plugins/copilot-chat.lua
@@ -1,224 +1,18 @@
-local IS_DEV = false
-
-local prompts = {
- -- Code related prompts
- Explain = "Please explain how the following code works.",
- Review = "Please review the following code and provide suggestions for improvement.",
- Tests = "Please explain how the selected code works, then generate unit tests for it.",
- Refactor = "Please refactor the following code to improve its clarity and readability.",
- FixCode = "Please fix the following code to make it work as intended.",
- FixError = "Please explain the error in the following text and provide a solution.",
- BetterNamings = "Please provide better names for the following variables and functions.",
- Documentation = "Please provide documentation for the following code.",
- SwaggerApiDocs = "Please provide documentation for the following API using Swagger.",
- SwaggerJsDocs = "Please write JSDoc for the following API using Swagger.",
- -- Text related prompts
- Summarize = "Please summarize the following text.",
- Spelling = "Please correct any grammar and spelling errors in the following text.",
- Wording = "Please improve the grammar and wording of the following text.",
- Concise = "Please rewrite the following text to make it more concise.",
-}
-
return {
- -- { import = "plugins.extras.copilot-vim" }, -- Or use { import = "lazyvim.plugins.extras.coding.copilot" },
- {
- "folke/which-key.nvim",
- optional = true,
- opts = {
- spec = {
- { "<leader>a", group = "ai" },
- { "gm", group = "+Copilot chat" },
- { "gmh", desc = "Show help" },
- { "gmd", desc = "Show diff" },
- { "gmp", desc = "Show system prompt" },
- { "gms", desc = "Show selection" },
- { "gmy", desc = "Yank diff" },
- },
- },
- },
{
- dir = IS_DEV and "~/Projects/research/CopilotChat.nvim" or nil,
"CopilotC-Nvim/CopilotChat.nvim",
- -- version = "v3.3.0", -- Use a specific version to prevent breaking changes
dependencies = {
- { "nvim-telescope/telescope.nvim" }, -- Use telescope for help actions
- { "nvim-lua/plenary.nvim" },
- { "zbirenbaum/copilot.lua" }, -- or github/copilot.vim
- },
- opts = {
- question_header = "## User ",
- answer_header = "## Copilot ",
- error_header = "## Error ",
- prompts = prompts,
- auto_follow_cursor = false, -- Don't follow the cursor after getting response
- mappings = {
- -- Use tab for completion
- complete = {
- detail = "Use @<Tab> or /<Tab> for options.",
- insert = "<Tab>",
- },
- -- Close the chat
- close = {
- normal = "q",
- insert = "<C-c>",
- },
- -- Reset the chat buffer
- reset = {
- normal = "<C-x>",
- insert = "<C-x>",
- },
- -- Submit the prompt to Copilot
- submit_prompt = {
- normal = "<CR>",
- insert = "<C-CR>",
- },
- -- Accept the diff
- accept_diff = {
- normal = "<C-y>",
- insert = "<C-y>",
- },
- -- Yank the diff in the response to register
- yank_diff = {
- normal = "gmy",
- },
- -- Show the diff
- show_diff = {
- normal = "gmd",
- },
- -- Show the info
- show_info = {
- normal = "gmi",
- },
- -- Show the context
- show_context = {
- normal = "gmc",
- },
- -- Show help
- show_help = {
- normal = "gmh",
- },
- },
- },
- config = function(_, opts)
- local chat = require("CopilotChat")
- local select = require("CopilotChat.select")
- -- Use unnamed register for the selection
- opts.selection = select.unnamed
-
- chat.setup(opts)
-
- vim.api.nvim_create_user_command("CopilotChatVisual", function(args)
- chat.ask(args.args, { selection = select.visual })
- end, { nargs = "*", range = true })
-
- -- Inline chat with Copilot
- vim.api.nvim_create_user_command("CopilotChatInline", function(args)
- chat.ask(args.args, {
- selection = select.visual,
- window = {
- layout = "float",
- relative = "cursor",
- width = 1,
- height = 0.4,
- row = 1,
- },
- })
- end, { nargs = "*", range = true })
-
- -- Restore CopilotChatBuffer
- vim.api.nvim_create_user_command("CopilotChatBuffer", function(args)
- chat.ask(args.args, { selection = select.buffer })
- end, { nargs = "*", range = true })
-
- -- Custom buffer for CopilotChat
- vim.api.nvim_create_autocmd("BufEnter", {
- pattern = "copilot-*",
- callback = function()
- vim.opt_local.relativenumber = true
- vim.opt_local.number = true
-
- -- Get current filetype and set it to markdown if the current filetype is copilot-chat
- local ft = vim.bo.filetype
- if ft == "copilot-chat" then
- vim.bo.filetype = "markdown"
- end
- end,
- })
- end,
- event = "VeryLazy",
- keys = {
- -- Show prompts actions with telescope
- {
- "<leader>ap",
- function()
- local actions = require("CopilotChat.actions")
- require("CopilotChat.integrations.telescope").pick(actions.prompt_actions())
- end,
- desc = "CopilotChat - Prompt actions",
- },
+ { "nvim-lua/plenary.nvim", branch = "master" }, -- for curl, log and async functions
{
- "<leader>ap",
- ":lua require('CopilotChat.integrations.telescope').pick(require('CopilotChat.actions').prompt_actions({selection = require('CopilotChat.select').visual}))<CR>",
- mode = "x",
- desc = "CopilotChat - Prompt actions",
+ "ibhagwan/fzf-lua",
+ config = function()
+ require("fzf-lua").setup({})
+ end
},
- -- Code related commands
- { "<leader>ae", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
- { "<leader>at", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
- { "<leader>ar", "<cmd>CopilotChatReview<cr>", desc = "CopilotChat - Review code" },
- { "<leader>aR", "<cmd>CopilotChatRefactor<cr>", desc = "CopilotChat - Refactor code" },
- { "<leader>an", "<cmd>CopilotChatBetterNamings<cr>", desc = "CopilotChat - Better Naming" },
- -- Chat with Copilot in visual mode
- {
- "<leader>av",
- ":CopilotChatVisual",
- mode = "x",
- desc = "CopilotChat - Open in vertical split",
- },
- {
- "<leader>ax",
- ":CopilotChatInline<cr>",
- mode = "x",
- desc = "CopilotChat - Inline chat",
- },
- -- Custom input for CopilotChat
- {
- "<leader>ai",
- function()
- local input = vim.fn.input("Ask Copilot: ")
- if input ~= "" then
- vim.cmd("CopilotChat " .. input)
- end
- end,
- desc = "CopilotChat - Ask input",
- },
- -- Generate commit message based on the git diff
- {
- "<leader>am",
- "<cmd>CopilotChatCommit<cr>",
- desc = "CopilotChat - Generate commit message for all changes",
- },
- -- Quick chat with Copilot
- {
- "<leader>aq",
- function()
- local input = vim.fn.input("Quick Chat: ")
- if input ~= "" then
- vim.cmd("CopilotChatBuffer " .. input)
- end
- end,
- desc = "CopilotChat - Quick chat",
- },
- -- Debug
- { "<leader>ad", "<cmd>CopilotChatDebugInfo<cr>", desc = "CopilotChat - Debug Info" },
- -- Fix the issue with diagnostic
- { "<leader>af", "<cmd>CopilotChatFixDiagnostic<cr>", desc = "CopilotChat - Fix Diagnostic" },
- -- Clear buffer and chat history
- { "<leader>al", "<cmd>CopilotChatReset<cr>", desc = "CopilotChat - Clear buffer and chat history" },
- -- Toggle Copilot Chat Vsplit
- { "<leader>av", "<cmd>CopilotChatToggle<cr>", desc = "CopilotChat - Toggle" },
- -- Copilot Chat Models
- { "<leader>a?", "<cmd>CopilotChatModels<cr>", desc = "CopilotChat - Select Models" },
},
+ opts = {
+ -- See Configuration section for options
+ },
+ -- See Commands section for default commands if you want to lazy load on them
},
}