mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-24 09:48:42 +02:00
plugins/cmp: refactoring
This commit is contained in:
parent
90fbde275c
commit
c10e73fb65
2 changed files with 330 additions and 314 deletions
148
plugins/completion/nvim-cmp/setup-options.nix
Normal file
148
plugins/completion/nvim-cmp/setup-options.nix
Normal file
|
@ -0,0 +1,148 @@
|
|||
{
|
||||
cfg,
|
||||
lib,
|
||||
helpers,
|
||||
}:
|
||||
with lib; let
|
||||
# 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 =
|
||||
mapAttrs
|
||||
(
|
||||
key: action:
|
||||
helpers.mkRaw (
|
||||
if isString action
|
||||
then action
|
||||
else let
|
||||
inherit (action) modes;
|
||||
modesString =
|
||||
optionalString
|
||||
(
|
||||
(modes != null)
|
||||
&& ((length modes) >= 1)
|
||||
)
|
||||
("," + (helpers.toLuaObject modes));
|
||||
in "cmp.mapping(${action.action}${modesString})"
|
||||
)
|
||||
)
|
||||
cfg.mapping;
|
||||
|
||||
luaMappings = helpers.toLuaObject mappings;
|
||||
|
||||
wrapped =
|
||||
lists.fold
|
||||
(
|
||||
presetName: prevString: ''cmp.mapping.preset.${presetName}(${prevString})''
|
||||
)
|
||||
luaMappings
|
||||
cfg.mappingPresets;
|
||||
in
|
||||
helpers.mkRaw wrapped;
|
||||
|
||||
sources' = let
|
||||
convertSourceAttrs = source:
|
||||
with source; {
|
||||
inherit
|
||||
name
|
||||
option
|
||||
;
|
||||
keyword_length = keywordLength;
|
||||
keywordPattern =
|
||||
helpers.ifNonNull' keywordPattern (helpers.mkRaw "[[${keywordPattern}]]");
|
||||
trigger_characters = triggerCharacters;
|
||||
inherit priority;
|
||||
group_index = groupIndex;
|
||||
entry_filter = entryFilter;
|
||||
};
|
||||
in
|
||||
if cfg.sources == null || cfg.sources == []
|
||||
then null
|
||||
# List of lists of sources -> we use the `cmp.config.sources` helper
|
||||
else if isList (head cfg.sources)
|
||||
then let
|
||||
sourcesListofLists =
|
||||
map
|
||||
(map convertSourceAttrs)
|
||||
cfg.sources;
|
||||
in
|
||||
helpers.mkRaw "cmp.config.sources(${helpers.toLuaObject sourcesListofLists})"
|
||||
# List of sources
|
||||
else map convertSourceAttrs cfg.sources;
|
||||
in
|
||||
with cfg;
|
||||
{
|
||||
performance = with performance; {
|
||||
inherit
|
||||
debounce
|
||||
throttle
|
||||
;
|
||||
fetching_timeout = fetchingTimeout;
|
||||
async_budget = asyncBudget;
|
||||
max_view_entries = maxViewEntries;
|
||||
};
|
||||
inherit preselect;
|
||||
inherit mapping';
|
||||
snippet = with snippet; {
|
||||
inherit expand;
|
||||
};
|
||||
completion = with completion; {
|
||||
keyword_length = keywordLength;
|
||||
keyword_pattern = keywordPattern;
|
||||
inherit
|
||||
autocomplete
|
||||
completeopt
|
||||
;
|
||||
};
|
||||
confirmation = with confirmation; {
|
||||
get_commit_characters = getCommitCharacters;
|
||||
};
|
||||
formatting = with formatting; {
|
||||
expandable_indicator = expandableIndicator;
|
||||
inherit fields format;
|
||||
};
|
||||
matching = with matching; {
|
||||
disallow_fuzzy_matching = disallowFuzzyMatching;
|
||||
disallow_fullfuzzy_matching = disallowFullfuzzyMatching;
|
||||
disallow_partial_fuzzy_matching = disallowPartialFuzzyMatching;
|
||||
disallow_partial_matching = disallowPartialMatching;
|
||||
disallow_prefix_unmatching = disallowPrefixUnmatching;
|
||||
};
|
||||
sorting = with sorting; {
|
||||
priority_weight = priorityWeight;
|
||||
inherit comparators;
|
||||
};
|
||||
inherit sources';
|
||||
view = with view; {
|
||||
inherit entries;
|
||||
docs = with docs; {
|
||||
auto_open = autoOpen;
|
||||
};
|
||||
};
|
||||
window = with window; {
|
||||
completion = with completion; {
|
||||
inherit
|
||||
border
|
||||
winhighlight
|
||||
zindex
|
||||
scrolloff
|
||||
;
|
||||
col_offset = colOffset;
|
||||
side_padding = sidePadding;
|
||||
inherit scrollbar;
|
||||
};
|
||||
documentation = with documentation; {
|
||||
inherit
|
||||
border
|
||||
winhighlight
|
||||
zindex
|
||||
;
|
||||
max_width = maxWidth;
|
||||
max_height = maxHeight;
|
||||
};
|
||||
};
|
||||
inherit experimental;
|
||||
}
|
||||
// cfg.extraOptions
|
Loading…
Add table
Add a link
Reference in a new issue