Compare commits

...

2 commits

Author SHA1 Message Date
NotAShelf
5b8ef42453
Merge f9cec7b4cc into f3817fb4b2 2024-04-20 14:40:28 +00:00
Kalle Jepsen
f9cec7b4cc
assistant/chatgpt: Add jackMort/ChatGPT.nvim 2024-04-20 17:40:22 +03:00
6 changed files with 84 additions and 0 deletions

View file

@ -222,6 +222,7 @@ inputs: let
};
assistant = {
chatgpt.enable = isMaximal;
copilot = {
enable = isMaximal;
cmp.enable = isMaximal;

View file

@ -550,6 +550,11 @@
};
# Assistant
plugin-chatgpt = {
url = "github:jackMort/ChatGPT.nvim";
flake = false;
};
plugin-copilot-lua = {
url = "github:zbirenbaum/copilot.lua";
flake = false;

View file

@ -0,0 +1,25 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.assistant.chatgpt = {
enable = mkEnableOption "ChatGPT AI assistant. Requires the environment variable OPENAI_API_KEY to be set";
setupOpts = mkPluginSetupOption "chatgpt" {};
mappings = {
chatGpt = mkMappingOption "ChatGPT" "<leader>ac";
editWithInstructions = mkMappingOption "[ChatGPT] Edit with instructions" "<leader>ae";
grammarCorrection = mkMappingOption "[ChatGPT] Grammar correction" "<leader>ag";
translate = mkMappingOption "[ChatGPT] Translate" "<leader>at";
keyword = mkMappingOption "[ChatGPT] Keywords" "<leader>ak";
docstring = mkMappingOption "[ChatGPT] Docstring" "<leader>ad";
addTests = mkMappingOption "[ChatGPT] Add tests" "<leader>aa";
optimize = mkMappingOption "[ChatGPT] Optimize code" "<leader>ao";
summarize = mkMappingOption "[ChatGPT] Summarize" "<leader>as";
fixBugs = mkMappingOption "[ChatGPT] Fix bugs" "<leader>af";
explain = mkMappingOption "[ChatGPT] Explain code" "<leader>ax";
roxygenEdit = mkMappingOption "[ChatGPT] Roxygen edit" "<leader>ar";
readabilityanalysis = mkMappingOption "[ChatGPT] Code reability analysis" "<leader>al";
};
};
}

View file

@ -0,0 +1,46 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.assistant.chatgpt;
self = import ./chatgpt.nix {inherit lib;};
mappingDefinitions = self.options.vim.assistant.chatgpt.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
maps = mkMerge [
(mkSetBinding mappings.editWithInstructions "<cmd>ChatGPTEditWithInstruction<CR>")
(mkSetBinding mappings.grammarCorrection "<cmd>ChatGPTRun grammar_correction<CR>")
(mkSetBinding mappings.translate "<cmd>ChatGPTRun translate<CR>")
(mkSetBinding mappings.keyword "<cmd>ChatGPTRun keywords<CR>")
(mkSetBinding mappings.docstring "<cmd>ChatGPTRun docstring<CR>")
(mkSetBinding mappings.addTests "<cmd>ChatGPTRun add_tests<CR>")
(mkSetBinding mappings.optimize "<cmd>ChatGPTRun optimize_code<CR>")
(mkSetBinding mappings.summarize "<cmd>ChatGPTRun summarize<CR>")
(mkSetBinding mappings.fixBugs "<cmd>ChatGPTRun fix_bugs<CR>")
(mkSetBinding mappings.explain "<cmd>ChatGPTRun explain_code<CR>")
(mkSetBinding mappings.roxygenEdit "<cmd>ChatGPTRun roxygen_edit<CR>")
(mkSetBinding mappings.readabilityanalysis "<cmd>ChatGPTRun code_readability_analysis<CR>")
];
in {
config = mkIf cfg.enable {
vim = {
startPlugins = [
"chatgpt"
];
luaConfigRC.chagpt = entryAnywhere ''
require("chatgpt").setup(${toLuaObject cfg.setupOpts})
'';
maps.normal = mkMerge [
(mkSetBinding mappings.chatGpt "<cmd>ChatGPT<CR>")
maps
];
maps.visual = maps;
};
};
}

View file

@ -0,0 +1,6 @@
{
imports = [
./chatgpt.nix
./config.nix
];
}

View file

@ -1,5 +1,6 @@
{
imports = [
./chatgpt
./copilot
];
}