mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-24 09:48:42 +02:00
helpers: Add option helpers for types that are either a lua str or a value (#876)
Those types needed the following code in apply: if builtins.isString value then mkRaw value else value This commit avoids this boilerplate, and clarifies that the `str` is lua code in the documentation.
This commit is contained in:
parent
8b8a1c0f4b
commit
8aa4b7e4ce
13 changed files with 109 additions and 129 deletions
|
@ -20,11 +20,7 @@ in {
|
|||
'';
|
||||
|
||||
timeout =
|
||||
helpers.defaultNullOpts.mkNullable
|
||||
(
|
||||
with types;
|
||||
either ints.unsigned str
|
||||
)
|
||||
helpers.defaultNullOpts.mkStrLuaOr types.ints.unsigned
|
||||
"vim.o.timeoutlen"
|
||||
''
|
||||
The time in which the keys must be hit in ms.
|
||||
|
@ -58,11 +54,7 @@ in {
|
|||
config = let
|
||||
setupOptions = with cfg;
|
||||
{
|
||||
inherit mapping;
|
||||
timeout =
|
||||
if isString timeout
|
||||
then helpers.mkRaw timeout
|
||||
else timeout;
|
||||
inherit mapping timeout;
|
||||
clear_empty_lines = clearEmptyLines;
|
||||
inherit keys;
|
||||
}
|
||||
|
|
|
@ -219,8 +219,7 @@ in {
|
|||
'';
|
||||
|
||||
transformExplicit =
|
||||
helpers.defaultNullOpts.mkNullable
|
||||
(with types; either str (enum [false]))
|
||||
helpers.defaultNullOpts.mkStrLuaFnOr (types.enum [false])
|
||||
"false"
|
||||
''
|
||||
A function that transforms the text to be inserted as the source/path of a link when a
|
||||
|
@ -241,8 +240,7 @@ in {
|
|||
'';
|
||||
|
||||
transformImplicit =
|
||||
helpers.defaultNullOpts.mkNullable
|
||||
(with types; either str (enum [false]))
|
||||
helpers.defaultNullOpts.mkStrLuaFnOr (types.enum [false])
|
||||
''
|
||||
function(text)
|
||||
text = text:gsub(" ", "-")
|
||||
|
@ -578,14 +576,8 @@ in {
|
|||
context
|
||||
;
|
||||
implicit_extension = implicitExtension;
|
||||
transform_implicit =
|
||||
if isString transformImplicit
|
||||
then helpers.mkRaw transformImplicit
|
||||
else transformImplicit;
|
||||
transform_explicit =
|
||||
if isString transformExplicit
|
||||
then helpers.mkRaw transformExplicit
|
||||
else transformExplicit;
|
||||
transform_implicit = transformImplicit;
|
||||
transform_explicit = transformExplicit;
|
||||
};
|
||||
to_do = with toDo; {
|
||||
inherit symbols;
|
||||
|
|
|
@ -13,26 +13,24 @@ in {
|
|||
|
||||
package = helpers.mkPackageOption "toggleterm" pkgs.vimPlugins.toggleterm-nvim;
|
||||
|
||||
size =
|
||||
helpers.defaultNullOpts.mkNullable
|
||||
(with types; either number str) "12" ''
|
||||
Size of the terminal.
|
||||
`size` can be a number or function
|
||||
Example:
|
||||
```nix
|
||||
size = 20
|
||||
```
|
||||
OR
|
||||
```
|
||||
size = function(term)
|
||||
if term.direction == "horizontal" then
|
||||
return 15
|
||||
elseif term.direction == "vertical" then
|
||||
return vim.o.columns * 0.4
|
||||
end
|
||||
size = helpers.defaultNullOpts.mkStrLuaFnOr types.number "12" ''
|
||||
Size of the terminal.
|
||||
`size` can be a number or function
|
||||
Example:
|
||||
```nix
|
||||
size = 20
|
||||
```
|
||||
OR
|
||||
```
|
||||
size = function(term)
|
||||
if term.direction == "horizontal" then
|
||||
return 15
|
||||
elseif term.direction == "vertical" then
|
||||
return vim.o.columns * 0.4
|
||||
end
|
||||
```
|
||||
'';
|
||||
end
|
||||
```
|
||||
'';
|
||||
|
||||
openMapping = helpers.mkNullOrOption types.str ''
|
||||
Setting the open_mapping key to use for toggling the terminal(s) will set up mappings for
|
||||
|
@ -170,12 +168,7 @@ in {
|
|||
};
|
||||
config = let
|
||||
setupOptions = with cfg; {
|
||||
inherit autochdir highlights direction shell;
|
||||
size = helpers.ifNonNull' size (
|
||||
if isInt size
|
||||
then size
|
||||
else helpers.mkRaw size
|
||||
);
|
||||
inherit autochdir highlights direction shell size;
|
||||
open_mapping = helpers.ifNonNull' openMapping (helpers.mkRaw "[[${openMapping}]]");
|
||||
on_create = onCreate;
|
||||
on_open = onOpen;
|
||||
|
|
|
@ -151,7 +151,7 @@ in {
|
|||
Setting the option after the first run has no effect.
|
||||
'';
|
||||
|
||||
pipeline = helpers.mkNullOrOption (with types; listOf str) ''
|
||||
pipeline = helpers.mkNullOrOption (with helpers.nixvimTypes; listOf strLua) ''
|
||||
Sets the pipeline to use to get completions.
|
||||
See `|wilder-pipeline|`.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue