plugins/nvim-cmp: refactor + tests (#237)

This commit is contained in:
Gaétan Lepage 2023-03-12 18:52:02 +01:00 committed by GitHub
parent 7c6f71199b
commit bfbe737aa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 580 additions and 287 deletions

View file

@ -7,89 +7,53 @@
with lib; let with lib; let
cfg = config.plugins.nvim-cmp; cfg = config.plugins.nvim-cmp;
helpers = import ../../helpers.nix {inherit lib;}; helpers = import ../../helpers.nix {inherit lib;};
mkNullOrOption = helpers.mkNullOrOption;
cmpLib = import ./cmp-helpers.nix args; cmpLib = import ./cmp-helpers.nix args;
# functionName should be a string
# parameters should be a list of strings
wrapWithFunction = functionName: parameters: let
parameterString = strings.concatStringsSep "," parameters;
in ''${functionName}(${parameterString})'';
in { in {
options.plugins.nvim-cmp = { options.plugins.nvim-cmp = {
enable = mkEnableOption "nvim-cmp"; enable = mkEnableOption "nvim-cmp";
package = helpers.mkPackageOption "nvim-cmp" pkgs.vimPlugins.nvim-cmp; package = helpers.mkPackageOption "nvim-cmp" pkgs.vimPlugins.nvim-cmp;
performance = mkOption { performance = helpers.mkCompositeOption "Performance options" {
default = null; debounce = helpers.defaultNullOpts.mkInt 60 ''
type = types.nullOr (types.submodule ({...}: { Sets debounce time
options = { This is the interval used to group up completions from different sources
debounce = mkOption { for filtering and displaying.
type = types.nullOr types.int; '';
default = null;
};
throttle = mkOption {
type = types.nullOr types.int;
default = null;
};
};
}));
};
preselect = mkOption { throttle = helpers.defaultNullOpts.mkInt 30 ''
type = types.nullOr (types.enum ["Item" "None"]); Sets throttle time.
default = null; This is used to delay filtering and displaying completions.
example = ''"Item"''; '';
};
snippet = mkOption { fetchingTimeout = helpers.defaultNullOpts.mkInt 500 ''
default = null; Sets the timeout of candidate fetching process.
type = types.nullOr (types.submodule ({...}: { The nvim-cmp will wait to display the most prioritized source.
options = {
expand = mkOption {
type = types.nullOr types.str;
example = ''
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
'';
};
};
}));
};
mappingPresets = mkOption {
default = [];
type = types.listOf (types.enum [
"insert"
"cmdline"
# Not sure if there are more or if this should just be str
]);
description = "Mapping presets to use; cmp.mapping.preset.\${mappingPreset} will be called with the configured mappings";
example = ''
[ "insert" "cmdline" ]
''; '';
}; };
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.
'';
mapping = mkOption { mapping = mkOption {
default = null; default = null;
type = types.nullOr (types.attrsOf (types.either types.str (types.submodule ({...}: { type = with types;
options = { nullOr (attrsOf (either str (types.submodule ({...}: {
action = mkOption { options = {
type = types.nonEmptyStr; action = mkOption {
description = "The function the mapping should call"; type = types.nonEmptyStr;
example = ''"cmp.mapping.scroll_docs(-4)"''; 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" ]'';
};
}; };
modes = mkOption { }))));
default = null;
type = types.nullOr (types.listOf types.str);
example = ''[ "i" "s" ]'';
};
};
}))));
example = '' example = ''
{ {
"<CR>" = "cmp.mapping.confirm({ select = true })"; "<CR>" = "cmp.mapping.confirm({ select = true })";
@ -115,103 +79,161 @@ in {
''; '';
}; };
completion = mkOption { mappingPresets = mkOption {
default = null; default = [];
type = types.nullOr (types.submodule ({...}: { type = types.listOf (types.enum [
options = { "insert"
keyword_length = mkOption { "cmdline"
default = null; ]);
type = types.nullOr types.int; description = ''
}; Mapping presets to use; cmp.mapping.preset.
\$\{mappingPreset} will be called with the configured mappings.
keyword_pattern = mkOption { '';
default = null; example = ''[ "insert" "cmdline" ]'';
type = types.nullOr types.str;
};
autocomplete = mkOption {
default = null;
type = types.nullOr types.str;
description = "Lua code for the event.";
example = ''"false"'';
};
completeopt = mkOption {
default = null;
type = types.nullOr types.str;
};
};
}));
}; };
confirmation = mkOption { snippet = helpers.mkCompositeOption "Snippet options" {
default = null; expand =
type = types.nullOr (types.submodule ({...}: { helpers.defaultNullOpts.mkStr
options = { ''
get_commit_characters = mkOption { function(_)
default = null; error('snippet engine is not configured.')
type = types.nullOr types.str; end
description = "Direct lua code as a string"; ''
}; ''
}; The snippet expansion function. That's how nvim-cmp interacts with a
})); particular snippet engine.
Example:
```
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
```
'';
}; };
formatting = mkOption { completion = helpers.mkCompositeOption "Completion options" {
default = null; keywordLength = helpers.defaultNullOpts.mkInt 1 ''
type = types.nullOr (types.submodule ({...}: { The number of characters needed to trigger auto-completion.
options = { '';
fields = mkOption {
default = null; keywordPattern =
type = types.nullOr (types.listOf types.str); helpers.defaultNullOpts.mkStr
example = ''[ "kind" "abbr" "menu" ]''; ''\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)''
}; ''
format = mkOption { The default keyword pattern.
default = null;
type = types.nullOr types.str; Note: the provided pattern will be embedded as such: `[[PATTERN]]`.
description = "A lua function as a string"; '';
};
}; 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.
'';
}; };
matching = mkOption { confirmation = helpers.mkCompositeOption "Confirmation options" {
default = null; getCommitCharacters =
type = types.nullOr (types.submodule ({...}: { helpers.defaultNullOpts.mkStr
options = { ''
disallow_fuzzy_matching = mkOption { function(commit_characters)
default = null; return commit_characters
type = types.nullOr types.bool; end
}; ''
disallow_partial_matching = mkOption { ''
default = null; You can append or exclude commitCharacters via this configuration option
type = types.nullOr types.bool; function. The commitCharacters are defined by the LSP spec.
}; '';
disallow_prefix_unmatching = mkOption {
default = null;
type = types.nullOr types.bool;
};
};
}));
}; };
sorting = mkOption { formatting = helpers.mkCompositeOption "Formatting options" {
default = null; expandableIndicator = helpers.defaultNullOpts.mkBool true ''
type = types.nullOr (types.submodule ({...}: { Boolean to show the `~` expandable indicator in cmp's floating window.
options = { '';
priority_weight = mkOption {
default = null; fields =
type = types.nullOr types.int; helpers.defaultNullOpts.mkNullable
}; (types.listOf types.str)
comparators = mkOption { ''[ "kind" "abbr" "menu" ]''
default = null; "An array of completion fields to specify their order.";
type = types.nullOr types.str;
}; 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`.
'';
}; };
auto_enable_sources = mkOption { 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.
'';
};
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)[]`
'';
};
autoEnableSources = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
description = '' description = ''
@ -228,51 +250,97 @@ in {
example = ''"buffer"''; example = ''"buffer"'';
}; };
option = mkOption { option = helpers.mkNullOrOption (types.attrs) ''
default = null; Any specific options defined by the source itself.
type = with types; nullOr (attrsOf anything);
description = "If direct lua code is needed use helpers.mkRaw";
};
keyword_length = mkOption { If direct lua code is needed use `helpers.mkRaw`.
default = null; '';
type = types.nullOr types.int;
};
keyword_pattern = mkOption { keywordLength = helpers.mkNullOrOption types.int ''
default = null; The source-specific keyword length to trigger auto completion.
type = types.nullOr types.int; '';
};
trigger_characters = mkOption { keywordPattern = helpers.mkNullOrOption types.str ''
default = null; The source-specific keyword pattern.
type = with types; nullOr (listOf str);
};
priority = mkOption { Note: the provided pattern will be embedded as such: `[[PATTERN]]`.
default = null; '';
type = types.nullOr types.int;
};
max_item_count = mkOption { triggerCharacters = helpers.mkNullOrOption (types.listOf types.str) ''
default = null; A source-specific keyword pattern.
type = types.nullOr types.int; '';
};
group_index = mkOption { priority = helpers.mkNullOrOption types.int "The source-specific priority value.";
default = null;
type = types.nullOr types.int; 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.
'';
}; };
}); });
in in
mkOption { mkOption {
default = null; default = null;
type = with types; nullOr (either (listOf source_config) (listOf (listOf source_config))); type = with types;
nullOr (
either
(listOf source_config)
(listOf (listOf source_config))
);
description = '' description = ''
The sources to use. The sources to use.
Can either be a list of sourceConfigs which will be made directly to a Lua object. 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`. Or it can be a list of lists, which will use the cmp built-in helper function
`cmp.config.sources`.
Default: [ ]
''; '';
example = '' example = ''
[ [
@ -284,55 +352,96 @@ in {
''; '';
}; };
view = mkOption { view = helpers.mkCompositeOption "View options" {
default = null; entries =
type = types.nullOr (types.submodule ({...}: { helpers.defaultNullOpts.mkNullable (with types; either str attrs)
options = { ''
entries = mkOption { {
default = null; name = "custom";
type = with types; nullOr (either str attrs); selection_order = "top_down";
}; }
}; ''
})); ''
The view class used to customize nvim-cmp's appearance.
'';
}; };
window = let window = let
# Reusable options # Reusable options
border = with types; mkNullOrOption (either str (listOf str)) null; mkBorderOption = default:
winhighlight = mkNullOrOption types.str null; helpers.defaultNullOpts.mkNullable
zindex = mkNullOrOption types.int null; (with types; either str (listOf str))
in default
mkOption { ''
default = null; Border characters used for the completion popup menu when |experimental.native_menu| is disabled.
type = types.nullOr (types.submodule ({...}: { See |nvim_open_win|.
options = { '';
completion = mkOption {
default = null;
type = types.nullOr (types.submodule ({...}: {
options = {
inherit border winhighlight zindex;
col_offset = mkNullOrOption types.int "Offsets the completion window relative to the cursor";
side_padding = mkNullOrOption types.int "The amount of padding to add on the completion window's sides";
};
}));
};
documentation = mkOption { mkWinhighlightOption = default:
default = null; helpers.defaultNullOpts.mkStr
type = types.nullOr (types.submodule ({...}: { default
options = { ''
inherit border winhighlight zindex; Specify the window's winhighlight option.
max_width = mkNullOrOption types.int "Window's max width"; See |nvim_open_win|.
max_height = mkNullOrOption types.int "Window's max height"; '';
};
})); zindex = helpers.mkNullOrOption types.int ''
}; The completion window's zindex.
}; See |nvim_open_win|.
})); '';
in
helpers.mkCompositeOption "Windows options" {
completion = helpers.mkCompositeOption "Completion window options" {
border = mkBorderOption ''[ "" "" "" "" "" "" "" "" ]'';
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.";
};
}; };
# This can be kept as types.attrs since experimental features are often removed or completely changed after a while # This can be kept as types.attrs since experimental features are often removed or completely
experimental = mkNullOrOption types.attrs "Experimental features"; # changed after a while
experimental = helpers.mkNullOrOption types.attrs "Experimental features";
}; };
config = let config = let
@ -340,9 +449,8 @@ in {
enabled = cfg.enable; enabled = cfg.enable;
performance = cfg.performance; performance = cfg.performance;
preselect = preselect =
if (isNull cfg.preselect) helpers.ifNonNull' cfg.preselect
then null (helpers.mkRaw "cmp.PreselectMode.${cfg.preselect}");
else helpers.mkRaw "cmp.PreselectMode.${cfg.preselect}";
# Not very readable sorry # Not very readable sorry
# If null then null # If null then null
@ -350,79 +458,158 @@ in {
# 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. # 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 mapping = let
mappings = mappings =
if (isNull cfg.mapping) helpers.ifNonNull' cfg.mapping
then null (mapAttrs
else
mapAttrs
(bind: mapping: (bind: mapping:
helpers.mkRaw ( helpers.mkRaw (
if isString mapping if isString mapping
then mapping then mapping
else "cmp.mapping(${mapping.action}${optionalString (mapping.modes != null && length mapping.modes >= 1) ("," + (helpers.toLuaObject mapping.modes))})" else let
modes = mapping.modes;
modesString =
optionalString (!isNull modes && ((length modes) >= 1))
("," + (helpers.toLuaObject mapping.modes));
in "cmp.mapping(${mapping.action}${modesString})"
)) ))
cfg.mapping; cfg.mapping);
luaMappings = helpers.toLuaObject mappings; luaMappings = helpers.toLuaObject mappings;
wrapped = lists.fold (presetName: prevString: ''cmp.mapping.preset.${presetName}(${prevString})'') luaMappings cfg.mappingPresets;
wrapped =
lists.fold
(
presetName: prevString: ''cmp.mapping.preset.${presetName}(${prevString})''
)
luaMappings
cfg.mappingPresets;
in in
helpers.mkRaw wrapped; helpers.mkRaw wrapped;
snippet = { snippet = helpers.ifNonNull' cfg.snippet {
expand = expand =
if (isNull cfg.snippet || isNull cfg.snippet.expand) helpers.ifNonNull'
then null cfg.snippet.expand
else helpers.mkRaw cfg.snippet.expand; (helpers.mkRaw cfg.snippet.expand);
}; };
completion = completion = helpers.ifNonNull' cfg.completion {
if (isNull cfg.completion) keyword_length = cfg.completion.keywordLength;
then null keyword_pattern = let
else { keywordPattern = cfg.completion.keywordPattern;
keyword_length = cfg.completion.keyword_length; in
keyword_pattern = cfg.completion.keyword_pattern; helpers.ifNonNull' keywordPattern
autocomplete = (helpers.mkRaw "[[${keywordPattern}]]");
if (isNull cfg.completion.autocomplete) autocomplete = let
then null autocomplete = cfg.completion.autocomplete;
else helpers.mkRaw cfg.completion.autocomplete; in
completeopt = cfg.completion.completeopt; if isList autocomplete
}; then
map
(triggerEvent:
helpers.mkRaw "require('cmp.types').cmp.TriggerEvent.${triggerEvent}")
autocomplete
# either null or false
else autocomplete;
completeopt = cfg.completion.completeopt;
};
confirmation = confirmation = helpers.ifNonNull' cfg.confirmation {
if (isNull cfg.confirmation) get_commit_characters =
then null if (isString cfg.confirmation.getCommitCharacters)
else { then helpers.mkRaw cfg.confirmation.getCommitCharacters
get_commit_characters = else cfg.confirmation.getCommitCharacters;
if (isString cfg.confirmation.get_commit_characters) };
then helpers.mkRaw cfg.confirmation.get_commit_characters
else cfg.confirmation.get_commit_characters;
};
formatting = formatting = helpers.ifNonNull' cfg.formatting {
if (isNull cfg.formatting) expandable_indicator = cfg.formatting.expandableIndicator;
then null fields = cfg.formatting.fields;
else { format =
fields = cfg.formatting.fields; helpers.ifNonNull' cfg.formatting.format
format = (helpers.mkRaw cfg.formatting.format);
if (isNull cfg.formatting.format) };
then null
else helpers.mkRaw cfg.formatting.format;
};
matching = cfg.matching; 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 = sorting = helpers.ifNonNull' cfg.sorting {
if (isNull cfg.sorting) priority_weight = cfg.sorting.priorityWeight;
then null comparators = let
else { comparators = cfg.sorting.comparators;
priority_weight = cfg.sorting.priority_weight; in
comparators = helpers.ifNonNull' comparators
if (isNull cfg.sorting.comparators) (
then null map
else helpers.mkRaw cfg.sorting.comparators; (
}; 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
);
sources = cfg.sources;
view = cfg.view; view = cfg.view;
window = cfg.window; 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
maxWidth = cfg.window.documentation.maxWidth;
in
if isInt maxWidth
then maxWidth
else helpers.ifNonNull' maxWidth (helpers.mkRaw maxWidth);
max_height = let
maxHeight = cfg.window.documentation.maxHeight;
in
if isInt maxHeight
then maxHeight
else helpers.ifNonNull' maxHeight (helpers.mkRaw maxHeight);
};
};
experimental = cfg.experimental; experimental = cfg.experimental;
}; };
in in
@ -454,7 +641,7 @@ in {
known_source_names); known_source_names);
in in
mkMerge [ mkMerge [
(mkIf cfg.auto_enable_sources attrs_enabled) (mkIf cfg.autoEnableSources attrs_enabled)
(mkIf (elem "nvim_lsp" found_sources) (mkIf (elem "nvim_lsp" found_sources)
{ {
lsp.capabilities = '' lsp.capabilities = ''

106
tests/plugins/nvim-cmp.nix Normal file
View file

@ -0,0 +1,106 @@
{
# Empty configuration
empty = {
plugins.nvim-cmp.enable = true;
};
# All the upstream default options of nvim-cmp
defaults = {
plugins.nvim-cmp = {
enable = true;
performance = {
debounce = 60;
throttle = 30;
fetchingTimeout = 500;
};
preselect = "Item";
snippet = {
expand = ''
function(_)
error('snippet engine is not configured.')
end
'';
};
completion = {
keywordLength = 1;
keywordPattern = ''\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)'';
autocomplete = ["TextChanged"];
completeopt = "menu,menuone,noselect";
};
confirmation = {
getCommitCharacters = ''
function(commit_characters)
return commit_characters
end
'';
};
formatting = {
expandableIndicator = true;
fields = ["abbr" "kind" "menu"];
format = ''
function(_, vim_item)
return vim_item
end
'';
};
matching = {
disallowFuzzyMatching = false;
disallowFullfuzzyMatching = false;
disallowPartialFuzzyMatching = true;
disallowPartialMatching = false;
disallowPrefixUnmatching = false;
};
sorting = {
priorityWeight = 2;
comparators = [
"offset"
"exact"
"score"
"recently_used"
"locality"
"kind"
"length"
"order"
];
};
sources = [];
experimental = {
ghost_text = false;
};
view = {
entries = {
name = "custom";
selection_order = "top_down";
};
};
window = {
completion = {
border = ["" "" "" "" "" "" "" ""];
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None";
scrolloff = 0;
colOffset = 0;
sidePadding = 1;
scrollbar = true;
};
documentation = {
maxHeight = "math.floor(40 * (40 / vim.o.lines))";
maxWidth = "math.floor((40 * 2) * (vim.o.columns / (40 * 2 * 16 / 9)))";
border = ["" "" "" " " "" "" "" " "];
winhighlight = "FloatBorder:NormalFloat";
};
};
};
};
}