nix-community.nixvim/plugins/cmp/options/settings-options.nix

318 lines
9.4 KiB
Nix
Raw Permalink Normal View History

2024-10-06 10:05:31 -05:00
{ lib }:
2024-10-06 09:57:31 -05:00
let
inherit (lib) mkOption types;
2024-10-06 10:05:31 -05:00
inherit (lib.nixvim) defaultNullOpts;
2024-10-06 09:57:31 -05:00
in
{
performance = {
2024-10-06 10:05:31 -05:00
debounce = defaultNullOpts.mkUnsignedInt 60 ''
Sets debounce time.
This is the interval used to group up completions from different sources for filtering and
displaying.
'';
2024-10-06 10:05:31 -05:00
throttle = defaultNullOpts.mkUnsignedInt 30 ''
Sets throttle time.
This is used to delay filtering and displaying completions.
'';
2024-10-06 10:05:31 -05:00
fetching_timeout = defaultNullOpts.mkUnsignedInt 500 ''
Sets the timeout of candidate fetching process.
The nvim-cmp will wait to display the most prioritized source.
'';
2024-10-06 10:05:31 -05:00
confirm_resolve_timeout = defaultNullOpts.mkUnsignedInt 80 ''
Sets the timeout for resolving item before confirmation.
'';
2024-10-06 10:05:31 -05:00
async_budget = defaultNullOpts.mkUnsignedInt 1 ''
Maximum time (in ms) an async function is allowed to run during one step of the event loop.
'';
2024-10-06 10:05:31 -05:00
max_view_entries = defaultNullOpts.mkUnsignedInt 200 ''
Maximum number of items to show in the entries list.
'';
};
2024-10-06 10:05:31 -05:00
preselect = defaultNullOpts.mkLua "cmp.PreselectMode.Item" ''
- "cmp.PreselectMode.Item": nvim-cmp will preselect the item that the source specified.
- "cmp.PreselectMode.None": nvim-cmp will not preselect any items.
'';
mapping = mkOption {
2024-05-05 19:39:35 +02:00
default = { };
2024-09-27 08:07:20 +01:00
type = with lib.types; maybeRaw (attrsOf strLua);
description = ''
cmp mappings declaration.
See `:h cmp-mapping` for more information.
'';
example = {
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
"<C-f>" = "cmp.mapping.scroll_docs(4)";
"<C-Space>" = "cmp.mapping.complete()";
"<C-e>" = "cmp.mapping.close()";
"<Tab>" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})";
"<S-Tab>" = "cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's'})";
"<CR>" = "cmp.mapping.confirm({ select = true })";
};
};
snippet = {
expand = mkOption {
2024-09-27 08:07:20 +01:00
type = with lib.types; nullOr strLuaFn;
default = null;
description = ''
The snippet expansion function. That's how nvim-cmp interacts with a particular snippet
engine.
Common engines:
```lua
function(args)
# vsnip
vim.fn["vsnip#anonymous"](args.body)
# luasnip
require('luasnip').lsp_expand(args.body)
# snippy
require('snippy').expand_snippet(args.body)
# ultisnips
vim.fn["UltiSnips#Anon"](args.body)
end
```
You can also provide a custom function:
```lua
function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end
```
'';
example = ''
function(args)
require('luasnip').lsp_expand(args.body)
end
'';
};
};
completion = {
2024-10-06 10:05:31 -05:00
keyword_length = defaultNullOpts.mkUnsignedInt 1 ''
The number of characters needed to trigger auto-completion.
'';
2024-10-06 10:05:31 -05:00
keyword_pattern = defaultNullOpts.mkLua ''[[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]]'' "The default keyword pattern.";
autocomplete =
2024-10-06 10:05:31 -05:00
defaultNullOpts.mkNullable (with lib.types; either (enum [ false ]) (listOf strLua))
[ "require('cmp.types').cmp.TriggerEvent.TextChanged" ]
2024-05-05 19:39:35 +02:00
''
The event to trigger autocompletion.
If set to `false`, then completion is only invoked manually (e.g. by calling `cmp.complete`).
'';
2024-10-06 10:05:31 -05:00
completeopt = defaultNullOpts.mkStr "menu,menuone,noselect" ''
Like vim's completeopt setting.
In general, you don't need to change this.
'';
};
confirmation = {
get_commit_characters =
2024-10-06 10:05:31 -05:00
defaultNullOpts.mkLuaFn
2024-05-05 19:39:35 +02:00
''
function(commit_characters)
return commit_characters
end
''
''
You can append or exclude `commitCharacters` via this configuration option function.
The `commitCharacters` are defined by the LSP spec.
'';
};
formatting = {
2024-10-06 10:05:31 -05:00
expandable_indicator = defaultNullOpts.mkBool true ''
Boolean to show the `~` expandable indicator in cmp's floating window.
'';
fields =
2024-10-06 10:05:31 -05:00
defaultNullOpts.mkListOf types.str
[
"abbr"
"kind"
"menu"
]
''
An array of completion fields to specify their order.
'';
format =
2024-10-06 10:05:31 -05:00
defaultNullOpts.mkLuaFn
2024-05-05 19:39:35 +02:00
''
function(_, vim_item)
return vim_item
end
''
''
`fun(entry: cmp.Entry, vim_item: vim.CompletedItem): vim.CompletedItem`
2024-05-05 19:39:35 +02:00
The function used to customize the appearance of the completion menu.
See `|complete-items|`.
This value can also be used to modify the `dup` property.
2024-05-05 19:39:35 +02:00
NOTE: The `vim.CompletedItem` can contain the special properties `abbr_hl_group`,
`kind_hl_group` and `menu_hl_group`.
'';
};
matching = {
2024-10-06 10:05:31 -05:00
disallow_fuzzy_matching = defaultNullOpts.mkBool false ''
Whether to allow fuzzy matching.
'';
2024-10-06 10:05:31 -05:00
disallow_fullfuzzy_matching = defaultNullOpts.mkBool false ''
Whether to allow full-fuzzy matching.
'';
2024-10-06 10:05:31 -05:00
disallow_partial_fuzzy_matching = defaultNullOpts.mkBool true ''
Whether to allow fuzzy matching without prefix matching.
'';
2024-10-06 10:05:31 -05:00
disallow_partial_matching = defaultNullOpts.mkBool false ''
Whether to allow partial matching.
'';
2024-10-06 10:05:31 -05:00
disallow_prefix_unmatching = defaultNullOpts.mkBool false ''
Whether to allow prefix unmatching.
'';
};
sorting = {
2024-10-06 10:05:31 -05:00
priority_weight = defaultNullOpts.mkUnsignedInt 2 ''
Each item's original priority (given by its corresponding source) will be increased by
`#sources - (source_index - 1)` and multiplied by `priority_weight`.
That is, the final priority is calculated by the following formula:
`final_score = orig_score + ((#sources - (source_index - 1)) * sorting.priority_weight)`
'';
comparators = mkOption {
2024-09-27 08:07:20 +01:00
type = with lib.types; nullOr (listOf strLuaFn);
default = null;
description = ''
The function to customize the sorting behavior.
You can use built-in comparators via `cmp.config.compare.*`.
Signature: `(fun(entry1: cmp.Entry, entry2: cmp.Entry): boolean | nil)[]`
Default:
```nix
[
"require('cmp.config.compare').offset"
"require('cmp.config.compare').exact"
"require('cmp.config.compare').score"
"require('cmp.config.compare').recently_used"
"require('cmp.config.compare').locality"
"require('cmp.config.compare').kind"
"require('cmp.config.compare').length"
"require('cmp.config.compare').order"
]
```
'';
};
};
2024-10-06 10:05:31 -05:00
sources = import ./sources-option.nix { inherit lib; };
view = {
entries =
2024-10-06 10:05:31 -05:00
defaultNullOpts.mkNullable (with types; either str (attrsOf anything))
{
name = "custom";
selection_order = "top_down";
}
2024-05-05 19:39:35 +02:00
''
The view class used to customize nvim-cmp's appearance.
'';
docs = {
2024-10-06 10:05:31 -05:00
auto_open = defaultNullOpts.mkBool true ''
Specify whether to show the docs_view when selecting an item.
'';
};
};
2024-05-05 19:39:35 +02:00
window =
let
mkWinhighlightOption =
default:
2024-10-06 10:05:31 -05:00
defaultNullOpts.mkStr default ''
2024-05-05 19:39:35 +02:00
Specify the window's winhighlight option.
See `|nvim_open_win|`.
'';
2024-10-06 10:05:31 -05:00
zindex = lib.nixvim.mkNullOrOption types.ints.unsigned ''
2024-05-05 19:39:35 +02:00
The window's zindex.
See `|nvim_open_win|`.
'';
2024-05-05 19:39:35 +02:00
in
{
completion = {
2024-10-06 10:05:31 -05:00
border = defaultNullOpts.mkBorder (lib.genList (_: "") 8) "nvim-cmp completion popup menu" "";
2024-05-05 19:39:35 +02:00
winhighlight = mkWinhighlightOption "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None";
2024-05-05 19:39:35 +02:00
inherit zindex;
2024-10-06 10:05:31 -05:00
scrolloff = defaultNullOpts.mkUnsignedInt 0 ''
2024-05-05 19:39:35 +02:00
Specify the window's scrolloff option.
See |'scrolloff'|.
'';
2024-10-06 10:05:31 -05:00
col_offset = defaultNullOpts.mkInt 0 ''
2024-05-05 19:39:35 +02:00
Offsets the completion window relative to the cursor.
'';
2024-10-06 10:05:31 -05:00
side_padding = defaultNullOpts.mkUnsignedInt 1 ''
2024-05-05 19:39:35 +02:00
The amount of padding to add on the completion window's sides.
'';
2024-10-06 10:05:31 -05:00
scrollbar = defaultNullOpts.mkBool true ''
2024-05-05 19:39:35 +02:00
Whether the scrollbar should be enabled if there are more items that fit.
'';
};
2024-05-05 19:39:35 +02:00
documentation = {
2024-10-06 10:05:31 -05:00
border = defaultNullOpts.mkBorder (lib.genList (_: "") 8) "nvim-cmp documentation popup menu" "";
2024-05-05 19:39:35 +02:00
winhighlight = mkWinhighlightOption "FloatBorder:NormalFloat";
2024-05-05 19:39:35 +02:00
inherit zindex;
2024-10-06 10:05:31 -05:00
max_width = lib.nixvim.mkNullOrStrLuaOr types.ints.unsigned ''
The documentation window's max width.
Default: "math.floor((40 * 2) * (vim.o.columns / (40 * 2 * 16 / 9)))"
'';
2024-10-06 10:05:31 -05:00
max_height = lib.nixvim.mkNullOrStrLuaOr types.ints.unsigned ''
The documentation window's max height.
Default: "math.floor(40 * (40 / vim.o.lines))"
'';
2024-05-05 19:39:35 +02:00
};
};
# This can be kept as types.attrs since experimental features are often removed or completely
# changed after a while
2024-10-06 10:05:31 -05:00
experimental = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
Experimental features.
'';
}