mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +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'
|
mkIfNonNull'
|
||||||
mkRaw
|
mkRaw
|
||||||
mkRawKey
|
mkRawKey
|
||||||
|
mkWarnings
|
||||||
nestedLiteral
|
nestedLiteral
|
||||||
nestedLiteralLua
|
nestedLiteralLua
|
||||||
override
|
override
|
||||||
|
|
|
@ -158,6 +158,7 @@ rec {
|
||||||
```
|
```
|
||||||
|
|
||||||
# Type
|
# Type
|
||||||
|
|
||||||
```
|
```
|
||||||
literalLua :: String -> AttrSet
|
literalLua :: String -> AttrSet
|
||||||
```
|
```
|
||||||
|
@ -172,6 +173,34 @@ rec {
|
||||||
in
|
in
|
||||||
lib.literalExpression exp;
|
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.
|
Convert the given string into a `__pretty` printed mkRaw expression.
|
||||||
|
|
||||||
|
@ -190,6 +219,7 @@ rec {
|
||||||
```
|
```
|
||||||
|
|
||||||
# Type
|
# Type
|
||||||
|
|
||||||
```
|
```
|
||||||
nestedLiteralLua :: String -> AttrSet
|
nestedLiteralLua :: String -> AttrSet
|
||||||
```
|
```
|
||||||
|
@ -221,6 +251,7 @@ rec {
|
||||||
```
|
```
|
||||||
|
|
||||||
# Type
|
# Type
|
||||||
|
|
||||||
```
|
```
|
||||||
nestedLiteral :: (String | literalExpression) -> AttrSet
|
nestedLiteral :: (String | literalExpression) -> AttrSet
|
||||||
```
|
```
|
||||||
|
|
|
@ -490,6 +490,30 @@ let
|
||||||
"mkAfter list".foo.bar = lib.mkAfter "Hello!";
|
"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
|
in
|
||||||
if results == [ ] then
|
if results == [ ] then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue