2023-02-20 11:42:13 +01:00
|
|
|
{
|
2023-11-06 15:04:08 +01:00
|
|
|
lib,
|
|
|
|
helpers,
|
2023-02-20 11:42:13 +01:00
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
} @ args:
|
|
|
|
with lib; let
|
2022-09-18 11:19:23 +01:00
|
|
|
cfg = config.plugins.nvim-cmp;
|
2022-07-28 21:38:38 +02:00
|
|
|
cmpLib = import ./cmp-helpers.nix args;
|
2023-02-20 11:42:13 +01:00
|
|
|
in {
|
2023-08-17 16:07:28 +02:00
|
|
|
options.plugins.nvim-cmp =
|
2024-01-25 16:15:55 +01:00
|
|
|
helpers.neovim-plugin.extraOptionsOptions
|
2023-08-17 16:07:28 +02:00
|
|
|
// {
|
|
|
|
enable = mkEnableOption "nvim-cmp";
|
|
|
|
|
|
|
|
package = helpers.mkPackageOption "nvim-cmp" pkgs.vimPlugins.nvim-cmp;
|
|
|
|
|
|
|
|
performance = {
|
|
|
|
debounce = helpers.defaultNullOpts.mkInt 60 ''
|
|
|
|
Sets debounce time
|
|
|
|
This is the interval used to group up completions from different sources
|
|
|
|
for filtering and displaying.
|
|
|
|
'';
|
2023-01-19 10:45:15 +00:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
throttle = helpers.defaultNullOpts.mkInt 30 ''
|
|
|
|
Sets throttle time.
|
|
|
|
This is used to delay filtering and displaying completions.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
fetchingTimeout = helpers.defaultNullOpts.mkInt 500 ''
|
|
|
|
Sets the timeout of candidate fetching process.
|
|
|
|
The nvim-cmp will wait to display the most prioritized source.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
asyncBudget = helpers.defaultNullOpts.mkInt 1 ''
|
|
|
|
Maximum time (in ms) an async function is allowed to run during one step of the event loop.
|
|
|
|
'';
|
2023-05-26 11:18:23 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
maxViewEntries = helpers.defaultNullOpts.mkInt 200 ''
|
|
|
|
Maximum number of items to show in the entries list.
|
|
|
|
'';
|
|
|
|
};
|
2023-05-26 11:18:23 +02:00
|
|
|
|
2024-02-01 16:36:09 +01:00
|
|
|
preselect = mkOption {
|
|
|
|
type = with types; nullOr (enum ["Item" "None"]);
|
|
|
|
apply = v:
|
|
|
|
helpers.ifNonNull' v
|
|
|
|
(helpers.mkRaw "cmp.PreselectMode.${v}");
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
- "Item": nvim-cmp will preselect the item that the source specified.
|
|
|
|
- "None": nvim-cmp will not preselect any items.
|
|
|
|
'';
|
|
|
|
};
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
mapping = mkOption {
|
2024-02-01 16:36:09 +01:00
|
|
|
default = {};
|
2023-08-17 16:07:28 +02:00
|
|
|
type = with types;
|
2024-02-01 16:36:09 +01:00
|
|
|
attrsOf
|
2023-08-17 16:07:28 +02:00
|
|
|
(
|
2024-02-01 16:36:09 +01:00
|
|
|
either
|
|
|
|
str
|
2023-08-17 16:07:28 +02:00
|
|
|
(
|
2024-02-01 16:36:09 +01:00
|
|
|
submodule {
|
|
|
|
options = {
|
|
|
|
action = mkOption {
|
|
|
|
type = nonEmptyStr;
|
|
|
|
description = "The function the mapping should call";
|
|
|
|
example = ''"cmp.mapping.scroll_docs(-4)"'';
|
2023-08-17 16:07:28 +02:00
|
|
|
};
|
2024-02-01 16:36:09 +01:00
|
|
|
modes = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = nullOr (listOf str);
|
|
|
|
example = ''[ "i" "s" ]'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2023-08-17 16:07:28 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
example = {
|
2024-01-08 08:30:29 +01:00
|
|
|
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
|
|
|
|
"<C-f>" = "cmp.mapping.scroll_docs(4)";
|
|
|
|
"<C-Space>" = "cmp.mapping.complete()";
|
|
|
|
"<C-e>" = "cmp.mapping.close()";
|
2022-07-28 21:38:38 +02:00
|
|
|
"<Tab>" = {
|
2023-08-17 16:07:28 +02:00
|
|
|
modes = ["i" "s"];
|
2024-01-08 08:30:29 +01:00
|
|
|
action = "cmp.mapping.select_next_item()";
|
|
|
|
};
|
|
|
|
"<S-Tab>" = {
|
|
|
|
modes = ["i" "s"];
|
|
|
|
action = "cmp.mapping.select_prev_item()";
|
2022-07-28 21:38:38 +02:00
|
|
|
};
|
2024-01-08 08:30:29 +01:00
|
|
|
"<CR>" = "cmp.mapping.confirm({ select = true })";
|
2023-08-17 16:07:28 +02:00
|
|
|
};
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
mappingPresets = mkOption {
|
|
|
|
default = [];
|
2024-02-01 16:36:09 +01:00
|
|
|
type = with types;
|
|
|
|
listOf (enum ["insert" "cmdline"]);
|
2023-08-17 16:07:28 +02:00
|
|
|
description = ''
|
|
|
|
Mapping presets to use; cmp.mapping.preset.
|
|
|
|
\$\{mappingPreset} will be called with the configured mappings.
|
|
|
|
'';
|
|
|
|
example = ''[ "insert" "cmdline" ]'';
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
snippet = {
|
2024-02-01 16:36:09 +01:00
|
|
|
expand = let
|
|
|
|
snippetEngines = {
|
|
|
|
"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)'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
mkOption {
|
|
|
|
default = null;
|
|
|
|
type = with types;
|
|
|
|
nullOr
|
|
|
|
(
|
|
|
|
either
|
|
|
|
helpers.nixvimTypes.rawLua
|
|
|
|
(enum (attrNames snippetEngines))
|
|
|
|
);
|
|
|
|
apply = v:
|
|
|
|
if isString v
|
|
|
|
then
|
|
|
|
helpers.mkRaw ''
|
|
|
|
function(args)
|
|
|
|
${snippetEngines.${v}}
|
|
|
|
end
|
|
|
|
''
|
|
|
|
else v;
|
|
|
|
description = ''
|
|
|
|
The snippet expansion function. That's how nvim-cmp interacts with a
|
|
|
|
particular snippet engine.
|
|
|
|
|
|
|
|
You may directly provide one of those four supported engines:
|
|
|
|
- vsnip
|
|
|
|
- luasnip
|
|
|
|
- snippy
|
|
|
|
- ultisnips
|
|
|
|
|
|
|
|
You can also provide a custom function:
|
|
|
|
```nix
|
|
|
|
{
|
|
|
|
__raw = \'\'
|
|
|
|
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
|
|
|
|
\'\';
|
|
|
|
};
|
|
|
|
```
|
|
|
|
'';
|
|
|
|
};
|
2023-08-17 16:07:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
completion = {
|
|
|
|
keywordLength = helpers.defaultNullOpts.mkInt 1 ''
|
|
|
|
The number of characters needed to trigger auto-completion.
|
2023-03-12 18:52:02 +01:00
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2024-02-01 16:36:09 +01:00
|
|
|
keywordPattern = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
2023-08-17 16:07:28 +02:00
|
|
|
The default keyword pattern.
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
Note: the provided pattern will be embedded as such: `[[PATTERN]]`.
|
2024-02-01 16:36:09 +01:00
|
|
|
|
|
|
|
Default: "\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)"
|
2023-08-17 16:07:28 +02:00
|
|
|
'';
|
2024-02-01 16:36:09 +01:00
|
|
|
apply = v:
|
|
|
|
helpers.ifNonNull'
|
|
|
|
v
|
|
|
|
(helpers.mkRaw "[[${v}]]");
|
|
|
|
};
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2024-02-01 16:36:09 +01:00
|
|
|
autocomplete = mkOption {
|
|
|
|
type = with types;
|
|
|
|
nullOr
|
|
|
|
(
|
2023-08-17 16:07:28 +02:00
|
|
|
either
|
|
|
|
(listOf str)
|
|
|
|
(types.enum [false])
|
2024-02-01 16:36:09 +01:00
|
|
|
);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
2023-08-17 16:07:28 +02:00
|
|
|
The event to trigger autocompletion.
|
|
|
|
If set to `"false"`, then completion is only invoked manually
|
|
|
|
(e.g. by calling `cmp.complete`).
|
2024-02-01 16:36:09 +01:00
|
|
|
|
|
|
|
Default: ["TextChanged"]
|
2023-08-17 16:07:28 +02:00
|
|
|
'';
|
2024-02-01 16:36:09 +01:00
|
|
|
apply = v:
|
|
|
|
if isList v
|
|
|
|
then
|
|
|
|
map
|
|
|
|
(triggerEvent:
|
|
|
|
helpers.mkRaw "require('cmp.types').cmp.TriggerEvent.${triggerEvent}")
|
|
|
|
v
|
|
|
|
# either null or false
|
|
|
|
else v;
|
|
|
|
};
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
completeopt = helpers.defaultNullOpts.mkStr "menu,menuone,noselect" ''
|
|
|
|
Like vim's completeopt setting. In general, you don't need to change this.
|
2023-03-12 18:52:02 +01:00
|
|
|
'';
|
2023-08-17 16:07:28 +02:00
|
|
|
};
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
confirmation = {
|
|
|
|
getCommitCharacters =
|
2024-02-01 16:36:09 +01:00
|
|
|
helpers.defaultNullOpts.mkLuaFn
|
2023-08-17 16:07:28 +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.
|
|
|
|
'';
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
formatting = {
|
|
|
|
expandableIndicator = helpers.defaultNullOpts.mkBool true ''
|
|
|
|
Boolean to show the `~` expandable indicator in cmp's floating window.
|
2023-03-12 18:52:02 +01:00
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
fields =
|
|
|
|
helpers.defaultNullOpts.mkNullable
|
|
|
|
(with types; listOf str)
|
|
|
|
''[ "kind" "abbr" "menu" ]''
|
|
|
|
"An array of completion fields to specify their order.";
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
format =
|
2023-12-29 15:24:42 +01:00
|
|
|
helpers.defaultNullOpts.mkLuaFn
|
2023-08-17 16:07:28 +02:00
|
|
|
''
|
|
|
|
function(_, vim_item)
|
|
|
|
return vim_item
|
|
|
|
end
|
|
|
|
''
|
|
|
|
''
|
|
|
|
`fun(entry: cmp.Entry, vim_item: vim.CompletedItem): vim.CompletedItem`
|
|
|
|
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.
|
|
|
|
NOTE: The `vim.CompletedItem` can contain the special properties
|
|
|
|
`abbr_hl_group`, `kind_hl_group` and `menu_hl_group`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
matching = {
|
|
|
|
disallowFuzzyMatching = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Whether to allow fuzzy matching.
|
2023-03-12 18:52:02 +01:00
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
disallowFullfuzzyMatching = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Whether to allow full-fuzzy matching.
|
|
|
|
'';
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
disallowPartialFuzzyMatching = helpers.defaultNullOpts.mkBool true ''
|
|
|
|
Whether to allow fuzzy matching without prefix matching.
|
|
|
|
'';
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
disallowPartialMatching = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Whether to allow partial matching.
|
|
|
|
'';
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
disallowPrefixUnmatching = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Whether to allow prefix unmatching.
|
|
|
|
'';
|
|
|
|
};
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
sorting = {
|
|
|
|
priorityWeight = helpers.defaultNullOpts.mkInt 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:
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
`final_score = orig_score + ((#sources - (source_index - 1)) * sorting.priority_weight)`
|
|
|
|
'';
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2024-02-01 16:36:09 +01:00
|
|
|
comparators = mkOption {
|
|
|
|
type = with helpers.nixvimTypes; nullOr (listOf strLuaFn);
|
|
|
|
apply = v:
|
|
|
|
helpers.ifNonNull' v (
|
|
|
|
map
|
|
|
|
(
|
|
|
|
funcName:
|
|
|
|
helpers.mkRaw "require('cmp.config.compare').${funcName}"
|
|
|
|
)
|
|
|
|
v
|
|
|
|
);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
2023-08-17 16:07:28 +02:00
|
|
|
The function to customize the sorting behavior.
|
|
|
|
You can use built-in comparators via `cmp.config.compare.*`.
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
Signature: `(fun(entry1: cmp.Entry, entry2: cmp.Entry): boolean | nil)[]`
|
2024-02-01 16:36:09 +01:00
|
|
|
|
|
|
|
Default: ["offset" "exact" "score" "recently_used" "locality" "kind" "length" "order"]
|
2023-08-17 16:07:28 +02:00
|
|
|
'';
|
2024-02-01 16:36:09 +01:00
|
|
|
};
|
2023-08-17 16:07:28 +02:00
|
|
|
};
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
autoEnableSources = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Scans the sources array and installs the plugins if they are known to nixvim.
|
2023-03-12 18:52:02 +01:00
|
|
|
'';
|
2023-08-17 16:07:28 +02:00
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
sources = let
|
2023-08-28 16:06:05 +02:00
|
|
|
source_config = types.submodule {
|
2023-08-17 16:07:28 +02:00
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The name of the source.";
|
|
|
|
example = "buffer";
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
option = helpers.mkNullOrOption types.attrs ''
|
|
|
|
Any specific options defined by the source itself.
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
If direct lua code is needed use `helpers.mkRaw`.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
keywordLength = helpers.mkNullOrOption types.int ''
|
|
|
|
The source-specific keyword length to trigger auto completion.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
keywordPattern = helpers.mkNullOrOption types.str ''
|
|
|
|
The source-specific keyword pattern.
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
Note: the provided pattern will be embedded as such: `[[PATTERN]]`.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
triggerCharacters = helpers.mkNullOrOption (with types; listOf str) ''
|
|
|
|
A source-specific keyword pattern.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
priority = helpers.mkNullOrOption types.int "The source-specific priority value.";
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
groupIndex = helpers.mkNullOrOption types.int ''
|
|
|
|
The source group index.
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
For instance, you can set the `buffer`'s source `groupIndex` to a larger number
|
|
|
|
if you don't want to see `buffer` source items while `nvim-lsp` source is available:
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
```nix
|
|
|
|
sources = [
|
|
|
|
{
|
|
|
|
name = "nvim_lsp";
|
|
|
|
groupIndex = 1;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "buffer";
|
|
|
|
groupIndex = 2;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
```
|
|
|
|
'';
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
entryFilter = helpers.mkNullOrOption types.str ''
|
|
|
|
A source-specific entry filter, with the following function signature:
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
`function(entry: cmp.Entry, ctx: cmp.Context): boolean`
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
Returning `true` will keep the entry, while returning `false` will remove it.
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
This can be used to hide certain entries from a given source. For instance, you
|
|
|
|
could hide all entries with kind `Text` from the `nvim_lsp` filter using the
|
|
|
|
following source definition:
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
```
|
|
|
|
{
|
|
|
|
name = 'nvim_lsp',
|
|
|
|
entry_filter = function(entry, ctx)
|
|
|
|
return require('cmp.types').lsp.CompletionItemKind[entry:get_kind()] ~= 'Text'
|
|
|
|
end
|
|
|
|
}
|
|
|
|
```
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
Using the `ctx` parameter, you can further customize the behaviour of the source.
|
|
|
|
'';
|
|
|
|
};
|
2023-08-28 16:06:05 +02:00
|
|
|
};
|
2023-08-17 16:07:28 +02:00
|
|
|
in
|
|
|
|
mkOption {
|
|
|
|
default = null;
|
2023-08-28 16:06:05 +02:00
|
|
|
type = with types;
|
|
|
|
nullOr
|
|
|
|
(
|
|
|
|
listOf
|
|
|
|
(
|
|
|
|
either
|
|
|
|
source_config
|
|
|
|
(listOf source_config)
|
|
|
|
)
|
|
|
|
);
|
2023-08-17 16:07:28 +02:00
|
|
|
description = ''
|
|
|
|
The sources to use.
|
2023-08-28 16:06:05 +02:00
|
|
|
Can either be a list of sourceConfigs which will be made directly to a Lua object.
|
|
|
|
Or it can be a list of lists, which will use the cmp built-in helper function
|
|
|
|
`cmp.config.sources`.
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
Default: `[]`
|
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
[
|
|
|
|
{ name = "nvim_lsp"; }
|
|
|
|
{ name = "luasnip"; } #For luasnip users.
|
|
|
|
{ name = "path"; }
|
|
|
|
{ name = "buffer"; }
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
view = {
|
|
|
|
entries =
|
|
|
|
helpers.defaultNullOpts.mkNullable (with types; either str attrs)
|
|
|
|
''
|
2023-03-12 18:52:02 +01:00
|
|
|
{
|
2023-08-17 16:07:28 +02:00
|
|
|
name = "custom";
|
|
|
|
selection_order = "top_down";
|
2023-03-12 18:52:02 +01:00
|
|
|
}
|
2023-08-17 16:07:28 +02:00
|
|
|
''
|
|
|
|
''
|
|
|
|
The view class used to customize nvim-cmp's appearance.
|
|
|
|
'';
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
docs = {
|
|
|
|
autoOpen = helpers.defaultNullOpts.mkBool true ''
|
|
|
|
Specify whether to show the docs_view when selecting an item.
|
2023-03-12 18:52:02 +01:00
|
|
|
'';
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
2022-08-05 15:01:10 +01:00
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
window = let
|
|
|
|
# Reusable options
|
|
|
|
mkWinhighlightOption = default:
|
|
|
|
helpers.defaultNullOpts.mkStr
|
|
|
|
default
|
|
|
|
''
|
|
|
|
Specify the window's winhighlight option.
|
|
|
|
See |nvim_open_win|.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
zindex = helpers.mkNullOrOption types.int ''
|
|
|
|
The completion window's zindex.
|
2023-03-12 18:52:02 +01:00
|
|
|
See |nvim_open_win|.
|
|
|
|
'';
|
2023-08-17 16:07:28 +02:00
|
|
|
in {
|
|
|
|
completion = {
|
|
|
|
border =
|
|
|
|
helpers.defaultNullOpts.mkBorder
|
|
|
|
''[ "" "" "" "" "" "" "" "" ]''
|
|
|
|
"nvim-cmp window"
|
|
|
|
"";
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
winhighlight =
|
|
|
|
mkWinhighlightOption
|
|
|
|
"Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None";
|
|
|
|
|
|
|
|
inherit zindex;
|
|
|
|
|
|
|
|
scrolloff = helpers.defaultNullOpts.mkInt 0 ''
|
|
|
|
Specify the window's scrolloff option.
|
|
|
|
See |'scrolloff'|.
|
|
|
|
'';
|
|
|
|
|
|
|
|
colOffset = helpers.defaultNullOpts.mkInt 0 ''
|
|
|
|
Offsets the completion window relative to the cursor.
|
|
|
|
'';
|
|
|
|
|
|
|
|
sidePadding = helpers.defaultNullOpts.mkInt 1 ''
|
|
|
|
The amount of padding to add on the completion window's sides.
|
|
|
|
'';
|
|
|
|
|
|
|
|
scrollbar = helpers.defaultNullOpts.mkBool true ''
|
|
|
|
Whether the scrollbar should be enabled if there are more items that fit
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
documentation = {
|
|
|
|
border =
|
|
|
|
helpers.defaultNullOpts.mkBorder
|
|
|
|
''[ "" "" "" " " "" "" "" " " ]''
|
|
|
|
"nvim-cmp documentation window"
|
|
|
|
"";
|
2023-03-12 18:52:02 +01:00
|
|
|
|
|
|
|
winhighlight = mkWinhighlightOption "FloatBorder:NormalFloat";
|
|
|
|
|
|
|
|
inherit zindex;
|
|
|
|
|
|
|
|
maxWidth =
|
2024-02-01 16:36:09 +01:00
|
|
|
helpers.mkNullOrStrLuaOr types.ints.unsigned
|
|
|
|
''
|
|
|
|
The documentation window's max width.
|
|
|
|
|
|
|
|
Default: "math.floor((40 * 2) * (vim.o.columns / (40 * 2 * 16 / 9)))"
|
|
|
|
'';
|
2023-03-12 18:52:02 +01:00
|
|
|
|
|
|
|
maxHeight =
|
2024-02-01 16:36:09 +01:00
|
|
|
helpers.mkNullOrStrLuaOr types.ints.unsigned
|
|
|
|
''
|
|
|
|
The documentation window's max height.
|
|
|
|
|
|
|
|
Default: "math.floor(40 * (40 / vim.o.lines))"
|
|
|
|
'';
|
2023-03-12 18:52:02 +01:00
|
|
|
};
|
2022-08-05 15:01:10 +01:00
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-08-17 16:07:28 +02:00
|
|
|
# This can be kept as types.attrs since experimental features are often removed or completely
|
|
|
|
# changed after a while
|
|
|
|
experimental = helpers.mkNullOrOption types.attrs "Experimental features";
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2024-02-01 16:36:09 +01:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
extraPlugins = [cfg.package];
|
2023-03-12 18:52:02 +01:00
|
|
|
|
2024-02-01 16:36:09 +01:00
|
|
|
extraConfigLua = let
|
|
|
|
setupOptions = import ./setup-options.nix {
|
|
|
|
inherit cfg lib helpers;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
helpers.wrapDo ''
|
2022-09-18 11:19:23 +01:00
|
|
|
local cmp = require('cmp')
|
2023-08-17 16:07:28 +02:00
|
|
|
cmp.setup(${helpers.toLuaObject setupOptions})
|
2022-09-18 11:19:23 +01:00
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2024-02-01 16:36:09 +01:00
|
|
|
# If autoEnableSources is set to true, figure out which are provided by the user
|
|
|
|
# and enable the corresponding plugins.
|
|
|
|
plugins = let
|
|
|
|
sourcesFlattenedList =
|
|
|
|
if cfg.sources == null
|
|
|
|
then []
|
|
|
|
else flatten cfg.sources;
|
|
|
|
|
|
|
|
# Take only the names from the sources provided by the user
|
|
|
|
foundSources =
|
|
|
|
lists.unique
|
|
|
|
(
|
|
|
|
map
|
|
|
|
(source: source.name)
|
|
|
|
sourcesFlattenedList
|
|
|
|
);
|
|
|
|
|
|
|
|
# A list of known source names
|
|
|
|
knownSourceNames = attrNames cmpLib.pluginAndSourceNames;
|
|
|
|
|
|
|
|
attrsEnabled = listToAttrs (map
|
|
|
|
(name: {
|
|
|
|
# Name of the corresponding plugin to enable
|
|
|
|
name = cmpLib.pluginAndSourceNames.${name};
|
|
|
|
|
|
|
|
# Whether or not we enable it
|
|
|
|
value.enable = mkIf (elem name foundSources) true;
|
|
|
|
})
|
|
|
|
knownSourceNames);
|
|
|
|
in
|
|
|
|
mkMerge [
|
|
|
|
(mkIf cfg.autoEnableSources attrsEnabled)
|
|
|
|
(mkIf (elem "nvim_lsp" foundSources)
|
|
|
|
{
|
|
|
|
lsp.capabilities = ''
|
|
|
|
capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
'';
|
2023-02-20 11:42:13 +01:00
|
|
|
})
|
2024-02-01 16:36:09 +01:00
|
|
|
];
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
}
|