diff --git a/plugins/by-name/cmp-tabnine/default.nix b/plugins/by-name/cmp-tabnine/default.nix new file mode 100644 index 00000000..f671142e --- /dev/null +++ b/plugins/by-name/cmp-tabnine/default.nix @@ -0,0 +1,67 @@ +{ lib, ... }: +let + inherit (lib) types; + inherit (lib.nixvim) defaultNullOpts; +in +lib.nixvim.neovim-plugin.mkNeovimPlugin { + name = "cmp-tabnine"; + + maintainers = [ lib.maintainers.GaetanLepage ]; + + imports = [ + { cmpSourcePlugins.cmp_tabnine = "cmp-tabnine"; } + ]; + + deprecateExtraOptions = true; + + moduleName = "cmp_tabnine.config"; + setup = ":setup"; + + settingsOptions = { + max_lines = defaultNullOpts.mkUnsignedInt 1000 '' + How many lines of buffer context to pass to TabNine. + ''; + + max_num_results = defaultNullOpts.mkUnsignedInt 20 '' + How many results to return. + ''; + + sort = defaultNullOpts.mkBool true '' + Sort results by returned priority. + ''; + + run_on_every_keystroke = defaultNullOpts.mkBool true '' + Generate new completion items on every keystroke. + + For more info, check out [#18](https://github.com/tzachar/cmp-tabnine/issues/18). + ''; + + snippet_placeholder = defaultNullOpts.mkStr ".." '' + Indicates where the cursor will be placed in case a completion item is asnippet. + Any string is accepted. + + For this to work properly, you need to setup snippet support for `nvim-cmp`. + ''; + + ignored_file_types = defaultNullOpts.mkAttrsOf' { + type = types.bool; + pluginDefault = { }; + example = { + lua = true; + }; + description = '' + Which file types to ignore. + ''; + }; + + min_percent = defaultNullOpts.mkNullable (types.numbers.between 0 100) 0 '' + Eliminate items with a percentage less than `min_percent`. + ''; + }; + + settingsExample = { + max_lines = 600; + max_num_results = 10; + sort = false; + }; +} diff --git a/plugins/cmp/sources/cmp-tabnine.nix b/plugins/cmp/sources/cmp-tabnine.nix deleted file mode 100644 index d86104b8..00000000 --- a/plugins/cmp/sources/cmp-tabnine.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - lib, - config, - ... -}: -let - cfg = config.plugins.cmp-tabnine; -in -{ - options.plugins.cmp-tabnine = lib.nixvim.neovim-plugin.extraOptionsOptions; - - config = lib.mkIf cfg.enable { - extraConfigLua = '' - require('cmp_tabnine.config'):setup(${lib.nixvim.toLuaObject cfg.extraOptions}) - ''; - }; -} diff --git a/plugins/cmp/sources/default.nix b/plugins/cmp/sources/default.nix index c217b591..9b9c3b3f 100644 --- a/plugins/cmp/sources/default.nix +++ b/plugins/cmp/sources/default.nix @@ -141,10 +141,6 @@ let pluginName = "cmp-spell"; sourceName = "spell"; } - { - pluginName = "cmp-tabnine"; - sourceName = "cmp_tabnine"; - } { pluginName = "cmp-tmux"; sourceName = "tmux"; @@ -194,7 +190,6 @@ in # For extra cmp plugins imports = [ ./copilot-cmp.nix - ./cmp-tabnine.nix ./crates-nvim.nix ] ++ pluginModules; } diff --git a/tests/test-sources/plugins/by-name/cmp-tabnine/default.nix b/tests/test-sources/plugins/by-name/cmp-tabnine/default.nix new file mode 100644 index 00000000..c2763c4f --- /dev/null +++ b/tests/test-sources/plugins/by-name/cmp-tabnine/default.nix @@ -0,0 +1,49 @@ +{ lib, pkgs, ... }: +let + platform = pkgs.stdenv.hostPlatform; + + # tabnine is not available on aarch64-linux. + doRun = !(platform.isLinux && platform.isAarch64); +in +lib.optionalAttrs doRun { + empty = { + plugins = { + cmp.enable = true; + cmp-tabnine.enable = true; + }; + }; + + defaults = { + plugins = { + cmp.enable = true; + cmp-tabnine = { + enable = true; + + settings = { + max_lines = 1000; + max_num_results = 20; + sort = true; + run_on_every_keystroke = true; + snippet_placeholder = ".."; + ignored_file_types = { }; + min_percent = 0; + }; + }; + }; + }; + + example = { + plugins = { + cmp.enable = true; + cmp-tabnine = { + enable = true; + + settings = { + max_lines = 600; + max_num_results = 10; + sort = false; + }; + }; + }; + }; +}