diff --git a/lib/types/types.nix b/lib/types/custom.nix similarity index 89% rename from lib/types/types.nix rename to lib/types/custom.nix index 250d7636..c4e20b64 100644 --- a/lib/types/types.nix +++ b/lib/types/custom.nix @@ -1,7 +1,7 @@ {lib}: let - inherit (lib) isStringLike showOption showFiles getFiles mergeOneOption mergeEqualOption mkOptionType; - inherit (lib.strings) isString; - inherit (lib.types) anything attrsOf; + inherit (lib.options) showOption showFiles getFiles mergeOneOption mergeEqualOption; + inherit (lib.strings) isString isStringLike; + inherit (lib.types) anything attrsOf listOf mkOptionType; inherit (lib.nvim.types) anythingConcatLists; inherit (builtins) typeOf isAttrs any head concatLists stringLength match; in { @@ -52,6 +52,8 @@ in { (mergeFunctions.${commonType} or mergeEqualOption) loc defs; }; + mergelessListOf = elemType: listOf elemType // {merge = mergeEqualOption;}; + char = mkOptionType { name = "char"; description = "character"; diff --git a/lib/types/default.nix b/lib/types/default.nix index 70ca6bef..73b35956 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -6,10 +6,10 @@ typesDag = import ./dag.nix {inherit lib;}; typesPlugin = import ./plugins.nix {inherit inputs lib;}; typesLanguage = import ./languages.nix {inherit lib;}; - typesTypes = import ./types.nix {inherit lib;}; + customTypes = import ./custom.nix {inherit lib;}; in { inherit (typesDag) dagOf; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; inherit (typesLanguage) diagnostics mkGrammarOption; - inherit (typesTypes) anythingConcatLists char hexColor; + inherit (customTypes) anythingConcatLists char hexColor mergelessListOf; } diff --git a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix index 1f74fbb7..6f6b1863 100644 --- a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix +++ b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix @@ -4,11 +4,12 @@ ... }: let inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; - inherit (lib.types) str attrsOf nullOr; + inherit (lib.types) str attrsOf nullOr either; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.binds) mkMappingOption; - inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf; inherit (lib.nvim.lua) toLuaObject; + inherit (builtins) isString; cfg = config.vim.autocomplete.nvim-cmp; in { @@ -24,6 +25,32 @@ in { See `:help completeopt` for the complete list. ''; }; + + sorting.comparators = mkOption { + type = mergelessListOf (either str luaInline); + default = [ + "offset" + "exact" + "score" + "kind" + "length" + "sort_text" + ]; + description = '' + The comparator functions used for sorting completions. + + You can either pass a valid inline lua function + (see `:help cmp-config.sorting.comparators`), + or a string, in which case the builtin comparator with that name will + be used. + ''; + apply = map ( + c: + if isString c + then mkLuaInline ("cmp.config.compare." + c) + else c + ); + }; }; mappings = { @@ -53,8 +80,9 @@ in { ``` ''; description = '' - The function used to customize the completion menu entires. - This is outside of `setupOpts` because of internal reasons. + The function used to customize the completion menu entires. This is + outside of `setupOpts` because of internal reasons, make sure to use + this one, instead of its `setupOpts` equivalent. See `:help cmp-config.formatting.format`. '';