|
1 | 1 | {
|
2 | 2 | lib,
|
3 | 3 | config,
|
| 4 | + options, |
4 | 5 | ...
|
5 | 6 | }:
|
6 | 7 | let
|
|
25 | 26 | (map (lib.getAttr "name"))
|
26 | 27 | lib.unique
|
27 | 28 | ];
|
| 29 | + |
| 30 | + newStylePlugins = lib.pipe options.plugins [ |
| 31 | + # First, a manual blacklist |
| 32 | + (lib.flip builtins.removeAttrs [ |
| 33 | + # lspkind has its own `cmp` options, but isn't a nvim-cmp source |
| 34 | + "lspkind" |
| 35 | + ]) |
| 36 | + builtins.attrValues |
| 37 | + # Filter for non-options (all plugins are plain attrsets, not options) |
| 38 | + # i.e. remove rename aliases |
| 39 | + (builtins.filter (opt: !lib.isOption opt)) |
| 40 | + # Filter for plugins that have `cmp` enabled |
| 41 | + (builtins.filter (opt: opt.cmp.value.enable or false)) |
| 42 | + # Collect the enable options' `loc`s |
| 43 | + (builtins.catAttrs "enable") |
| 44 | + (builtins.catAttrs "loc") |
| 45 | + # Drop the `"enable"` part of the option-loc |
| 46 | + (builtins.map (lib.lists.dropEnd 1)) |
| 47 | + # Render each plugin loc as an option string |
| 48 | + (builtins.map lib.showOption) |
| 49 | + ]; |
28 | 50 | in
|
29 | 51 | {
|
30 | 52 | options = {
|
|
55 | 77 | };
|
56 | 78 | };
|
57 | 79 |
|
58 |
| - config = lib.mkIf (cfg.enable && cfg.autoEnableSources) ( |
59 |
| - lib.mkMerge [ |
60 |
| - { |
| 80 | + config = lib.mkMerge ( |
| 81 | + [ |
| 82 | + (lib.mkIf (cfg.enable && cfg.autoEnableSources && newStylePlugins != [ ]) { |
| 83 | + # Warn when the new and old systems are used together. |
| 84 | + # `autoEnableSources` is incompatible with the new `plugins.*.cmp` options |
| 85 | + # TODO: |
| 86 | + # - Have `autoEnableSources` default to no `plugins.*.cmp` options being enabled? |
| 87 | + # - Maybe warn when `autoEnableSources` has highestPrio 1500? |
| 88 | + # - I'm not sure how best to migrate to having `plugins.*.cmp.enable` default to true... |
| 89 | + warnings = lib.nixvim.mkWarnings "plugins.cmp" '' |
| 90 | + You have enabled `autoEnableSources` that tells Nixvim to automatically enable the source plugins with respect to the list of sources provided in `settings.sources`. |
| 91 | + However, ${builtins.toString (builtins.length newStylePlugins)} plugins have cmp integration configured via `plugins.*.cmp`:${ |
| 92 | + lib.concatMapStrings (opt: "\n- `${opt}`") newStylePlugins |
| 93 | + } |
| 94 | + ''; |
| 95 | + }) |
| 96 | + (lib.mkIf (cfg.enable && cfg.autoEnableSources) { |
61 | 97 | warnings = lib.nixvim.mkWarnings "plugins.cmp" [
|
62 | 98 | # TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions
|
63 | 99 | {
|
|
82 | 118 | }
|
83 | 119 | ];
|
84 | 120 |
|
85 |
| - # If the user has enabled the `foo` and `bar` sources, then `plugins` will look like: |
86 |
| - # { |
87 |
| - # cmp-foo.enable = true; |
88 |
| - # cmp-bar.enable = true; |
89 |
| - # } |
90 |
| - plugins = lib.mapAttrs' (source: name: { |
91 |
| - inherit name; |
92 |
| - value.enable = lib.mkIf (lib.elem source enabledSources) true; |
93 |
| - }) config.cmpSourcePlugins; |
94 |
| - } |
95 |
| - { |
96 | 121 | plugins.lsp.capabilities = lib.mkIf (lib.elem "nvim_lsp" enabledSources) ''
|
97 | 122 | capabilities = vim.tbl_deep_extend("force", capabilities, require('cmp_nvim_lsp').default_capabilities())
|
98 | 123 | '';
|
99 |
| - } |
| 124 | + }) |
| 125 | + ] |
| 126 | + # If the user has enabled the `foo` and `bar` sources, then `plugins` will look like: |
| 127 | + # { |
| 128 | + # cmp-foo.enable = true; |
| 129 | + # cmp-bar.enable = true; |
| 130 | + # } |
| 131 | + # |
| 132 | + # To avoid inf-rec, we have to define _all_ declared plugins, |
| 133 | + # outside of any conditional that depends on config.plugins. |
| 134 | + # We can use mkIf _within_ definitions though. |
| 135 | + ++ lib.pipe options.plugins [ |
| 136 | + (lib.flip builtins.removeAttrs [ |
| 137 | + # lspkind has its own `cmp` options, but isn't a nvim-cmp source |
| 138 | + "lspkind" |
| 139 | + ]) |
| 140 | + # Actual options are probably aliases, not plugins |
| 141 | + (lib.filterAttrs (_: opt: !lib.isOption opt)) |
| 142 | + (lib.filterAttrs (_: opt: opt ? cmp)) |
| 143 | + builtins.attrNames |
| 144 | + (builtins.map ( |
| 145 | + name: |
| 146 | + let |
| 147 | + inherit (config.plugins.${name}) cmp; |
| 148 | + in |
| 149 | + lib.mkIf ( |
| 150 | + cfg.enable |
| 151 | + && cfg.autoEnableSources |
| 152 | + # Avoid inf-rec by not auto-enabling sources that add themselves to sources? |
| 153 | + && !cmp.enable or false |
| 154 | + && builtins.elem cmp.name enabledSources |
| 155 | + ) { plugins.${name}.enable = true; } |
| 156 | + )) |
100 | 157 | ]
|
101 | 158 | );
|
102 | 159 | }
|
0 commit comments