diff --git a/module.nix b/module.nix index b94cf72..7f18f87 100644 --- a/module.nix +++ b/module.nix @@ -3,6 +3,12 @@ options.nixvim-config = { enable = lib.mkEnableOption "Enable nixvim-config"; + enable-ai = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable ai plugins"; + }; + enable-startify = lib.mkOption { type = lib.types.bool; default = false; diff --git a/plugins/avante.nix b/plugins/avante.nix index 2c4c6ce..1afa8d3 100644 --- a/plugins/avante.nix +++ b/plugins/avante.nix @@ -1,64 +1,119 @@ -{ ... }: +{ config, ... }: { - programs.nixvim.plugins.avante = { - enable = true; + programs.nixvim.plugins = if config.nixvim-config.enable-ai then { + ## required dependencies + dressing.enable = true; # this is archived and may break in the future + nui.enable = true; - settings = { - provider = "copilot"; + ## optional dependencies + cmp.enable = true; + copilot-lua.enable = true; + fzf-lua.enable = true; + mini.enable = true; + telescope.enable = true; + web-devicons.enable = true; - claude = { - api_key_name = ""; - }; - openai = { - api_key_name = ""; - }; + avante = { + enable = true; - vendors = { - ollama = { - api_key_name = ""; - endpoint = "http://localhost:11434/v1"; - model = "hf.co/unsloth/DeepSeek-R1-Distill-Qwen-1.5B-GGUF"; - temperature = "0.6"; - parse_curl_args.__raw = '' - function(opts, code_opts) - return { - url = opts.endpoint .. "/chat/completions", - headers = { - ["Accept"] = "application/json", - ["Content-Type"] = "application/json", - ["x-api-key"] = "ollama", - }, - body = { - model = opts.model, - messages = require("avante.providers").copilot.parse_messages(code_opts), - max_tokens = opts.max_tokens, - stream = true, - }, - } - end''; - parse_response_data.__raw = '' - function(data_stream, event_state, opts) - require("avante.providers").openai.parse_response(data_stream, event_state, opts) - end''; - }; - }; + settings = { + provider = "copilot"; - mappings = { - ask = "ca"; - edit = "ce"; - refresh = "cr"; - focus = "cf"; - toggle = { - default = "ct"; - debug = "cd"; - hint = "ch"; - suggestion = "cs"; - repomap = "cR"; - }; files = { - add_current = "cc"; + auto_include = true; # Automatically include relevant files + max_files = 50; # Maximum number of files to include in context + max_size_kb = 1000; # Maximum total size of files in KB + + # Define which files to include/exclude + include = [ + "*.lua" + "*.nix" + "*.rs" + "*.ts" + "*.js" + "*.jsx" + "*.tsx" + # Add more patterns as needed + ]; + + exclude = [ + "node_modules/**" + "dist/**" + ".git/**" + # Add more patterns to exclude + ]; }; + + claude = { + api_key_name = ""; + }; + openai = { + api_key_name = ""; + }; + + vendors = { + ollama = { + api_key_name = ""; + endpoint = "http://localhost:11434/v1"; + model = "hf.co/unsloth/DeepSeek-R1-Distill-Qwen-1.5B-GGUF"; + temperature = "0.6"; + parse_curl_args.__raw = '' + function(opts, code_opts) + return { + url = opts.endpoint .. "/chat/completions", + headers = { + ["Accept"] = "application/json", + ["Content-Type"] = "application/json", + ["x-api-key"] = "ollama", + }, + body = { + model = opts.model, + messages = require("avante.providers").copilot.parse_messages(code_opts), + max_tokens = opts.max_tokens, + stream = true, + }, + } + end''; + parse_response_data.__raw = '' + function(data_stream, event_state, opts) + require("avante.providers").openai.parse_response(data_stream, event_state, opts) + end''; + }; + }; + + ## Default keybindings: + # aa - ask + # ae - edit + # ar - refresh + # af - focus + # co - choose ours + # ct - choose theirs + # ca - choose all theirs + # c0 - choose none + # cb - choose both + # cc - choose cursor + # ]x - previous conflict + # [x - next conflict + # [[ - previous code block + # ]] - next code block + + # mappings = { + # ask = "ca"; + # edit = "ce"; + # refresh = "cr"; + # focus = "cf"; + # toggle = { + # default = "ct"; + # debug = "cd"; + # hint = "ch"; + # suggestion = "cs"; + # repomap = "cR"; + # }; + # files = { + # add_current = "cc"; + # }; + # }; }; }; - }; + } else {}; } diff --git a/plugins/cmp.nix b/plugins/cmp.nix index 83cd1ba..f2c3f2c 100644 --- a/plugins/cmp.nix +++ b/plugins/cmp.nix @@ -1,4 +1,4 @@ -{ ... }: +{ config, ... }: { programs.nixvim = { plugins = { @@ -42,6 +42,19 @@ option.get_bufnrs.__raw = "vim.api.nvim_list_bufs"; keywordLength = 3; } + ] ++ (if config.nixvim-config.enable-ai then [ + { name = "codecompanion"; } + { name = "copilot"; } + ] else []) ++ [ + { + name = "path"; # file system paths + keywordLength = 3; + } + { + name = "luasnip"; # snippets + keywordLength = 3; + } + { name = "cmdline"; } { name = "codecompanion"; } { name = "copilot"; } { @@ -157,6 +170,7 @@ "" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })"; "" = '' cmp.mapping(function() + local luasnip = require('luasnip') if luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() end @@ -164,6 +178,7 @@ ''; "" = '' cmp.mapping(function() + local luasnip = require('luasnip') if luasnip.locally_jumpable(-1) then luasnip.jump(-1) end diff --git a/plugins/codecompanion.nix b/plugins/codecompanion.nix index 006a1ae..fce0222 100644 --- a/plugins/codecompanion.nix +++ b/plugins/codecompanion.nix @@ -1,7 +1,7 @@ -{ pkgs, ... }: +{ config, pkgs, ... }: { programs.nixvim = { - keymaps = [ + keymaps = if config.nixvim-config.enable-ai then [ { mode = [ "n" ]; key = ""; @@ -12,10 +12,10 @@ key = ",c"; action = ":CodeCompanionChat Toggle"; } - ]; + ] else []; plugins.codecompanion = { - enable = true; + enable = config.nixvim-config.enable-ai; settings = { adapters = { diff --git a/plugins/copilot.nix b/plugins/copilot.nix index 2da60cd..e61cdef 100644 --- a/plugins/copilot.nix +++ b/plugins/copilot.nix @@ -1,8 +1,8 @@ -{ ... }: +{ config, ... }: { programs.nixvim = { plugins.copilot-lua = { - enable = true; + enable = config.nixvim-config.enable-ai; settings = { suggestion.enabled = false; diff --git a/plugins/default.nix b/plugins/default.nix index af58c89..650b1ce 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -26,6 +26,8 @@ programs.nixvim.plugins = { comment.enable = true; + ## needed by avante. already archived, so may need to migrate to snacks + dressing.enable = true; fugitive.enable = true; gitsigns.enable = true; lightline.enable = false; @@ -40,6 +42,8 @@ top_down = false; }; }; + ## needed by avante. + nui.enable = true; nvim-autopairs.enable = true; nvim-bqf.enable = true; nvim-lightbulb.enable = true; diff --git a/plugins/luasnip.nix b/plugins/luasnip.nix index cdc7103..9fe4465 100644 --- a/plugins/luasnip.nix +++ b/plugins/luasnip.nix @@ -1,14 +1,14 @@ { ... }: { programs.nixvim = { - # keymaps = [ - # { - # mode = "i"; - # key = ""; - # action.__raw = ''function() require("luasnip.extras.select_choice")() end''; - # options.desc = "Search"; - # } - # ]; + keymaps = [ + { + mode = "i"; + key = ""; + action.__raw = ''function() require("luasnip.extras.select_choice")() end''; + options.desc = "Search"; + } + ]; plugins.luasnip = { enable = true; @@ -25,16 +25,16 @@ updateevents = ["TextChanged" "TextChangedI"]; region_check_events = "CursorHold"; delete_check_events = "InsertLeave"; - # ext_opts.__raw = '' - # { - # [require('luasnip.util.types').choiceNode] = { - # active = { - # virt_text = { { 'choice ', 'Comment' } }, - # hl_mode = 'combine', - # }, - # }, - # } - # ''; + ext_opts.__raw = '' + { + [require('luasnip.util.types').choiceNode] = { + active = { + virt_text = { { 'choice ', 'Comment' } }, + hl_mode = 'combine', + }, + }, + } + ''; }; }; };