mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
lib/utils: add mkWarnings
This commit is contained in:
parent
1036b8f8b6
commit
02e16b2a76
3 changed files with 56 additions and 0 deletions
|
@ -86,6 +86,7 @@ lib.makeExtensible (
|
|||
mkIfNonNull'
|
||||
mkRaw
|
||||
mkRawKey
|
||||
mkWarnings
|
||||
nestedLiteral
|
||||
nestedLiteralLua
|
||||
override
|
||||
|
|
|
@ -158,6 +158,7 @@ rec {
|
|||
```
|
||||
|
||||
# Type
|
||||
|
||||
```
|
||||
literalLua :: String -> AttrSet
|
||||
```
|
||||
|
@ -172,6 +173,34 @@ rec {
|
|||
in
|
||||
lib.literalExpression exp;
|
||||
|
||||
/**
|
||||
Convert one or several conditional warnings to a final warning list.
|
||||
The second argument can either be a list of _conditional warnings_ or a single one.
|
||||
|
||||
# Example
|
||||
|
||||
```nix
|
||||
warnings = mkWarnings "plugins.foo" {
|
||||
when = plugins.foo.settings.barIntegration && (!plugins.bar.enable);
|
||||
message = "`barIntegration` is enabled but the `bar` plugin is not."
|
||||
}
|
||||
```
|
||||
|
||||
# Type
|
||||
|
||||
```
|
||||
mkWarnings :: String -> List -> List
|
||||
```
|
||||
*/
|
||||
mkWarnings =
|
||||
scope: warnings:
|
||||
let
|
||||
processWarning =
|
||||
warning:
|
||||
lib.optional (warning.when or true) "Nixvim (${scope}): ${lib.trim (warning.message or warning)}";
|
||||
in
|
||||
builtins.concatMap processWarning (lib.toList warnings);
|
||||
|
||||
/**
|
||||
Convert the given string into a `__pretty` printed mkRaw expression.
|
||||
|
||||
|
@ -190,6 +219,7 @@ rec {
|
|||
```
|
||||
|
||||
# Type
|
||||
|
||||
```
|
||||
nestedLiteralLua :: String -> AttrSet
|
||||
```
|
||||
|
@ -221,6 +251,7 @@ rec {
|
|||
```
|
||||
|
||||
# Type
|
||||
|
||||
```
|
||||
nestedLiteral :: (String | literalExpression) -> AttrSet
|
||||
```
|
||||
|
|
|
@ -490,6 +490,30 @@ let
|
|||
"mkAfter list".foo.bar = lib.mkAfter "Hello!";
|
||||
};
|
||||
};
|
||||
|
||||
testMkWarnings = {
|
||||
expr =
|
||||
(lib.nixvim.mkWarnings "foo-bar" [
|
||||
{
|
||||
when = true;
|
||||
message = "This is the message";
|
||||
}
|
||||
{
|
||||
when = false;
|
||||
message = "This should not be included";
|
||||
}
|
||||
"This is an unconditional warning"
|
||||
])
|
||||
++ (lib.nixvim.mkWarnings "single-element") {
|
||||
when = true;
|
||||
message = "Hello";
|
||||
};
|
||||
expected = [
|
||||
"Nixvim (foo-bar): This is the message"
|
||||
"Nixvim (foo-bar): This is an unconditional warning"
|
||||
"Nixvim (single-element): Hello"
|
||||
];
|
||||
};
|
||||
};
|
||||
in
|
||||
if results == [ ] then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue