|
14 | 14 | applyExtraConfig = "It has been moved to `lib.plugins.utils`";
|
15 | 15 | mkConfigAt = "It has been moved to `lib.plugins.utils`";
|
16 | 16 | };
|
| 17 | + internal = lib.mkOption { internal = true; }; |
17 | 18 | in
|
18 | 19 | {
|
19 | 20 | # Evaluate nixvim modules, checking warnings and assertions
|
|
52 | 53 | helpers = self;
|
53 | 54 | } // extraSpecialArgs;
|
54 | 55 | };
|
| 56 | + |
| 57 | + # Create a module configuring a plugin's integration with blink.cmp |
| 58 | + mkBlinkPluginModule = |
| 59 | + { |
| 60 | + # The plugin's option location-path |
| 61 | + loc ? [ |
| 62 | + "plugins" |
| 63 | + pluginName |
| 64 | + ], |
| 65 | + # Name of the plugin, used in documentation |
| 66 | + pluginName, |
| 67 | + # Name of the module blink should import |
| 68 | + # i.e. `sources.providers.<name>.module` |
| 69 | + module ? pluginName, |
| 70 | + # The default for `blink.settings.name` |
| 71 | + # i.e. `sources.providers.<name>.name` |
| 72 | + # TODO: consider doing some pre-processing to the default source name, |
| 73 | + # e.g. removing `-cmp` or `blink-` prefix/suffix? |
| 74 | + sourceName, |
| 75 | + # The default for `blink.key` |
| 76 | + # i.e. the attr name for `sources.providers.<name>` |
| 77 | + key ? lib.strings.toLower sourceName, |
| 78 | + # Whether to enable the blink completion provider by default |
| 79 | + enableProvider ? true, |
| 80 | + # Defaults for the corresponding source options |
| 81 | + enableDefault ? true, |
| 82 | + enableCmdline ? false, |
| 83 | + enabledFiletypes ? { }, |
| 84 | + # Whether the plugin's settings should be used as the provider's `opts` |
| 85 | + usePluginSettings ? true, |
| 86 | + settingsExample ? { |
| 87 | + score_offset = -7; |
| 88 | + fallbacks = [ ]; |
| 89 | + }, |
| 90 | + }: |
| 91 | + { config, options, ... }: |
| 92 | + let |
| 93 | + pluginCfg = lib.getAttrFromPath loc config; |
| 94 | + cfg = pluginCfg.blink; |
| 95 | + pluginOpts = lib.getAttrFromPath loc options; |
| 96 | + opt = pluginOpts.blink; |
| 97 | + in |
| 98 | + { |
| 99 | + options = lib.setAttrByPath loc { |
| 100 | + blink = { |
| 101 | + enable = lib.mkOption { |
| 102 | + type = lib.types.bool; |
| 103 | + default = enableProvider; |
| 104 | + example = !enableProvider; |
| 105 | + description = '' |
| 106 | + Whether to integrate this plugin with blink.cmp. |
| 107 | + ''; |
| 108 | + }; |
| 109 | + key = lib.mkOption { |
| 110 | + type = lib.types.str; |
| 111 | + default = key; |
| 112 | + description = '' |
| 113 | + The key to use for ${pluginName}'s blink.cmp provider. |
| 114 | + This is the id you should use when including this provider in completion source lists. |
| 115 | + Must be unique. |
| 116 | + ''; |
| 117 | + }; |
| 118 | + default = lib.mkOption { |
| 119 | + type = lib.types.bool; |
| 120 | + default = enableDefault; |
| 121 | + example = !enableDefault; |
| 122 | + description = '' |
| 123 | + Whether to include this plugin in the `default` completion source list. |
| 124 | + ''; |
| 125 | + }; |
| 126 | + cmdline = lib.mkOption { |
| 127 | + type = lib.types.bool; |
| 128 | + default = enableCmdline; |
| 129 | + example = !enableCmdline; |
| 130 | + description = '' |
| 131 | + Whether to include this plugin in the `cmdline` completion source list. |
| 132 | + ''; |
| 133 | + }; |
| 134 | + filetypes = lib.mkOption { |
| 135 | + type = lib.types.attrsOf lib.types.bool; |
| 136 | + # Only include `true` attrs in the final value |
| 137 | + apply = lib.filterAttrs (_: lib.id); |
| 138 | + default = enabledFiletypes; |
| 139 | + # TODO: example |
| 140 | + description = '' |
| 141 | + Whether to include this plugin in the specific `per_filetype` completion source lists. |
| 142 | + ''; |
| 143 | + }; |
| 144 | + settings = lib.mkOption { |
| 145 | + default = { }; |
| 146 | + description = '' |
| 147 | + Settings for the blink.cmp completion provider. |
| 148 | + ''; |
| 149 | + example = settingsExample; |
| 150 | + type = lib.types.submodule [ |
| 151 | + { |
| 152 | + options.enabled = internal; |
| 153 | + options.module = internal; |
| 154 | + } |
| 155 | + ../plugins/by-name/blink-cmp/provider-config.nix |
| 156 | + ]; |
| 157 | + }; |
| 158 | + }; |
| 159 | + }; |
| 160 | + config = lib.mkMerge [ |
| 161 | + (lib.setAttrByPath loc { |
| 162 | + # NOTE: this could be defined within the `blink.settings` submodule, |
| 163 | + # but that would not populate the option's `definitions` list. |
| 164 | + # Meaning we wouldn't be able to propagate the definitions further using `mkAliasDefinitions`. |
| 165 | + blink.settings = { |
| 166 | + name = lib.mkDefault sourceName; |
| 167 | + inherit module; |
| 168 | + opts = lib.mkIf usePluginSettings (lib.modules.mkAliasDefinitions pluginOpts.settings); |
| 169 | + }; |
| 170 | + }) |
| 171 | + (lib.mkIf (pluginCfg.enable && cfg.enable) { |
| 172 | + plugins.blink-cmp.settings.sources = { |
| 173 | + # Use mkAliasDefinitions to preserve override priorities |
| 174 | + providers.${cfg.key} = lib.modules.mkAliasDefinitions opt.settings; |
| 175 | + default = lib.mkIf cfg.default [ cfg.key ]; |
| 176 | + # FIXME: the reference shows `cmdline` should/could be defined as a function |
| 177 | + # https://cmp.saghen.dev/configuration/reference.html#sources |
| 178 | + cmdline = lib.mkIf cfg.cmdline [ cfg.key ]; |
| 179 | + per_filetype = lib.mkIf (cfg.filetypes != { }) ( |
| 180 | + builtins.mapAttrs (_: _: [ cfg.key ]) cfg.filetypes |
| 181 | + ); |
| 182 | + }; |
| 183 | + warnings = lib.nixvim.mkWarnings (lib.showOption loc) { |
| 184 | + when = !config.plugins.blink-cmp.enable && options.plugins.blink-cmp.enable.highestPrio == 1500; |
| 185 | + message = '' |
| 186 | + You have enabled the blink.cmp provider, but `plugins.blink-cmp` is not enabled. |
| 187 | + You can suppress this warning by explicitly setting `plugins.blink-cmp.enable = false`. |
| 188 | + ''; |
| 189 | + }; |
| 190 | + }) |
| 191 | + ]; |
| 192 | + }; |
55 | 193 | }
|
56 | 194 | // lib.mapAttrs (
|
57 | 195 | name: msg:
|
|
0 commit comments