2023-02-20 11:42:13 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
} @ args:
|
|
|
|
with lib; let
|
2022-09-18 11:19:23 +01:00
|
|
|
cfg = config.plugins.nvim-cmp;
|
2023-02-20 11:42:13 +01:00
|
|
|
helpers = import ../../helpers.nix {inherit lib;};
|
2022-07-28 21:38:38 +02:00
|
|
|
cmpLib = import ./cmp-helpers.nix args;
|
2023-03-12 22:31:32 +01:00
|
|
|
|
|
|
|
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)'';
|
|
|
|
};
|
2023-02-20 11:42:13 +01:00
|
|
|
in {
|
2022-09-18 11:19:23 +01:00
|
|
|
options.plugins.nvim-cmp = {
|
2023-01-22 03:32:08 +00:00
|
|
|
enable = mkEnableOption "nvim-cmp";
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-01-25 19:46:49 +01:00
|
|
|
package = helpers.mkPackageOption "nvim-cmp" pkgs.vimPlugins.nvim-cmp;
|
2023-01-19 10:45:15 +00:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
performance = helpers.mkCompositeOption "Performance options" {
|
|
|
|
debounce = helpers.defaultNullOpts.mkInt 60 ''
|
|
|
|
Sets debounce time
|
|
|
|
This is the interval used to group up completions from different sources
|
|
|
|
for filtering and displaying.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01: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-03-12 18:52:02 +01: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
|
|
|
'';
|
|
|
|
};
|
2022-08-05 15:01:10 +01:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
preselect = helpers.defaultNullOpts.mkEnumFirstDefault ["Item" "None"] ''
|
|
|
|
- "Item": nvim-cmp will preselect the item that the source specified.
|
|
|
|
- "None": nvim-cmp will not preselect any items.
|
|
|
|
'';
|
|
|
|
|
2022-07-28 21:38:38 +02:00
|
|
|
mapping = mkOption {
|
|
|
|
default = null;
|
2023-03-12 18:52:02 +01:00
|
|
|
type = with types;
|
2023-05-22 15:45:47 +05:30
|
|
|
nullOr (attrsOf (either str (types.submodule (_: {
|
2023-03-12 18:52:02 +01:00
|
|
|
options = {
|
|
|
|
action = mkOption {
|
|
|
|
type = types.nonEmptyStr;
|
|
|
|
description = "The function the mapping should call";
|
|
|
|
example = ''"cmp.mapping.scroll_docs(-4)"'';
|
|
|
|
};
|
|
|
|
modes = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
example = ''[ "i" "s" ]'';
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
};
|
2023-03-12 18:52:02 +01:00
|
|
|
}))));
|
2022-07-28 21:38:38 +02:00
|
|
|
example = ''
|
|
|
|
{
|
|
|
|
"<CR>" = "cmp.mapping.confirm({ select = true })";
|
|
|
|
"<Tab>" = {
|
|
|
|
modes = [ "i" "s" ];
|
|
|
|
action = '${""}'
|
|
|
|
function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expandable() then
|
|
|
|
luasnip.expand()
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
elseif check_backspace() then
|
|
|
|
fallback()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
'${""}';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
mappingPresets = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf (types.enum [
|
|
|
|
"insert"
|
|
|
|
"cmdline"
|
|
|
|
]);
|
|
|
|
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-03-12 18:52:02 +01:00
|
|
|
snippet = helpers.mkCompositeOption "Snippet options" {
|
|
|
|
expand =
|
2023-03-12 22:31:32 +01:00
|
|
|
helpers.mkNullOrOption
|
|
|
|
(
|
|
|
|
types.either
|
|
|
|
helpers.rawType
|
|
|
|
(types.enum (attrNames snippetEngines))
|
|
|
|
)
|
2023-03-12 18:52:02 +01:00
|
|
|
''
|
|
|
|
The snippet expansion function. That's how nvim-cmp interacts with a
|
|
|
|
particular snippet engine.
|
|
|
|
|
2023-03-12 22:31:32 +01:00
|
|
|
You may directly provide one of those four supported engines:
|
|
|
|
- vsnip
|
|
|
|
- luasnip
|
|
|
|
- snippy
|
|
|
|
- ultisnips
|
|
|
|
|
|
|
|
You can also provide a custom function:
|
2023-03-12 18:52:02 +01:00
|
|
|
```
|
2023-03-12 22:31:32 +01:00
|
|
|
{
|
|
|
|
__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-03-12 18:52:02 +01:00
|
|
|
```
|
|
|
|
'';
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
completion = helpers.mkCompositeOption "Completion options" {
|
|
|
|
keywordLength = helpers.defaultNullOpts.mkInt 1 ''
|
|
|
|
The number of characters needed to trigger auto-completion.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
keywordPattern =
|
|
|
|
helpers.defaultNullOpts.mkStr
|
|
|
|
''\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)''
|
|
|
|
''
|
|
|
|
The default keyword pattern.
|
|
|
|
|
|
|
|
Note: the provided pattern will be embedded as such: `[[PATTERN]]`.
|
|
|
|
'';
|
|
|
|
|
|
|
|
autocomplete =
|
|
|
|
helpers.defaultNullOpts.mkNullable
|
|
|
|
(
|
|
|
|
with types;
|
|
|
|
either
|
|
|
|
(listOf str)
|
|
|
|
(types.enum [false])
|
|
|
|
)
|
|
|
|
''[ "TextChanged" ]''
|
|
|
|
''
|
|
|
|
The event to trigger autocompletion.
|
|
|
|
If set to `"false"`, then completion is only invoked manually
|
|
|
|
(e.g. by calling `cmp.complete`).
|
|
|
|
'';
|
|
|
|
|
|
|
|
completeopt = helpers.defaultNullOpts.mkStr "menu,menuone,noselect" ''
|
|
|
|
Like vim's completeopt setting. In general, you don't need to change this.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
};
|
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
confirmation = helpers.mkCompositeOption "Confirmation options" {
|
|
|
|
getCommitCharacters =
|
|
|
|
helpers.defaultNullOpts.mkStr
|
|
|
|
''
|
|
|
|
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-03-12 18:52:02 +01:00
|
|
|
formatting = helpers.mkCompositeOption "Formatting options" {
|
|
|
|
expandableIndicator = helpers.defaultNullOpts.mkBool true ''
|
|
|
|
Boolean to show the `~` expandable indicator in cmp's floating window.
|
|
|
|
'';
|
|
|
|
|
|
|
|
fields =
|
|
|
|
helpers.defaultNullOpts.mkNullable
|
|
|
|
(types.listOf types.str)
|
|
|
|
''[ "kind" "abbr" "menu" ]''
|
|
|
|
"An array of completion fields to specify their order.";
|
|
|
|
|
|
|
|
format =
|
|
|
|
helpers.defaultNullOpts.mkStr
|
|
|
|
''
|
|
|
|
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`.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
};
|
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
matching = helpers.mkCompositeOption "Matching options" {
|
|
|
|
disallowFuzzyMatching = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Whether to allow fuzzy matching.
|
|
|
|
'';
|
|
|
|
|
|
|
|
disallowFullfuzzyMatching = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Whether to allow full-fuzzy matching.
|
|
|
|
'';
|
|
|
|
|
|
|
|
disallowPartialFuzzyMatching = helpers.defaultNullOpts.mkBool true ''
|
|
|
|
Whether to allow fuzzy matching without prefix matching.
|
|
|
|
'';
|
|
|
|
|
|
|
|
disallowPartialMatching = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Whether to allow partial matching.
|
|
|
|
'';
|
|
|
|
|
|
|
|
disallowPrefixUnmatching = helpers.defaultNullOpts.mkBool false ''
|
|
|
|
Whether to allow prefix unmatching.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
};
|
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
sorting = helpers.mkCompositeOption "Sorting options" {
|
|
|
|
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:
|
|
|
|
|
|
|
|
`final_score = orig_score + ((#sources - (source_index - 1)) * sorting.priority_weight)`
|
|
|
|
'';
|
|
|
|
|
|
|
|
comparators =
|
|
|
|
helpers.defaultNullOpts.mkNullable (types.listOf types.str)
|
|
|
|
''[ "offset" "exact" "score" "recently_used" "locality" "kind" "length" "order" ]''
|
|
|
|
''
|
|
|
|
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)[]`
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
};
|
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
autoEnableSources = mkOption {
|
2023-01-21 18:12:32 +01:00
|
|
|
type = types.bool;
|
2022-07-28 21:38:38 +02:00
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Scans the sources array and installs the plugins if they are known to nixvim.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
sources = let
|
2023-05-22 15:45:47 +05:30
|
|
|
source_config = types.submodule (_: {
|
2023-02-20 11:42:13 +01:00
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The name of the source.";
|
|
|
|
example = ''"buffer"'';
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-05-22 15:45:47 +05:30
|
|
|
option = helpers.mkNullOrOption types.attrs ''
|
2023-03-12 18:52:02 +01:00
|
|
|
Any specific options defined by the source itself.
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
If direct lua code is needed use `helpers.mkRaw`.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
keywordLength = helpers.mkNullOrOption types.int ''
|
|
|
|
The source-specific keyword length to trigger auto completion.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
keywordPattern = helpers.mkNullOrOption types.str ''
|
|
|
|
The source-specific keyword pattern.
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
Note: the provided pattern will be embedded as such: `[[PATTERN]]`.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
triggerCharacters = helpers.mkNullOrOption (types.listOf types.str) ''
|
|
|
|
A source-specific keyword pattern.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
priority = helpers.mkNullOrOption types.int "The source-specific priority value.";
|
|
|
|
|
|
|
|
maxItemCount = helpers.mkNullOrOption types.int "The source-specific item count.";
|
|
|
|
|
|
|
|
groupIndex = helpers.mkNullOrOption types.int ''
|
|
|
|
The source group index.
|
|
|
|
|
|
|
|
For instance, you can set the `buffer`'s source `group_index` to a larger number
|
|
|
|
if you don't want to see `buffer` source items while `nvim-lsp` source is available:
|
|
|
|
|
|
|
|
```
|
|
|
|
cmp.setup {
|
|
|
|
sources = {
|
|
|
|
{ name = 'nvim_lsp', group_index = 1 },
|
|
|
|
{ name = 'buffer', group_index = 2 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
You can also achieve this by using the built-in configuration helper like this:
|
|
|
|
```
|
|
|
|
cmp.setup {
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
}, {
|
|
|
|
{ name = 'buffer' },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
```
|
|
|
|
'';
|
|
|
|
|
|
|
|
entryFilter = helpers.mkNullOrOption types.str ''
|
|
|
|
A source-specific entry filter, with the following function signature:
|
|
|
|
|
|
|
|
`function(entry: cmp.Entry, ctx: cmp.Context): boolean`
|
|
|
|
|
|
|
|
Returning `true` will keep the entry, while returning `false` will remove it.
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
name = 'nvim_lsp',
|
|
|
|
entry_filter = function(entry, ctx)
|
|
|
|
return require('cmp.types').lsp.CompletionItemKind[entry:get_kind()] ~= 'Text'
|
|
|
|
end
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Using the `ctx` parameter, you can further customize the behaviour of the source.
|
|
|
|
'';
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
in
|
2022-08-05 15:01:10 +01:00
|
|
|
mkOption {
|
|
|
|
default = null;
|
2023-03-12 18:52:02 +01:00
|
|
|
type = with types;
|
|
|
|
nullOr (
|
|
|
|
either
|
|
|
|
(listOf source_config)
|
|
|
|
(listOf (listOf source_config))
|
|
|
|
);
|
2022-08-05 15:01:10 +01:00
|
|
|
description = ''
|
|
|
|
The sources to use.
|
|
|
|
Can either be a list of sourceConfigs which will be made directly to a Lua object.
|
2023-03-12 18:52:02 +01:00
|
|
|
Or it can be a list of lists, which will use the cmp built-in helper function
|
|
|
|
`cmp.config.sources`.
|
|
|
|
|
|
|
|
Default: [ ]
|
2022-08-05 15:01:10 +01:00
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
[
|
|
|
|
{ name = "nvim_lsp"; }
|
|
|
|
{ name = "luasnip"; } #For luasnip users.
|
|
|
|
{ name = "path"; }
|
|
|
|
{ name = "buffer"; }
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
view = helpers.mkCompositeOption "View options" {
|
|
|
|
entries =
|
|
|
|
helpers.defaultNullOpts.mkNullable (with types; either str attrs)
|
|
|
|
''
|
|
|
|
{
|
|
|
|
name = "custom";
|
|
|
|
selection_order = "top_down";
|
|
|
|
}
|
|
|
|
''
|
|
|
|
''
|
|
|
|
The view class used to customize nvim-cmp's appearance.
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
window = let
|
|
|
|
# Reusable options
|
2023-03-12 18:52:02 +01:00
|
|
|
mkBorderOption = default:
|
|
|
|
helpers.defaultNullOpts.mkNullable
|
|
|
|
(with types; either str (listOf str))
|
|
|
|
default
|
|
|
|
''
|
|
|
|
Border characters used for the completion popup menu when |experimental.native_menu| is disabled.
|
|
|
|
See |nvim_open_win|.
|
|
|
|
'';
|
|
|
|
|
|
|
|
mkWinhighlightOption = default:
|
|
|
|
helpers.defaultNullOpts.mkStr
|
|
|
|
default
|
|
|
|
''
|
|
|
|
Specify the window's winhighlight option.
|
|
|
|
See |nvim_open_win|.
|
|
|
|
'';
|
|
|
|
|
|
|
|
zindex = helpers.mkNullOrOption types.int ''
|
|
|
|
The completion window's zindex.
|
|
|
|
See |nvim_open_win|.
|
|
|
|
'';
|
2023-02-20 11:42:13 +01:00
|
|
|
in
|
2023-03-12 18:52:02 +01:00
|
|
|
helpers.mkCompositeOption "Windows options" {
|
|
|
|
completion = helpers.mkCompositeOption "Completion window options" {
|
|
|
|
border = mkBorderOption ''[ "" "" "" "" "" "" "" "" ]'';
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
documentation = helpers.mkCompositeOption "Documentation window options" {
|
|
|
|
border = mkBorderOption ''[ "" "" "" " " "" "" "" " " ]'';
|
|
|
|
|
|
|
|
winhighlight = mkWinhighlightOption "FloatBorder:NormalFloat";
|
|
|
|
|
|
|
|
inherit zindex;
|
|
|
|
|
|
|
|
maxWidth =
|
|
|
|
helpers.defaultNullOpts.mkNullable
|
|
|
|
(types.either types.int types.str)
|
|
|
|
"math.floor((40 * 2) * (vim.o.columns / (40 * 2 * 16 / 9)))"
|
|
|
|
"The documentation window's max width.";
|
|
|
|
|
|
|
|
maxHeight =
|
|
|
|
helpers.defaultNullOpts.mkNullable
|
|
|
|
(types.either types.int types.str)
|
|
|
|
"math.floor(40 * (40 / vim.o.lines))"
|
|
|
|
"The documentation window's max height.";
|
|
|
|
};
|
2022-08-05 15:01:10 +01:00
|
|
|
};
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2023-03-12 18:52:02 +01: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
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
|
|
|
options = {
|
2023-04-07 22:39:37 +02:00
|
|
|
# The upstream default value (which is a function) should not be overwritten.
|
|
|
|
# https://www.reddit.com/r/neovim/comments/vtw4vl/comment/if9zfdf/?utm_source=share&utm_medium=web2x&context=3
|
|
|
|
enabled =
|
|
|
|
if cfg.enable
|
|
|
|
then null
|
|
|
|
else false;
|
|
|
|
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg) performance;
|
2023-02-20 11:42:13 +01:00
|
|
|
preselect =
|
2023-03-12 18:52:02 +01:00
|
|
|
helpers.ifNonNull' cfg.preselect
|
|
|
|
(helpers.mkRaw "cmp.PreselectMode.${cfg.preselect}");
|
2023-02-20 11:42:13 +01:00
|
|
|
|
|
|
|
# Not very readable sorry
|
|
|
|
# If null then null
|
|
|
|
# If an attribute is a string, just treat it as lua code for that mapping
|
|
|
|
# If an attribute is a module, create a mapping with cmp.mapping() using the action as the first input and the modes as the second.
|
|
|
|
mapping = let
|
|
|
|
mappings =
|
2023-03-12 18:52:02 +01:00
|
|
|
helpers.ifNonNull' cfg.mapping
|
|
|
|
(mapAttrs
|
2023-02-20 11:42:13 +01:00
|
|
|
(bind: mapping:
|
|
|
|
helpers.mkRaw (
|
|
|
|
if isString mapping
|
|
|
|
then mapping
|
2023-03-12 18:52:02 +01:00
|
|
|
else let
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (mapping) modes;
|
2023-03-12 18:52:02 +01:00
|
|
|
modesString =
|
2023-05-22 15:45:47 +05:30
|
|
|
optionalString (modes != null && ((length modes) >= 1))
|
2023-03-12 18:52:02 +01:00
|
|
|
("," + (helpers.toLuaObject mapping.modes));
|
|
|
|
in "cmp.mapping(${mapping.action}${modesString})"
|
2023-02-20 11:42:13 +01:00
|
|
|
))
|
2023-03-12 18:52:02 +01:00
|
|
|
cfg.mapping);
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
luaMappings = helpers.toLuaObject mappings;
|
2023-03-12 18:52:02 +01:00
|
|
|
|
|
|
|
wrapped =
|
|
|
|
lists.fold
|
|
|
|
(
|
|
|
|
presetName: prevString: ''cmp.mapping.preset.${presetName}(${prevString})''
|
|
|
|
)
|
|
|
|
luaMappings
|
|
|
|
cfg.mappingPresets;
|
2023-02-20 11:42:13 +01:00
|
|
|
in
|
|
|
|
helpers.mkRaw wrapped;
|
2022-08-05 15:01:10 +01:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
snippet = helpers.ifNonNull' cfg.snippet {
|
2023-03-12 22:31:32 +01:00
|
|
|
expand = let
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.snippet) expand;
|
2023-03-12 22:31:32 +01:00
|
|
|
in
|
|
|
|
if isString expand
|
|
|
|
then
|
|
|
|
helpers.mkRaw ''
|
|
|
|
function(args)
|
|
|
|
${snippetEngines.${expand}}
|
|
|
|
end
|
|
|
|
''
|
|
|
|
else expand;
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
completion = helpers.ifNonNull' cfg.completion {
|
|
|
|
keyword_length = cfg.completion.keywordLength;
|
|
|
|
keyword_pattern = let
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.completion) keywordPattern;
|
2023-03-12 18:52:02 +01:00
|
|
|
in
|
|
|
|
helpers.ifNonNull' keywordPattern
|
|
|
|
(helpers.mkRaw "[[${keywordPattern}]]");
|
|
|
|
autocomplete = let
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.completion) autocomplete;
|
2023-03-12 18:52:02 +01:00
|
|
|
in
|
|
|
|
if isList autocomplete
|
|
|
|
then
|
|
|
|
map
|
|
|
|
(triggerEvent:
|
|
|
|
helpers.mkRaw "require('cmp.types').cmp.TriggerEvent.${triggerEvent}")
|
|
|
|
autocomplete
|
|
|
|
# either null or false
|
|
|
|
else autocomplete;
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.completion) completeopt;
|
2023-03-12 18:52:02 +01:00
|
|
|
};
|
2022-08-05 15:01:10 +01:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
confirmation = helpers.ifNonNull' cfg.confirmation {
|
|
|
|
get_commit_characters =
|
|
|
|
if (isString cfg.confirmation.getCommitCharacters)
|
|
|
|
then helpers.mkRaw cfg.confirmation.getCommitCharacters
|
|
|
|
else cfg.confirmation.getCommitCharacters;
|
|
|
|
};
|
2022-08-05 15:01:10 +01:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
formatting = helpers.ifNonNull' cfg.formatting {
|
|
|
|
expandable_indicator = cfg.formatting.expandableIndicator;
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.formatting) fields;
|
2023-03-12 18:52:02 +01:00
|
|
|
format =
|
|
|
|
helpers.ifNonNull' cfg.formatting.format
|
|
|
|
(helpers.mkRaw cfg.formatting.format);
|
|
|
|
};
|
2022-08-05 15:01:10 +01:00
|
|
|
|
2023-03-12 18:52:02 +01:00
|
|
|
matching = helpers.ifNonNull' cfg.matching {
|
|
|
|
disallow_fuzzy_matching = cfg.matching.disallowFuzzyMatching;
|
|
|
|
disallow_fullfuzzy_matching = cfg.matching.disallowFullfuzzyMatching;
|
|
|
|
disallow_partial_fuzzy_matching = cfg.matching.disallowPartialFuzzyMatching;
|
|
|
|
disallow_partial_matching = cfg.matching.disallowPartialMatching;
|
|
|
|
disallow_prefix_unmatching = cfg.matching.disallowPrefixUnmatching;
|
|
|
|
};
|
|
|
|
|
|
|
|
sorting = helpers.ifNonNull' cfg.sorting {
|
|
|
|
priority_weight = cfg.sorting.priorityWeight;
|
|
|
|
comparators = let
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.sorting) comparators;
|
2023-03-12 18:52:02 +01:00
|
|
|
in
|
|
|
|
helpers.ifNonNull' comparators
|
|
|
|
(
|
|
|
|
map
|
|
|
|
(
|
|
|
|
funcName:
|
|
|
|
helpers.mkRaw "require('cmp.config.compare').${funcName}"
|
|
|
|
)
|
|
|
|
comparators
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
sources = helpers.ifNonNull' cfg.sources (
|
|
|
|
map
|
|
|
|
(source: {
|
|
|
|
inherit (source) name option;
|
|
|
|
keyword_length = source.keywordLength;
|
|
|
|
|
|
|
|
keywordPattern =
|
|
|
|
helpers.ifNonNull' source.keywordPattern
|
|
|
|
(helpers.mkRaw "[[${source.keywordPattern}]]");
|
|
|
|
|
|
|
|
trigger_characters = source.triggerCharacters;
|
|
|
|
|
|
|
|
inherit (source) priority;
|
|
|
|
|
|
|
|
max_item_count = source.maxItemCount;
|
|
|
|
|
|
|
|
group_index = source.groupIndex;
|
|
|
|
|
|
|
|
entry_filter = source.entryFilter;
|
|
|
|
})
|
|
|
|
cfg.sources
|
|
|
|
);
|
2022-08-05 15:01:10 +01:00
|
|
|
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg) view;
|
2023-03-12 18:52:02 +01:00
|
|
|
window = helpers.ifNonNull' cfg.window {
|
|
|
|
completion = helpers.ifNonNull' cfg.window.completion {
|
|
|
|
inherit
|
|
|
|
(cfg.window.completion)
|
|
|
|
border
|
|
|
|
winhighlight
|
|
|
|
zindex
|
|
|
|
scrolloff
|
|
|
|
scrollbar
|
|
|
|
;
|
|
|
|
col_offset = cfg.window.completion.colOffset;
|
|
|
|
side_padding = cfg.window.completion.sidePadding;
|
|
|
|
};
|
|
|
|
documentation = helpers.ifNonNull' cfg.window.completion {
|
|
|
|
inherit
|
|
|
|
(cfg.window.completion)
|
|
|
|
border
|
|
|
|
winhighlight
|
|
|
|
zindex
|
|
|
|
;
|
|
|
|
max_width = let
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.window.documentation) maxWidth;
|
2023-03-12 18:52:02 +01:00
|
|
|
in
|
|
|
|
if isInt maxWidth
|
|
|
|
then maxWidth
|
|
|
|
else helpers.ifNonNull' maxWidth (helpers.mkRaw maxWidth);
|
|
|
|
max_height = let
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.window.documentation) maxHeight;
|
2023-03-12 18:52:02 +01:00
|
|
|
in
|
|
|
|
if isInt maxHeight
|
|
|
|
then maxHeight
|
|
|
|
else helpers.ifNonNull' maxHeight (helpers.mkRaw maxHeight);
|
|
|
|
};
|
|
|
|
};
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg) experimental;
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
|
|
|
in
|
2022-08-05 15:01:10 +01:00
|
|
|
mkIf cfg.enable {
|
2023-02-20 11:42:13 +01:00
|
|
|
extraPlugins = [cfg.package];
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2022-10-25 01:17:02 +02:00
|
|
|
extraConfigLua = helpers.wrapDo ''
|
2022-09-18 11:19:23 +01:00
|
|
|
local cmp = require('cmp')
|
|
|
|
cmp.setup(${helpers.toLuaObject options})
|
|
|
|
'';
|
2022-07-28 21:38:38 +02:00
|
|
|
|
2022-09-18 11:19:23 +01:00
|
|
|
# If auto_enable_sources is set to true, figure out which are provided by the user
|
|
|
|
# and enable the corresponding plugins.
|
2023-02-20 11:42:13 +01:00
|
|
|
plugins = let
|
|
|
|
flattened_sources =
|
2023-05-22 15:45:47 +05:30
|
|
|
if (cfg.sources == null)
|
2023-02-20 11:42:13 +01:00
|
|
|
then []
|
|
|
|
else flatten cfg.sources;
|
|
|
|
# Take only the names from the sources provided by the user
|
|
|
|
found_sources = lists.unique (lists.map (source: source.name) flattened_sources);
|
|
|
|
# A list of known source names
|
|
|
|
known_source_names = attrNames cmpLib.pluginAndSourceNames;
|
|
|
|
|
|
|
|
attrs_enabled = listToAttrs (map
|
|
|
|
(name: {
|
|
|
|
name = cmpLib.pluginAndSourceNames.${name};
|
|
|
|
value.enable = mkIf (elem name found_sources) true;
|
|
|
|
})
|
|
|
|
known_source_names);
|
|
|
|
in
|
2023-02-20 17:32:05 +01:00
|
|
|
mkMerge [
|
2023-03-12 18:52:02 +01:00
|
|
|
(mkIf cfg.autoEnableSources attrs_enabled)
|
2023-02-20 17:32:05 +01:00
|
|
|
(mkIf (elem "nvim_lsp" found_sources)
|
|
|
|
{
|
|
|
|
lsp.capabilities = ''
|
|
|
|
capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
2022-07-28 21:38:38 +02:00
|
|
|
};
|
|
|
|
}
|