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
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";

View file

@ -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;
}

View file

@ -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`.
'';