mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
nvim-cmp: fix snippet not being able to be null
This commit is contained in:
parent
5cb317a5cb
commit
70dd3446fb
1 changed files with 192 additions and 166 deletions
|
@ -7,9 +7,11 @@ let
|
|||
cmpLib = import ./cmp-helpers.nix args;
|
||||
# functionName should be a string
|
||||
# parameters should be a list of strings
|
||||
wrapWithFunction = functionName: parameters: let
|
||||
wrapWithFunction = functionName: parameters:
|
||||
let
|
||||
parameterString = strings.concatStringsSep "," parameters;
|
||||
in ''${functionName}(${parameterString})'';
|
||||
in
|
||||
''${functionName}(${parameterString})'';
|
||||
in
|
||||
{
|
||||
options.programs.nixvim.plugins.nvim-cmp = {
|
||||
|
@ -68,6 +70,7 @@ in
|
|||
[ "insert" "cmdline" ]
|
||||
'';
|
||||
};
|
||||
|
||||
mapping = mkOption {
|
||||
default = null;
|
||||
type = types.nullOr (types.attrsOf (types.either types.str (types.submodule ({ ... }: {
|
||||
|
@ -212,7 +215,8 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
sources = let
|
||||
sources =
|
||||
let
|
||||
source_config = types.submodule ({ ... }: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
|
@ -258,7 +262,8 @@ in
|
|||
};
|
||||
};
|
||||
});
|
||||
in mkOption {
|
||||
in
|
||||
mkOption {
|
||||
default = null;
|
||||
type = with types; nullOr (either (listOf source_config) (listOf (listOf source_config)));
|
||||
description = ''
|
||||
|
@ -288,12 +293,14 @@ in
|
|||
}));
|
||||
};
|
||||
|
||||
window = let
|
||||
window =
|
||||
let
|
||||
# Reusable options
|
||||
border = with types; mkNullOrOption (either str (listOf str)) null;
|
||||
winhighlight = mkNullOrOption types.str null;
|
||||
zindex = mkNullOrOption types.int null;
|
||||
in mkOption {
|
||||
in
|
||||
mkOption {
|
||||
default = null;
|
||||
type = types.nullOr (types.submodule ({ ... }: {
|
||||
options = {
|
||||
|
@ -324,7 +331,8 @@ in
|
|||
experimental = mkNullOrOption types.attrs "Experimental features";
|
||||
};
|
||||
|
||||
config = let
|
||||
config =
|
||||
let
|
||||
options = {
|
||||
enabled = cfg.enable;
|
||||
performance = cfg.performance;
|
||||
|
@ -334,42 +342,56 @@ in
|
|||
# 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 = if (isNull cfg.mapping) then null
|
||||
else mapAttrs (bind: mapping: helpers.mkRaw (if isString mapping then mapping
|
||||
else "cmp.mapping(${mapping.action}${optionalString (mapping.modes != null && length mapping.modes >= 1) ("," + (helpers.toLuaObject mapping.modes))})")) cfg.mapping;
|
||||
mapping =
|
||||
let
|
||||
mappings =
|
||||
if (isNull cfg.mapping) then null
|
||||
else
|
||||
mapAttrs
|
||||
(bind: mapping: helpers.mkRaw (if isString mapping then mapping
|
||||
else "cmp.mapping(${mapping.action}${optionalString (mapping.modes != null && length mapping.modes >= 1) ("," + (helpers.toLuaObject mapping.modes))})"))
|
||||
cfg.mapping;
|
||||
luaMappings = (helpers.toLuaObject mappings);
|
||||
wrapped = lists.fold (presetName: prevString: ''cmp.mapping.preset.${presetName}(${prevString})'') luaMappings cfg.mappingPresets;
|
||||
in helpers.mkRaw wrapped;
|
||||
in
|
||||
helpers.mkRaw wrapped;
|
||||
|
||||
snippet = {
|
||||
expand = if (isNull cfg.snippet.expand) then null else helpers.mkRaw cfg.snippet.expand;
|
||||
expand = if (isNull cfg.snippet || isNull cfg.snippet.expand) then null else helpers.mkRaw cfg.snippet.expand;
|
||||
};
|
||||
|
||||
completion = if (isNull cfg.completion) then null else {
|
||||
keyword_length = cfg.completion.keyword_length;
|
||||
keyword_pattern = cfg.completion.keyword_pattern;
|
||||
autocomplete = if (isNull cfg.completion.autocomplete) then null else mkRaw cfg.completion.autocomplete;
|
||||
completeopt = cfg.completion.completeopt;
|
||||
};
|
||||
|
||||
confirmation = if (isNull cfg.confirmation) then null else {
|
||||
get_commit_characters =
|
||||
if (isString cfg.confirmation.get_commit_characters) then helpers.mkRaw cfg.confirmation.get_commit_characters
|
||||
else cfg.confirmation.get_commit_characters;
|
||||
};
|
||||
|
||||
formatting = if (isNull cfg.formatting) then null else {
|
||||
fields = cfg.formatting.fields;
|
||||
format = if (isNull cfg.formatting.format) then null else helpers.mkRaw cfg.formatting.format;
|
||||
};
|
||||
|
||||
matching = cfg.matching;
|
||||
|
||||
sorting = if (isNull cfg.sorting) then null else {
|
||||
priority_weight = cfg.sorting.priority_weight;
|
||||
comparators = if (isNull cfg.sorting.comparators) then null else helpers.mkRaw cfg.sorting.comparators;
|
||||
};
|
||||
|
||||
sources = cfg.sources;
|
||||
view = cfg.view;
|
||||
window = cfg.window;
|
||||
experimental = cfg.experimental;
|
||||
};
|
||||
in mkIf cfg.enable {
|
||||
in
|
||||
mkIf cfg.enable {
|
||||
programs.nixvim = {
|
||||
extraPlugins = [ pkgs.vimPlugins.nvim-cmp ];
|
||||
|
||||
|
@ -380,18 +402,22 @@ in
|
|||
|
||||
# If auto_enable_sources is set to true, figure out which are provided by the user
|
||||
# and enable the corresponding plugins.
|
||||
plugins = let
|
||||
plugins =
|
||||
let
|
||||
flattened_sources = if (isNull cfg.sources) 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: {
|
||||
attrs_enabled = listToAttrs (map
|
||||
(name: {
|
||||
name = cmpLib.pluginAndSourceNames.${name};
|
||||
value.enable = mkIf (elem name found_sources) true;
|
||||
}) known_source_names);
|
||||
in mkIf cfg.auto_enable_sources attrs_enabled;
|
||||
})
|
||||
known_source_names);
|
||||
in
|
||||
mkIf cfg.auto_enable_sources attrs_enabled;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue