2024-10-09 17:50:34 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD;
|
2024-11-04 15:50:50 +00:00
|
|
|
inherit (lib.types) str attrsOf nullOr either listOf;
|
2024-10-09 17:50:34 +00:00
|
|
|
inherit (lib.generators) mkLuaInline;
|
2024-02-26 05:05:23 +00:00
|
|
|
inherit (lib.nvim.binds) mkMappingOption;
|
2024-11-04 15:50:50 +00:00
|
|
|
inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf pluginType;
|
2024-10-09 17:50:34 +00:00
|
|
|
inherit (lib.nvim.lua) toLuaObject;
|
|
|
|
inherit (builtins) isString;
|
2023-02-27 14:52:43 +00:00
|
|
|
|
2024-10-09 17:50:34 +00:00
|
|
|
cfg = config.vim.autocomplete.nvim-cmp;
|
|
|
|
in {
|
|
|
|
options.vim.autocomplete.nvim-cmp = {
|
|
|
|
enable = mkEnableOption "nvim-cmp";
|
|
|
|
setupOpts = mkPluginSetupOption "the autocomplete plugin" {
|
|
|
|
completion.completeopt = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "menu,menuone,noinsert";
|
|
|
|
description = ''
|
|
|
|
A comma-separated list of options for completion.
|
2023-04-22 15:43:58 +00:00
|
|
|
|
2024-10-09 17:50:34 +00:00
|
|
|
See `:help completeopt` for the complete list.
|
|
|
|
'';
|
2023-02-27 14:52:43 +00:00
|
|
|
};
|
2023-04-17 20:27:27 +00:00
|
|
|
|
2024-10-09 17:50:34 +00:00
|
|
|
sorting.comparators = mkOption {
|
|
|
|
type = mergelessListOf (either str luaInline);
|
|
|
|
default = [
|
2024-11-04 08:34:16 +00:00
|
|
|
(mkLuaInline "deprio(kinds.Text)")
|
|
|
|
(mkLuaInline "deprio(kinds.Snippet)")
|
2024-10-09 17:50:34 +00:00
|
|
|
"offset"
|
|
|
|
"exact"
|
|
|
|
"score"
|
|
|
|
"kind"
|
|
|
|
"length"
|
|
|
|
"sort_text"
|
|
|
|
];
|
2023-11-04 11:30:04 +00:00
|
|
|
description = ''
|
2024-10-09 17:50:34 +00:00
|
|
|
The comparator functions used for sorting completions.
|
2023-04-17 22:48:44 +00:00
|
|
|
|
2024-10-09 17:50:34 +00:00
|
|
|
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.
|
2024-11-04 08:34:16 +00:00
|
|
|
|
|
|
|
A `deprio` function and a `kinds`
|
|
|
|
(`require("cmp.types").lsp.CompletionItemKind`) variable is provided
|
2024-11-26 07:36:39 +00:00
|
|
|
above `setupOpts`. By passing a type to the function, the returned
|
2024-11-04 08:34:16 +00:00
|
|
|
function will be a comparator that always ranks the specified kind the
|
|
|
|
lowest.
|
2023-04-17 22:48:44 +00:00
|
|
|
'';
|
2024-10-09 17:50:34 +00:00
|
|
|
apply = map (
|
|
|
|
c:
|
|
|
|
if isString c
|
|
|
|
then mkLuaInline ("cmp.config.compare." + c)
|
|
|
|
else c
|
|
|
|
);
|
2023-04-17 22:48:44 +00:00
|
|
|
};
|
2024-10-09 17:50:34 +00:00
|
|
|
};
|
2023-04-17 22:48:44 +00:00
|
|
|
|
2024-10-09 17:50:34 +00:00
|
|
|
mappings = {
|
|
|
|
complete = mkMappingOption "Complete [nvim-cmp]" "<C-Space>";
|
|
|
|
confirm = mkMappingOption "Confirm [nvim-cmp]" "<CR>";
|
|
|
|
next = mkMappingOption "Next item [nvim-cmp]" "<Tab>";
|
|
|
|
previous = mkMappingOption "Previous item [nvim-cmp]" "<S-Tab>";
|
|
|
|
close = mkMappingOption "Close [nvim-cmp]" "<C-e>";
|
|
|
|
scrollDocsUp = mkMappingOption "Scroll docs up [nvim-cmp]" "<C-d>";
|
|
|
|
scrollDocsDown = mkMappingOption "Scroll docs down [nvim-cmp]" "<C-f>";
|
|
|
|
};
|
2023-04-17 22:48:44 +00:00
|
|
|
|
2024-10-09 17:50:34 +00:00
|
|
|
format = mkOption {
|
2024-11-12 21:35:03 +00:00
|
|
|
type = nullOr luaInline;
|
2024-10-09 17:50:34 +00:00
|
|
|
default = mkLuaInline ''
|
|
|
|
function(entry, vim_item)
|
|
|
|
vim_item.menu = (${toLuaObject cfg.sources})[entry.source.name]
|
|
|
|
return vim_item
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
defaultText = literalMD ''
|
|
|
|
```lua
|
|
|
|
function(entry, vim_item)
|
|
|
|
vim_item.menu = (''${toLuaObject config.vim.autocomplete.nvim-cmp.sources})[entry.source.name]
|
|
|
|
return vim_item
|
|
|
|
end
|
|
|
|
```
|
|
|
|
'';
|
|
|
|
description = ''
|
2024-11-26 07:36:39 +00:00
|
|
|
The function used to customize the completion menu entries. This is
|
2024-10-09 17:50:34 +00:00
|
|
|
outside of `setupOpts` to allow for an easier integration with
|
|
|
|
lspkind.nvim.
|
2023-04-17 22:48:44 +00:00
|
|
|
|
2024-10-09 17:50:34 +00:00
|
|
|
See `:help cmp-config.formatting.format`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sources = mkOption {
|
|
|
|
type = attrsOf (nullOr str);
|
|
|
|
default = {};
|
|
|
|
description = "The list of sources used by nvim-cmp";
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
nvim-cmp = null;
|
|
|
|
buffer = "[Buffer]";
|
|
|
|
}
|
|
|
|
'';
|
2023-02-27 14:52:43 +00:00
|
|
|
};
|
2024-11-04 15:50:50 +00:00
|
|
|
|
|
|
|
sourcePlugins = mkOption {
|
|
|
|
type = listOf pluginType;
|
|
|
|
default = [];
|
|
|
|
description = "List of source plugins used by nvim-cmp.";
|
|
|
|
};
|
2023-02-27 14:52:43 +00:00
|
|
|
};
|
|
|
|
}
|