From 46eb3242d36a4196a5e6f3fc4ec8f0dd820915cc Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 12 Jun 2024 11:41:03 +0200 Subject: [PATCH] refactor: copilot-chat --- .../plugins/extras/coding/copilot-chat.lua | 82 +++++-------------- 1 file changed, 20 insertions(+), 62 deletions(-) diff --git a/lua/lazyvim/plugins/extras/coding/copilot-chat.lua b/lua/lazyvim/plugins/extras/coding/copilot-chat.lua index d7e33d15..2db98a8c 100644 --- a/lua/lazyvim/plugins/extras/coding/copilot-chat.lua +++ b/lua/lazyvim/plugins/extras/coding/copilot-chat.lua @@ -1,3 +1,19 @@ +local M = {} + +---@param kind string +function M.pick(kind) + return function() + local actions = require("CopilotChat.actions") + local items = actions[kind .. "_actions"]() + if not items then + LazyVim.warn("No " .. kind .. " found on the current line") + return + end + local ok = pcall(require, "fzf-lua") + require("CopilotChat.integrations." .. (ok and "fzflua" or "telescope")).pick(items) + end +end + return { { "CopilotC-Nvim/CopilotChat.nvim", @@ -50,6 +66,10 @@ return { desc = "Quick Chat (CopilotChat)", mode = { "n", "v" }, }, + -- Show help actions with telescope + { "ad", M.pick("help"), desc = "Diagnostic Help (CopilotChat)", mode = { "n", "v" } }, + -- Show prompts actions with telescope + { "ap", M.pick("prompt"), desc = "Prompt Actions (CopilotChat)", mode = { "n", "v" } }, }, config = function(_, opts) local chat = require("CopilotChat") @@ -67,68 +87,6 @@ return { end, }, - -- Telescope integration - { - "nvim-telescope/telescope.nvim", - optional = true, - keys = { - -- Show help actions with telescope - { - "ad", - function() - local actions = require("CopilotChat.actions") - local help = actions.help_actions() - if not help then - LazyVim.warn("No diagnostics found on the current line") - return - end - require("CopilotChat.integrations.telescope").pick(help) - end, - desc = "Diagnostic Help (CopilotChat)", - mode = { "n", "v" }, - }, - -- Show prompts actions with telescope - { - "ap", - function() - local actions = require("CopilotChat.actions") - require("CopilotChat.integrations.telescope").pick(actions.prompt_actions()) - end, - desc = "Prompt Actions (CopilotChat)", - mode = { "n", "v" }, - }, - }, - }, - - { - "ibhagwan/fzf-lua", - optional = true, - keys = { - -- Show help actions with fzf-lua (if installed in extras) - { - "ad", - function() - local actions = require("CopilotChat.actions") - local help = actions.help_actions() - if not help then - LazyVim.warn("No diagnostics found on the current line") - return - end - require("CopilotChat.integrations.fzflua").pick(help) - end, - desc = "Diagnostic Help (CopilotChat)", - }, - -- Show prompts actions with fzf-lua (if installed in extras) - { - "ap", - function() - local actions = require("CopilotChat.actions") - require("CopilotChat.integrations.fzflua").pick(actions.prompt_actions()) - end, - desc = "Prompt Actions (CopilotChat)", - }, - }, - }, -- Edgy integration { "folke/edgy.nvim",