mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
modules/filetype: ensure that the module does not set empty settings
When setting any filetype suboption to null (or anything else guarded by mkIf) it's value becomes: { extension = null; filename = null; pattern = null; } Account for that case in mkIf condition so that the option would not produce empty filetype definition.
This commit is contained in:
parent
d2f733efb4
commit
34aa3e00e7
2 changed files with 24 additions and 3 deletions
|
@ -6,6 +6,8 @@
|
||||||
}:
|
}:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
|
cfg = config.filetype;
|
||||||
|
|
||||||
filetypeDefinition = helpers.mkNullOrOption (
|
filetypeDefinition = helpers.mkNullOrOption (
|
||||||
with types;
|
with types;
|
||||||
attrsOf (oneOf [
|
attrsOf (oneOf [
|
||||||
|
@ -52,7 +54,9 @@ in
|
||||||
pattern = filetypeDefinition "set filetypes matching the specified pattern";
|
pattern = filetypeDefinition "set filetypes matching the specified pattern";
|
||||||
};
|
};
|
||||||
|
|
||||||
config.extraConfigLua = helpers.mkIfNonNull' config.filetype ''
|
config.extraConfigLua =
|
||||||
vim.filetype.add(${helpers.toLuaObject config.filetype})
|
lib.mkIf (cfg != null && (builtins.any (v: v != null) (builtins.attrValues cfg)))
|
||||||
'';
|
''
|
||||||
|
vim.filetype.add(${helpers.toLuaObject cfg})
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,21 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
default-empty.module =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
files.test = { };
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = builtins.match ".*vim\.filetype\..*" config.content == null;
|
||||||
|
message = "No vim.filetype definitions should be present in init.lua by default.";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assertion = builtins.match ".*vim\.filetype\..*" config.files.test.content == null;
|
||||||
|
message = "No vim.filetype definitions should be present in files submodules by default.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue