summaryrefslogtreecommitdiffstats
path: root/modules/plugins/assistant/codecompanion/config.nix
blob: 6fbb60fb4a7f8430d1761c183637068559103626 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
  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";
            };
          };
        };
      };
    };
  };
}