From a61193abcc00f54a1313c6a218123afc5871ce65 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Wed, 18 Dec 2024 18:55:45 +0100 Subject: [PATCH] plugins/cmp-ai: move to by-name --- plugins/by-name/cmp-ai/default.nix | 89 +++++++++++++++++ plugins/cmp/sources/cmp-ai.nix | 95 ------------------- plugins/cmp/sources/default.nix | 5 - .../cmp-ai.nix => by-name/cmp-ai/default.nix} | 0 4 files changed, 89 insertions(+), 100 deletions(-) create mode 100644 plugins/by-name/cmp-ai/default.nix delete mode 100644 plugins/cmp/sources/cmp-ai.nix rename tests/test-sources/plugins/{cmp/cmp-ai.nix => by-name/cmp-ai/default.nix} (100%) diff --git a/plugins/by-name/cmp-ai/default.nix b/plugins/by-name/cmp-ai/default.nix new file mode 100644 index 00000000..0a1f55c8 --- /dev/null +++ b/plugins/by-name/cmp-ai/default.nix @@ -0,0 +1,89 @@ +{ + lib, + ... +}: +let + inherit (lib.nixvim) defaultNullOpts; +in +lib.nixvim.neovim-plugin.mkNeovimPlugin { + name = "cmp-ai"; + + maintainers = [ lib.maintainers.GaetanLepage ]; + + imports = [ + { cmpSourcePlugins.cmp_ai = "cmp-ai"; } + ]; + + moduleName = "cmp_ai.config"; + setup = ":setup"; + + settingsOptions = { + max_lines = defaultNullOpts.mkUnsignedInt 50 '' + How many lines of buffer context to use. + ''; + + run_on_every_keystroke = defaultNullOpts.mkBool true '' + Generate new completion items on every keystroke. + ''; + + provider = defaultNullOpts.mkStr "HF" '' + Which AI provider to use. + + Check the [README](https://github.com/tzachar/cmp-ai/blob/main/README.md) to learn about + available options. + ''; + + provider_options = defaultNullOpts.mkAttrsOf lib.types.anything { } '' + Options to forward to the provider. + ''; + + notify = defaultNullOpts.mkBool true '' + As some completion sources can be quit slow, setting this to `true` will trigger a + notification when a completion starts and ends using `vim.notify`. + ''; + + notify_callback = defaultNullOpts.mkLuaFn' { + description = '' + The default notify function uses `vim.notify`, but an override can be configured. + ''; + pluginDefault = '' + function(msg) + vim.notify(msg) + end + ''; + example = '' + function(msg) + require('notify').notify(msg, vim.log.levels.INFO, { + title = 'OpenAI', + render = 'compact', + }) + end + ''; + }; + + ignored_file_types = defaultNullOpts.mkAttrsOf' { + type = lib.types.bool; + description = "Which filetypes to ignore."; + pluginDefault = { }; + example = { + lua = true; + html = true; + }; + }; + }; + + settingsExample = { + max_lines = 1000; + provider = "HF"; + notify = true; + notify_callback = '' + function(msg) + vim.notify(msg) + end + ''; + run_on_every_keystroke = true; + ignored_file_types = { + lua = true; + }; + }; +} diff --git a/plugins/cmp/sources/cmp-ai.nix b/plugins/cmp/sources/cmp-ai.nix deleted file mode 100644 index 0fe76899..00000000 --- a/plugins/cmp/sources/cmp-ai.nix +++ /dev/null @@ -1,95 +0,0 @@ -{ - lib, - config, - ... -}: -let - inherit (lib.nixvim) defaultNullOpts; - - cfg = config.plugins.cmp-ai; -in -{ - meta.maintainers = [ lib.maintainers.GaetanLepage ]; - - options.plugins.cmp-ai = { - settings = lib.nixvim.mkSettingsOption { - description = "Options provided to the `require('cmp_ai.config'):setup` function."; - - options = { - max_lines = defaultNullOpts.mkUnsignedInt 50 '' - How many lines of buffer context to use. - ''; - - run_on_every_keystroke = defaultNullOpts.mkBool true '' - Generate new completion items on every keystroke. - ''; - - provider = defaultNullOpts.mkStr "HF" '' - Which AI provider to use. - - Check the [README](https://github.com/tzachar/cmp-ai/blob/main/README.md) to learn about - available options. - ''; - - provider_options = defaultNullOpts.mkAttrsOf lib.types.anything { } '' - Options to forward to the provider. - ''; - - notify = defaultNullOpts.mkBool true '' - As some completion sources can be quit slow, setting this to `true` will trigger a - notification when a completion starts and ends using `vim.notify`. - ''; - - notify_callback = defaultNullOpts.mkLuaFn' { - description = '' - The default notify function uses `vim.notify`, but an override can be configured. - ''; - pluginDefault = '' - function(msg) - vim.notify(msg) - end - ''; - example = '' - function(msg) - require('notify').notify(msg, vim.log.levels.INFO, { - title = 'OpenAI', - render = 'compact', - }) - end - ''; - }; - - ignored_file_types = defaultNullOpts.mkAttrsOf' { - type = lib.types.bool; - description = "Which filetypes to ignore."; - pluginDefault = { }; - example = { - lua = true; - html = true; - }; - }; - }; - - example = { - max_lines = 1000; - provider = "HF"; - notify = true; - notify_callback = '' - function(msg) - vim.notify(msg) - end - ''; - run_on_every_keystroke = true; - ignored_file_types = { - lua = true; - }; - }; - }; - }; - - config = lib.mkIf cfg.enable { - extraConfigLua = '' - require('cmp_ai.config'):setup(${lib.nixvim.toLuaObject cfg.settings}) - ''; - }; -} diff --git a/plugins/cmp/sources/default.nix b/plugins/cmp/sources/default.nix index 37221104..54227f6a 100644 --- a/plugins/cmp/sources/default.nix +++ b/plugins/cmp/sources/default.nix @@ -10,10 +10,6 @@ let # More complex cmp sources can instead be defined as their own plugin # and register their source-name association using the `cmpSourcePlugins` option. sources = [ - { - pluginName = "cmp-ai"; - sourceName = "cmp_ai"; - } { pluginName = "cmp-async-path"; sourceName = "async_path"; @@ -202,7 +198,6 @@ in # For extra cmp plugins imports = [ ./copilot-cmp.nix - ./cmp-ai.nix ./cmp-git.nix ./cmp-tabnine.nix ./crates-nvim.nix diff --git a/tests/test-sources/plugins/cmp/cmp-ai.nix b/tests/test-sources/plugins/by-name/cmp-ai/default.nix similarity index 100% rename from tests/test-sources/plugins/cmp/cmp-ai.nix rename to tests/test-sources/plugins/by-name/cmp-ai/default.nix