mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-07 19:01:35 +00:00
treewide: rewrite autocompletion module and related stuff (#404)
* modules/completion: rewrite * treewide: remove vsnip, add luasnip * nvim-cmp: add default sorting * nvim-cmp: load after luasnip * lib: fix docs for mergelessListOf * docs: add changelog entires for rewrite * deprecations: add rewrite deprecations * nvim-cmp: clarify in format description * docs: fix option reference in release notes * treewide: remove reduant `// {default = false;}`s * luasnip: add missing `{option}` for option reference * deprecations: add entry for vsnip * nvim-autopairs: use multiline string * nvim-dap: use outer attribute
This commit is contained in:
parent
ef413736e9
commit
7dbd1cd8d1
33 changed files with 512 additions and 483 deletions
|
@ -1,72 +1,103 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib.options) mkEnableOption mkOption literalMD;
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD;
|
||||
inherit (lib.types) str attrsOf nullOr either;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.binds) mkMappingOption;
|
||||
inherit (lib.types) enum attrsOf nullOr str bool;
|
||||
inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (builtins) isString;
|
||||
|
||||
cfg = config.vim.autocomplete.nvim-cmp;
|
||||
in {
|
||||
options.vim = {
|
||||
autocomplete = {
|
||||
enable = mkEnableOption "autocomplete" // {default = false;};
|
||||
|
||||
alwaysComplete = mkOption {
|
||||
type = bool;
|
||||
description = "Automatically show completion.";
|
||||
default = true;
|
||||
};
|
||||
|
||||
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>";
|
||||
};
|
||||
|
||||
type = mkOption {
|
||||
type = enum ["nvim-cmp"];
|
||||
default = "nvim-cmp";
|
||||
description = "Set the autocomplete plugin. Options: [nvim-cmp]";
|
||||
};
|
||||
|
||||
sources = mkOption {
|
||||
options.vim.autocomplete.nvim-cmp = {
|
||||
enable = mkEnableOption "nvim-cmp";
|
||||
setupOpts = mkPluginSetupOption "the autocomplete plugin" {
|
||||
completion.completeopt = mkOption {
|
||||
type = str;
|
||||
default = "menu,menuone,noinsert";
|
||||
description = ''
|
||||
Attribute set of source names for nvim-cmp.
|
||||
A comma-separated list of options for completion.
|
||||
|
||||
If an attribute set is provided, then the menu value of
|
||||
`vim_item` in the format will be set to the value (if
|
||||
utilizing the `nvim_cmp_menu_map` function).
|
||||
|
||||
Note: only use a single attribute name per attribute set
|
||||
'';
|
||||
type = attrsOf (nullOr str);
|
||||
default = {};
|
||||
example = ''
|
||||
{nvim-cmp = null; buffer = "[Buffer]";}
|
||||
See `:help completeopt` for the complete list.
|
||||
'';
|
||||
};
|
||||
|
||||
formatting = {
|
||||
format = mkOption {
|
||||
description = ''
|
||||
The function used to customize the appearance of the completion menu.
|
||||
sorting.comparators = mkOption {
|
||||
type = mergelessListOf (either str luaInline);
|
||||
default = [
|
||||
"offset"
|
||||
"exact"
|
||||
"score"
|
||||
"kind"
|
||||
"length"
|
||||
"sort_text"
|
||||
];
|
||||
description = ''
|
||||
The comparator functions used for sorting completions.
|
||||
|
||||
If [](#opt-vim.lsp.lspkind.enable) is true, then the function
|
||||
will be called before modifications from lspkind.
|
||||
|
||||
Default is to call the menu mapping function.
|
||||
'';
|
||||
type = str;
|
||||
default = "nvim_cmp_menu_map";
|
||||
example = literalMD ''
|
||||
```lua
|
||||
function(entry, vim_item)
|
||||
return vim_item
|
||||
end
|
||||
```
|
||||
'';
|
||||
};
|
||||
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 = {
|
||||
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>";
|
||||
};
|
||||
|
||||
format = mkOption {
|
||||
type = luaInline;
|
||||
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 = ''
|
||||
The function used to customize the completion menu entires. This is
|
||||
outside of `setupOpts` to allow for an easier integration with
|
||||
lspkind.nvim.
|
||||
|
||||
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]";
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue