{ config, lib, ... }: let inherit (lib.modules) mkIf; cfg = config.vim.assistant.codecompanion-nvim; in { config = mkIf cfg.enable { vim = { startPlugins = [ "plenary-nvim" ]; lazy.plugins = { codecompanion-nvim = { package = "codecompanion-nvim"; setupModule = "codecompanion"; inherit (cfg) setupOpts; # Register commands with lz.n so Neovim recognizes them immediately cmd = [ "CodeCompanion" "CodeCompanionChat" "CodeCompanionActions" "CodeCompanionCmd" ]; # Ensure the plugin loads when entering Insert/Cmdline mode # so the module is ready when blink.cmp requests it event = ["InsertEnter" "CmdlineEnter"]; }; }; treesitter = { enable = true; # Codecompanion depends on the YAML grammar being added. Below is # an easy way of adding an user-configurable grammar package exposed # by the YAML language module *without* enabling the whole YAML language # module. The package is defined even when the module is disabled. grammars = [ config.vim.languages.yaml.treesitter.package ]; }; autocomplete = { nvim-cmp = { sources = {codecompanion-nvim = "[codecompanion]";}; sourcePlugins = ["codecompanion-nvim"]; }; blink-cmp = { setupOpts.sources = { default = ["codecompanion"]; providers.codecompanion = { name = "CodeCompanion"; module = "codecompanion.providers.completion.blink"; }; }; }; }; }; }; }