From 9ed3538685b2c8a39d435eacaa5d26f2892939f5 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Tue, 18 Jun 2024 16:40:46 +0200 Subject: [PATCH] plugins/cmp-tabby: switch to RFC-42 style --- plugins/completion/cmp/sources/cmp-tabby.nix | 74 ++++++++++++------- .../plugins/completion/cmp-tabby.nix | 6 +- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/plugins/completion/cmp/sources/cmp-tabby.nix b/plugins/completion/cmp/sources/cmp-tabby.nix index 9f41b5bc..d967abe4 100644 --- a/plugins/completion/cmp/sources/cmp-tabby.nix +++ b/plugins/completion/cmp/sources/cmp-tabby.nix @@ -11,37 +11,59 @@ in { meta.maintainers = [ maintainers.GaetanLepage ]; - options.plugins.cmp-tabby = helpers.neovim-plugin.extraOptionsOptions // { - host = helpers.defaultNullOpts.mkStr "http://localhost:5000" '' - The address of the tabby host server. - ''; + # TODO: introduced 24-06-18, remove after 24.11 + imports = + let + basePluginPath = [ + "plugins" + "cmp-tabby" + ]; + settingsPath = basePluginPath ++ [ "settings" ]; + in + [ + (mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath) + (mkRenamedOptionModule (basePluginPath ++ [ "host" ]) (settingsPath ++ [ "host" ])) + (mkRenamedOptionModule (basePluginPath ++ [ "maxLines" ]) (settingsPath ++ [ "max_lines" ])) + (mkRenamedOptionModule (basePluginPath ++ [ "runOnEveryKeyStroke" ]) ( + settingsPath ++ [ "run_on_every_keystroke" ] + )) + (mkRenamedOptionModule (basePluginPath ++ [ "stop" ]) (settingsPath ++ [ "stop" ])) + ]; - maxLines = helpers.defaultNullOpts.mkUnsignedInt 100 '' - The max number of lines to complete. - ''; + options.plugins.cmp-tabby = { + settings = helpers.mkSettingsOption { + description = "Options provided to the `require('cmp_ai.config'):setup` function."; - runOnEveryKeyStroke = helpers.defaultNullOpts.mkBool true '' - Whether to run the completion on every keystroke. - ''; + options = { + host = helpers.defaultNullOpts.mkStr "http://localhost:5000" '' + The address of the tabby host server. + ''; - stop = helpers.defaultNullOpts.mkListOf types.str ''["\n"]'' ""; + max_lines = helpers.defaultNullOpts.mkUnsignedInt 100 '' + The max number of lines to complete. + ''; + + run_on_every_keystroke = helpers.defaultNullOpts.mkBool true '' + Whether to run the completion on every keystroke. + ''; + + stop = helpers.defaultNullOpts.mkListOf types.str [ "\n" ] '' + Stop character. + ''; + }; + + example = { + host = "http://localhost:5000"; + max_lines = 100; + run_on_every_keystroke = true; + stop = [ "\n" ]; + }; + }; }; config = mkIf cfg.enable { - extraConfigLua = - let - setupOptions = - with cfg; - { - inherit host; - max_lines = maxLines; - run_on_every_keystroke = runOnEveryKeyStroke; - inherit stop; - } - // cfg.extraOptions; - in - '' - require('cmp_tabby.config'):setup(${helpers.toLuaObject setupOptions}) - ''; + extraConfigLua = '' + require('cmp_tabby.config'):setup(${helpers.toLuaObject cfg.settings}) + ''; }; } diff --git a/tests/test-sources/plugins/completion/cmp-tabby.nix b/tests/test-sources/plugins/completion/cmp-tabby.nix index 215b206f..e9816b95 100644 --- a/tests/test-sources/plugins/completion/cmp-tabby.nix +++ b/tests/test-sources/plugins/completion/cmp-tabby.nix @@ -12,10 +12,10 @@ enable = true; settings.sources = [ { name = "cmp_tabby"; } ]; }; - cmp-tabby = { + cmp-tabby.settings = { host = "http://localhost:5000"; - maxLines = 100; - runOnEveryKeyStroke = true; + max_lines = 100; + run_on_every_keystroke = true; stop = [ "\n" ]; }; };