nvim-cmp: add default sorting

This commit is contained in:
diniamo 2024-10-06 21:54:11 +02:00
parent 2e07db7efc
commit 2f75849924
3 changed files with 39 additions and 9 deletions

View file

@ -1,7 +1,7 @@
{lib}: let {lib}: let
inherit (lib) isStringLike showOption showFiles getFiles mergeOneOption mergeEqualOption mkOptionType; inherit (lib.options) showOption showFiles getFiles mergeOneOption mergeEqualOption;
inherit (lib.strings) isString; inherit (lib.strings) isString isStringLike;
inherit (lib.types) anything attrsOf; inherit (lib.types) anything attrsOf listOf mkOptionType;
inherit (lib.nvim.types) anythingConcatLists; inherit (lib.nvim.types) anythingConcatLists;
inherit (builtins) typeOf isAttrs any head concatLists stringLength match; inherit (builtins) typeOf isAttrs any head concatLists stringLength match;
in { in {
@ -52,6 +52,8 @@ in {
(mergeFunctions.${commonType} or mergeEqualOption) loc defs; (mergeFunctions.${commonType} or mergeEqualOption) loc defs;
}; };
mergelessListOf = elemType: listOf elemType // {merge = mergeEqualOption;};
char = mkOptionType { char = mkOptionType {
name = "char"; name = "char";
description = "character"; description = "character";

View file

@ -6,10 +6,10 @@
typesDag = import ./dag.nix {inherit lib;}; typesDag = import ./dag.nix {inherit lib;};
typesPlugin = import ./plugins.nix {inherit inputs lib;}; typesPlugin = import ./plugins.nix {inherit inputs lib;};
typesLanguage = import ./languages.nix {inherit lib;}; typesLanguage = import ./languages.nix {inherit lib;};
typesTypes = import ./types.nix {inherit lib;}; customTypes = import ./custom.nix {inherit lib;};
in { in {
inherit (typesDag) dagOf; inherit (typesDag) dagOf;
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType;
inherit (typesLanguage) diagnostics mkGrammarOption; inherit (typesLanguage) diagnostics mkGrammarOption;
inherit (typesTypes) anythingConcatLists char hexColor; inherit (customTypes) anythingConcatLists char hexColor mergelessListOf;
} }

View file

@ -4,11 +4,12 @@
... ...
}: let }: let
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; 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.generators) mkLuaInline;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) isString;
cfg = config.vim.autocomplete.nvim-cmp; cfg = config.vim.autocomplete.nvim-cmp;
in { in {
@ -24,6 +25,32 @@ in {
See `:help completeopt` for the complete list. 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 = { mappings = {
@ -53,8 +80,9 @@ in {
``` ```
''; '';
description = '' description = ''
The function used to customize the completion menu entires. The function used to customize the completion menu entires. This is
This is outside of `setupOpts` because of internal reasons. outside of `setupOpts` because of internal reasons, make sure to use
this one, instead of its `setupOpts` equivalent.
See `:help cmp-config.formatting.format`. See `:help cmp-config.formatting.format`.
''; '';