From 234cefdcdceb584ffc0ae7dd1033525a3e5f4af6 Mon Sep 17 00:00:00 2001 From: Hawtian Wang Date: Thu, 18 Apr 2024 22:13:09 +0800 Subject: [PATCH] ... --- lua/dotvim/extra/ui/copilot-chat.lua | 56 ++++++++++++++++++++++++++++ lua/dotvim/extra/ui/init.lua | 3 ++ 2 files changed, 59 insertions(+) create mode 100644 lua/dotvim/extra/ui/copilot-chat.lua diff --git a/lua/dotvim/extra/ui/copilot-chat.lua b/lua/dotvim/extra/ui/copilot-chat.lua new file mode 100644 index 00000000..571c90c2 --- /dev/null +++ b/lua/dotvim/extra/ui/copilot-chat.lua @@ -0,0 +1,56 @@ +---@class dotvim.extra.ui.copilot_chat +local M = {} + +function M.toggle() + if M.renderer then + return M.renderer:focus() + end + + local n = require("nui-components") + local chat = require("CopilotChat") + + local win_width = vim.o.columns + local win_height = vim.o.lines + + local width = math.floor(win_width * 0.6) + local height = math.floor(win_height * 0.8) + + local renderer = n.create_renderer { + width = width, + height = height, + relative = "editor", + position = { + row = math.floor((win_height - height) / 2), + col = math.floor((win_width - width) / 2), + }, + } + + local signal = n.create_signal { + prompt = "", + } + + local buttons = function() + return n.columns { + n.button { + text = "Send", + on_click = function() + local prompt = signal:get("prompt") + if prompt == "" then + return + end + + vim.api.nvim_command("CopilotChat send " .. prompt) + signal:set("prompt", "") + end, + }, + n.button { + text = "Close", + on_click = function() + renderer:close() + end, + }, + } + end +end + +return M diff --git a/lua/dotvim/extra/ui/init.lua b/lua/dotvim/extra/ui/init.lua index 84a9fb0b..df7ea4e0 100644 --- a/lua/dotvim/extra/ui/init.lua +++ b/lua/dotvim/extra/ui/init.lua @@ -7,4 +7,7 @@ M.args_input = require("dotvim.extra.ui.args_input") ---@type dotvim.extra.ui.spectre M.spectre = require("dotvim.extra.ui.spectre") +---@type dotvim.extra.ui.copilot_chat +M.copilot_chat = require("dotvim.extra.ui.copilot-chat") + return M