1
0
Fork 0

add ai to nvim

This commit is contained in:
Luca Bilke 2024-04-14 03:04:34 +02:00
parent 779b25218e
commit 72f3c6d785
3 changed files with 230 additions and 5 deletions

View File

@ -13,4 +13,13 @@ function M.generate_shortcut_maps()
return maps
end
---@param key string
---@return string?
function M.get_secret(key)
local ok, keys = pcall(require, "custom.secrets")
if ok then
return keys[key]
end
end
return M

View File

@ -1,5 +1,224 @@
---@type LazySpec
return {
{
"CopilotC-Nvim/CopilotChat.nvim",
dependencies = {
{ "zbirenbaum/copilot.lua" },
{ "nvim-lua/plenary.nvim" },
{
"folke/which-key.nvim",
optional = true,
opts = { defaults = { ["<leader>a"] = { name = "+ai" }, ["<leader>ac"] = { name = "+copilot" } } },
},
},
keys = {
{ "<leader>acc", "<cmd>CopilotChatToggle<cr>", desc = "Toggle Chat", mode = { "n", "v" } },
{ "<leader>acx", "<cmd>CopilotChatReset<cr>", desc = "Reset Chat", mode = { "n", "v" } },
{ "<leader>acf", "<cmd>CopilotChatFix<cr>", desc = "Fix Selection", mode = { "v" } },
{ "<leader>ace", "<cmd>CopilotChatExplain<cr>", desc = "Explain Selection", mode = { "v" } },
{ "<leader>acr", "<cmd>CopilotChatExplain<cr>", desc = "Review Selection", mode = { "v" } },
{ "<leader>aco", "<cmd>CopilotChatOptimize<cr>", desc = "Optimize Selection", mode = { "v" } },
{ "<leader>acd", "<cmd>CopilotChatDocs<cr>", desc = "Document Selection", mode = { "v" } },
{ "<leader>act", "<cmd>CopilotChatTests<cr>", desc = "Unittest Selection", mode = { "v" } },
},
opts = {
window = {
layout = "float",
width = 0.9,
height = 0.8,
},
mappings = {
complete = {
detail = "Use @<Tab> or /<Tab> for options.",
insert = "<Tab>",
},
close = {
normal = "q",
insert = "<C-c>",
},
reset = {
normal = "<C-l>",
insert = "<C-l>",
},
submit_prompt = {
normal = "<CR>",
insert = "<C-CR>",
},
accept_diff = {
normal = "<C-y>",
insert = "<C-y>",
},
yank_diff = {
normal = "gy",
},
show_diff = {
normal = "gd",
},
show_system_prompt = {
normal = "gp",
},
show_user_selection = {
normal = "gs",
},
},
},
},
{
"jackMort/ChatGPT.nvim",
cmd = { "ChatGPT", "ChatGPTActAs", "ChatGPTEditWithInstructions", "ChatGPTRun" },
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
"folke/trouble.nvim",
"nvim-telescope/telescope.nvim",
{
"folke/which-key.nvim",
optional = true,
opts = {
defaults = {
["<leader>a"] = { name = "+ai" },
["<leader>ag"] = { name = "+chatgpt" },
["<leader>agt"] = { name = "+translate" },
},
},
},
},
config = function(_, opts)
local key = Lib.get_secret("openai")
require("chatgpt.api").OPENAI_API_KEY = key
require("chatgpt.api").AUTHORIZATION_HEADER = "Authorization: Bearer " .. key
require("chatgpt").setup(opts)
end,
--stylua: ignore
keys = {
{ "<leader>agc", function() require("chatgpt").openChat() end, desc = "Toggle Chat" },
{ "<leader>age", function() require("chatgpt").edit_with_instructions() end, desc = "Edit with instruction", mode = { "n", "v" } },
{ "<leader>agg", function() require("chatgpt").run_action("grammar_correction") end, desc = "Grammar Correction", mode = { "n", "v" } },
{ "<leader>agtg", function() require("chatgpt").run_action({ fargs = { "translate", "german" } }) end, desc = "German", mode = { "n", "v" } },
{ "<leader>agte", function() require("chatgpt").run_action({ fargs = { "translate", "english" } }) end, desc = "English", mode = { "n", "v" } },
{ "<leader>agtf", function() require("chatgpt").run_action({ fargs = { "translate", "french" } }) end, desc = "French", mode = { "n", "v" } },
{ "<leader>agtr", function() require("chatgpt").run_action({ fargs = { "translate", "russian" } }) end, desc = "Russian", mode = { "n", "v" } },
{ "<leader>agk", function() require("chatgpt").run_action({ fargs = { "keywords" } }) end, desc = "Keywords", mode = { "n", "v" } },
{ "<leader>agd", function() require("chatgpt").run_action({ fargs = { "docstring" } }) end, desc = "Docstring", mode = { "n", "v" } },
{ "<leader>aga", function() require("chatgpt").run_action({ fargs = { "add_tests" } }) end, desc = "Add Tests", mode = { "n", "v" } },
{ "<leader>ago", function() require("chatgpt").run_action({ fargs = { "optimize_code" } }) end, desc = "Optimize Code", mode = { "n", "v" } },
{ "<leader>ags", function() require("chatgpt").run_action({ fargs = { "summarize" } }) end, desc = "Summarize", mode = { "n", "v" } },
{ "<leader>agf", function() require("chatgpt").run_action({ fargs = { "fix_bugs" } }) end, desc = "Fix Bugs", mode = { "n", "v" } },
{ "<leader>agx", function() require("chatgpt").run_action({ fargs = { "explain_code" } }) end, desc = "Explain Code", mode = { "n", "v" } },
{ "<leader>agr", function() require("chatgpt").run_action({ fargs = { "roxygen_edit" } }) end, desc = "Roxygen Edit", mode = { "n", "v" } },
{ "<leader>agl", function() require("chatgpt").run_action({ fargs = { "code_readability_analysis" } }) end, desc = "Code Readability Analysis", mode = { "n", "v" } },
},
opts = {
edit_with_instructions = {
keymaps = {
close = "<C-c>",
accept = "<C-y>",
toggle_diff = "<C-d>",
toggle_settings = "<C-o>",
toggle_help = "<C-.>",
cycle_windows = "<Tab>",
use_output_as_input = "<C-,>",
},
},
chat = {
question_sign = "",
answer_sign = "󰚩",
sessions_window = {
active_sign = " 󰭹 ",
inactive_sign = " 󰻞 ",
current_line_sign = "",
border = {
style = "single",
},
},
keymaps = {
close = "<C-c>",
yank_last = "<C-y>",
yank_last_code = "<C-p>",
scroll_up = "<C-u>",
scroll_down = "<C-d>",
new_session = "<C-g>",
cycle_windows = "<Tab>",
cycle_modes = "<C-f>",
next_message = "<C-n>",
prev_message = "<C-p>",
select_session = "<Space>",
rename_session = "r",
delete_session = "d",
draft_message = "<C-r>",
edit_message = "e",
delete_message = "d",
toggle_settings = "<C-o>",
toggle_sessions = "<C-s>",
toggle_help = "<C-.>",
toggle_message_role = "<C-,>",
toggle_system_role_open = "<C-'>",
stop_generating = "<C-x>",
},
},
popup_layout = {
default = "center",
center = {
width = "90%",
height = "80%",
},
right = {
width = "30%",
width_settings_open = "50%",
},
},
popup_window = {
border = {
style = "single",
},
win_options = {
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder",
},
},
system_window = {
border = {
style = "single",
},
win_options = {
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder",
},
},
popup_input = {
border = {
style = "single",
},
win_options = {
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder",
},
submit = "<C-Enter>",
submit_n = "<Enter>",
},
settings_window = {
border = {
style = "single",
},
win_options = {
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder",
},
},
help_window = {
border = {
style = "single",
},
win_options = {
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder",
},
},
openai_params = {
-- model = "gpt-3.5-turbo",
model = "gpt-4-turbo",
},
openai_edit_params = {
-- model = "gpt-3.5-turbo",
model = "gpt-4-turbo",
},
},
},
{
"nvim-neo-tree/neo-tree.nvim",
opts = function(_, opts)
@ -26,11 +245,7 @@ return {
{
"folke/which-key.nvim",
optional = true,
opts = {
defaults = {
["<leader>z"] = { name = "+zk" },
},
},
opts = { defaults = { ["<leader>z"] = { name = "+zk" } } },
},
},
opts = {

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
.config/nvim/lua/config/keys.lua
.config/gtk-2.0/gtkfilechooser.ini
.config/nvim/spell/en.utf-8.add.spl
.config/nvim/lua/custom/secrets.lua