treewide: Reformat with nixfmt

This commit is contained in:
traxys 2024-05-05 19:39:35 +02:00
parent c6281260dc
commit 62f32bfc71
459 changed files with 28139 additions and 26377 deletions

View file

@ -3,7 +3,8 @@
nixvimOptions,
nixvimTypes,
}:
with lib; rec {
with lib;
rec {
autoGroupOption = types.submodule {
options = {
clear = mkOption {
@ -75,7 +76,5 @@ with lib; rec {
nested = nixvimOptions.defaultNullOpts.mkBool false "Run nested autocommands.";
};
autoCmdOption = types.submodule {
options = autoCmdOptions;
};
autoCmdOption = types.submodule { options = autoCmdOptions; };
}

View file

@ -1,23 +1,22 @@
{ lib, pkgs }:
{
lib,
pkgs,
}: {
/*
Write a lua file to the nix store, formatted using stylua.
Write a lua file to the nix store, formatted using stylua.
# Type
# Type
```
writeLua :: String -> String -> Derivation
```
```
writeLua :: String -> String -> Derivation
```
# Arguments
# Arguments
- [name] The name of the derivation
- [text] The content of the lua file
- [name] The name of the derivation
- [text] The content of the lua file
*/
writeLua = name: text:
pkgs.runCommand name {inherit text;} ''
writeLua =
name: text:
pkgs.runCommand name { inherit text; } ''
echo -n "$text" > "$out"
${lib.getExe pkgs.stylua} \

View file

@ -5,10 +5,9 @@
pkgs,
_nixvimTests ? false,
...
} @ args: {
}@args:
{
# Add all exported modules here
check = import ../tests/test-derivation.nix {
inherit makeNixvim makeNixvimWithModule pkgs;
};
helpers = import ./helpers.nix (args // {inherit _nixvimTests;});
check = import ../tests/test-derivation.nix { inherit makeNixvim makeNixvimWithModule pkgs; };
helpers = import ./helpers.nix (args // { inherit _nixvimTests; });
}

View file

@ -3,22 +3,30 @@
pkgs,
_nixvimTests,
...
}: let
nixvimBuilders = import ./builders.nix {inherit lib pkgs;};
nixvimTypes = import ./types.nix {inherit lib nixvimOptions;};
nixvimUtils = import ./utils.nix {inherit lib _nixvimTests;};
nixvimOptions = import ./options.nix {inherit lib nixvimTypes nixvimUtils;};
inherit (import ./to-lua.nix {inherit lib;}) toLuaObject;
}:
let
nixvimBuilders = import ./builders.nix { inherit lib pkgs; };
nixvimTypes = import ./types.nix { inherit lib nixvimOptions; };
nixvimUtils = import ./utils.nix { inherit lib _nixvimTests; };
nixvimOptions = import ./options.nix { inherit lib nixvimTypes nixvimUtils; };
inherit (import ./to-lua.nix { inherit lib; }) toLuaObject;
in
{
maintainers = import ./maintainers.nix;
keymaps = import ./keymap-helpers.nix {inherit lib nixvimOptions nixvimTypes;};
autocmd = import ./autocmd-helpers.nix {inherit lib nixvimOptions nixvimTypes;};
neovim-plugin = import ./neovim-plugin.nix {inherit lib nixvimOptions nixvimUtils toLuaObject;};
vim-plugin = import ./vim-plugin.nix {inherit lib nixvimOptions nixvimUtils;};
inherit nixvimTypes;
inherit toLuaObject;
}
// nixvimUtils
// nixvimOptions
// nixvimBuilders
{
maintainers = import ./maintainers.nix;
keymaps = import ./keymap-helpers.nix { inherit lib nixvimOptions nixvimTypes; };
autocmd = import ./autocmd-helpers.nix { inherit lib nixvimOptions nixvimTypes; };
neovim-plugin = import ./neovim-plugin.nix {
inherit
lib
nixvimOptions
nixvimUtils
toLuaObject
;
};
vim-plugin = import ./vim-plugin.nix { inherit lib nixvimOptions nixvimUtils; };
inherit nixvimTypes;
inherit toLuaObject;
}
// nixvimUtils
// nixvimOptions
// nixvimBuilders

View file

@ -3,40 +3,25 @@
nixvimOptions,
nixvimTypes,
}:
with lib; rec {
with lib;
rec {
# These are the configuration options that change the behavior of each mapping.
mapConfigOptions = {
silent =
nixvimOptions.defaultNullOpts.mkBool false
"Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
silent = nixvimOptions.defaultNullOpts.mkBool false "Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
nowait =
nixvimOptions.defaultNullOpts.mkBool false
"Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
nowait = nixvimOptions.defaultNullOpts.mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
script =
nixvimOptions.defaultNullOpts.mkBool false
"Equivalent to adding <script> to a map.";
script = nixvimOptions.defaultNullOpts.mkBool false "Equivalent to adding <script> to a map.";
expr =
nixvimOptions.defaultNullOpts.mkBool false
"Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
expr = nixvimOptions.defaultNullOpts.mkBool false "Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
unique =
nixvimOptions.defaultNullOpts.mkBool false
"Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
unique = nixvimOptions.defaultNullOpts.mkBool false "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
noremap =
nixvimOptions.defaultNullOpts.mkBool true
"Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
noremap = nixvimOptions.defaultNullOpts.mkBool true "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
remap =
nixvimOptions.defaultNullOpts.mkBool false
"Make the mapping recursive. Inverses \"noremap\"";
remap = nixvimOptions.defaultNullOpts.mkBool false "Make the mapping recursive. Inverses \"noremap\"";
desc =
nixvimOptions.mkNullOrOption types.str
"A textual description of this keybind, to be shown in which-key, if you have it.";
desc = nixvimOptions.mkNullOrOption types.str "A textual description of this keybind, to be shown in which-key, if you have it.";
};
modes = {
@ -70,80 +55,75 @@ with lib; rec {
modeEnum =
types.enum
# ["" "n" "v" ...]
(
map
(
{short, ...}: short
)
(attrValues modes)
);
# ["" "n" "v" ...]
(map ({ short, ... }: short) (attrValues modes));
mapOptionSubmodule = mkMapOptionSubmodule {};
mapOptionSubmodule = mkMapOptionSubmodule { };
mkModeOption = default:
mkModeOption =
default:
mkOption {
type = with types;
either
modeEnum
(listOf modeEnum);
type = with types; either modeEnum (listOf modeEnum);
description = ''
One or several modes.
Use the short-names (`"n"`, `"v"`, ...).
See `:h map-modes` to learn more.
'';
inherit default;
example = ["n" "v"];
example = [
"n"
"v"
];
};
mkMapOptionSubmodule = defaults: (with types;
submodule {
options = {
key = mkOption ({
type = str;
description = "The key to map.";
example = "<C-m>";
}
// (
optionalAttrs
(defaults ? key)
{default = defaults.key;}
));
mkMapOptionSubmodule =
defaults:
(
with types;
submodule {
options = {
key = mkOption (
{
type = str;
description = "The key to map.";
example = "<C-m>";
}
// (optionalAttrs (defaults ? key) { default = defaults.key; })
);
mode = mkModeOption defaults.mode or "";
mode = mkModeOption defaults.mode or "";
action = mkOption ({
type = nixvimTypes.maybeRaw str;
description = "The action to execute.";
}
// (
optionalAttrs
(defaults ? action)
{default = defaults.action;}
));
action = mkOption (
{
type = nixvimTypes.maybeRaw str;
description = "The action to execute.";
}
// (optionalAttrs (defaults ? action) { default = defaults.action; })
);
lua = mkOption {
type = bool;
description = ''
If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`.
'';
default = defaults.lua or false;
lua = mkOption {
type = bool;
description = ''
If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`.
'';
default = defaults.lua or false;
};
options = mapConfigOptions;
};
options = mapConfigOptions;
};
});
}
);
# Correctly merge two attrs (partially) representing a mapping.
mergeKeymap = defaults: keymap: let
# First, merge the `options` attrs of both options.
mergedOpts = (defaults.options or {}) // (keymap.options or {});
in
mergeKeymap =
defaults: keymap:
let
# First, merge the `options` attrs of both options.
mergedOpts = (defaults.options or { }) // (keymap.options or { });
in
# Then, merge the root attrs together and add the previously merged `options` attrs.
(defaults // keymap) // {options = mergedOpts;};
(defaults // keymap) // { options = mergedOpts; };
mkKeymaps = defaults:
map
(mergeKeymap defaults);
mkKeymaps = defaults: map (mergeKeymap defaults);
}

View file

@ -18,9 +18,7 @@
github = "MattSturgeon";
githubId = 5046562;
name = "Matt Sturgeon";
keys = [
{fingerprint = "7082 22EA 1808 E39A 83AC 8B18 4F91 844C ED1A 8299";}
];
keys = [ { fingerprint = "7082 22EA 1808 E39A 83AC 8B18 4F91 844C ED1A 8299"; } ];
};
DanielLaing = {
email = "daniel@daniellaing.com";
@ -28,9 +26,7 @@
github = "Bodleum";
githubId = 60107449;
name = "Daniel Laing";
keys = [
{fingerprint = "0821 8B96 DC73 85E5 BB7C A535 D264 3BD2 13BC 0FA8";}
];
keys = [ { fingerprint = "0821 8B96 DC73 85E5 BB7C A535 D264 3BD2 13BC 0FA8"; } ];
};
JanKremer = {
email = "mail@jankremer.eu";
@ -38,9 +34,7 @@
github = "janurskremer";
githubId = 79042825;
name = "Jan Kremer";
keys = [
{fingerprint = "20AF 0A65 9F2B 93AD 9184 15D1 A7DA 689C B3B0 78EC";}
];
keys = [ { fingerprint = "20AF 0A65 9F2B 93AD 9184 15D1 A7DA 689C B3B0 78EC"; } ];
};
Kareem-Medhat = {
email = "kareemmedhatnabil@gmail.com";

View file

@ -4,24 +4,25 @@
toLuaObject,
nixvimUtils,
}:
with lib; rec {
mkSettingsOption = {
pluginName ? null,
options ? {},
description ?
if pluginName != null
then "Options provided to the `require('${pluginName}').setup` function."
else throw "mkSettingsOption: Please provide either a `pluginName` or `description`.",
example ? null,
}:
nixvimOptions.mkSettingsOption {
inherit options description example;
};
with lib;
rec {
mkSettingsOption =
{
pluginName ? null,
options ? { },
description ?
if pluginName != null then
"Options provided to the `require('${pluginName}').setup` function."
else
throw "mkSettingsOption: Please provide either a `pluginName` or `description`.",
example ? null,
}:
nixvimOptions.mkSettingsOption { inherit options description example; };
# TODO: DEPRECATED: use the `settings` option instead
extraOptionsOptions = {
extraOptions = mkOption {
default = {};
default = { };
type = with types; attrsOf anything;
description = ''
These attributes will be added to the table parameter for the setup function.
@ -30,82 +31,68 @@ with lib; rec {
};
};
mkNeovimPlugin = config: {
name,
maintainers,
url ? defaultPackage.meta.homepage,
imports ? [],
description ? null,
# deprecations
deprecateExtraOptions ? false,
optionsRenamedToSettings ? [],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
defaultPackage,
settingsOptions ? {},
settingsExample ? null,
extraOptions ? {},
# config
luaName ? name,
extraConfig ? cfg: {},
extraPlugins ? [],
extraPackages ? [],
callSetup ? true,
}: let
namespace =
if isColorscheme
then "colorschemes"
else "plugins";
in {
meta = {
inherit maintainers;
nixvimInfo = {
inherit
description
name
url
;
kind = namespace;
};
};
imports = let
basePluginPath = [namespace name];
settingsPath = basePluginPath ++ ["settings"];
mkNeovimPlugin =
config:
{
name,
maintainers,
url ? defaultPackage.meta.homepage,
imports ? [ ],
description ? null,
# deprecations
deprecateExtraOptions ? false,
optionsRenamedToSettings ? [ ],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
defaultPackage,
settingsOptions ? { },
settingsExample ? null,
extraOptions ? { },
# config
luaName ? name,
extraConfig ? cfg: { },
extraPlugins ? [ ],
extraPackages ? [ ],
callSetup ? true,
}:
let
namespace = if isColorscheme then "colorschemes" else "plugins";
in
imports
++ (
optional
deprecateExtraOptions
(
mkRenamedOptionModule
(basePluginPath ++ ["extraOptions"])
settingsPath
)
)
++ (
map
(
option: let
optionPath =
if isString option
then [option]
else option; # option is already a path (i.e. a list)
{
meta = {
inherit maintainers;
nixvimInfo = {
inherit description name url;
kind = namespace;
};
};
imports =
let
basePluginPath = [
namespace
name
];
settingsPath = basePluginPath ++ [ "settings" ];
in
imports
++ (optional deprecateExtraOptions (
mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath
))
++ (map (
option:
let
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath;
in
mkRenamedOptionModule
(basePluginPath ++ optionPath)
(settingsPath ++ optionPathSnakeCase)
)
optionsRenamedToSettings
);
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings);
options.${namespace}.${name} =
{
options.${namespace}.${name} = {
enable = mkEnableOption originalName;
package = nixvimOptions.mkPackageOption originalName defaultPackage;
@ -115,31 +102,24 @@ with lib; rec {
options = settingsOptions;
example = settingsExample;
};
}
// extraOptions;
} // extraOptions;
config = let
cfg = config.${namespace}.${name};
extraConfigNamespace =
if isColorscheme
then "extraConfigLuaPre"
else "extraConfigLua";
in
mkIf cfg.enable (
mkMerge [
config =
let
cfg = config.${namespace}.${name};
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua";
in
mkIf cfg.enable (mkMerge [
{
extraPlugins = [cfg.package] ++ extraPlugins;
extraPlugins = [ cfg.package ] ++ extraPlugins;
inherit extraPackages;
${extraConfigNamespace} = optionalString callSetup ''
require('${luaName}').setup(${toLuaObject cfg.settings})
'';
}
(optionalAttrs (isColorscheme && (colorscheme != null)) {
inherit colorscheme;
})
(optionalAttrs (isColorscheme && (colorscheme != null)) { inherit colorscheme; })
(extraConfig cfg)
]
);
};
]);
};
}

View file

@ -4,21 +4,23 @@
nixvimUtils,
}:
with lib;
with nixvimUtils; rec {
with nixvimUtils;
rec {
# Creates an option with a nullable type that defaults to null.
mkNullOrOption = type: desc:
mkNullOrOption =
type: desc:
lib.mkOption {
type = lib.types.nullOr type;
default = null;
description = desc;
};
mkCompositeOption = desc: options:
mkNullOrOption (types.submodule {inherit options;}) desc;
mkCompositeOption = desc: options: mkNullOrOption (types.submodule { inherit options; }) desc;
mkNullOrStr = mkNullOrOption (with nixvimTypes; maybeRaw str);
mkNullOrLua = desc:
mkNullOrLua =
desc:
lib.mkOption {
type = lib.types.nullOr nixvimTypes.strLua;
default = null;
@ -26,7 +28,8 @@ with nixvimUtils; rec {
apply = mkRaw;
};
mkNullOrLuaFn = desc:
mkNullOrLuaFn =
desc:
lib.mkOption {
type = lib.types.nullOr nixvimTypes.strLuaFn;
default = null;
@ -34,37 +37,35 @@ with nixvimUtils; rec {
apply = mkRaw;
};
mkNullOrStrLuaOr = ty: desc:
mkNullOrStrLuaOr =
ty: desc:
lib.mkOption {
type = lib.types.nullOr (types.either nixvimTypes.strLua ty);
default = null;
description = desc;
apply = v:
if builtins.isString v
then mkRaw v
else v;
apply = v: if builtins.isString v then mkRaw v else v;
};
mkNullOrStrLuaFnOr = ty: desc:
mkNullOrStrLuaFnOr =
ty: desc:
lib.mkOption {
type = lib.types.nullOr (types.either nixvimTypes.strLuaFn ty);
default = null;
description = desc;
apply = v:
if builtins.isString v
then mkRaw v
else v;
apply = v: if builtins.isString v then mkRaw v else v;
};
defaultNullOpts = rec {
mkNullable = type: default: desc:
mkNullable =
type: default: desc:
mkNullOrOption type (
let
defaultDesc = "default: `${default}`";
in
if desc == ""
then defaultDesc
else ''
if desc == "" then
defaultDesc
else
''
${desc}
${defaultDesc}
@ -73,33 +74,41 @@ with nixvimUtils; rec {
mkNullableWithRaw = type: mkNullable (maybeRaw type);
mkStrLuaOr = type: default: desc:
mkNullOrStrLuaOr type (let
defaultDesc = "default: `${default}`";
in
if desc == ""
then defaultDesc
else ''
${desc}
mkStrLuaOr =
type: default: desc:
mkNullOrStrLuaOr type (
let
defaultDesc = "default: `${default}`";
in
if desc == "" then
defaultDesc
else
''
${desc}
${defaultDesc}
'');
${defaultDesc}
''
);
mkStrLuaFnOr = type: default: desc:
mkNullOrStrLuaFnOr type (let
defaultDesc = "default: `${default}`";
in
if desc == ""
then defaultDesc
else ''
${desc}
mkStrLuaFnOr =
type: default: desc:
mkNullOrStrLuaFnOr type (
let
defaultDesc = "default: `${default}`";
in
if desc == "" then
defaultDesc
else
''
${desc}
${defaultDesc}
'');
${defaultDesc}
''
);
mkLua = default: desc:
mkNullOrLua
(
mkLua =
default: desc:
mkNullOrLua (
(optionalString (desc != "") ''
${desc}
@ -109,18 +118,20 @@ with nixvimUtils; rec {
''
);
mkLuaFn = default: desc: let
defaultDesc = "default: `${default}`";
in
mkNullOrLuaFn
(
if desc == ""
then defaultDesc
else ''
${desc}
mkLuaFn =
default: desc:
let
defaultDesc = "default: `${default}`";
in
mkNullOrLuaFn (
if desc == "" then
defaultDesc
else
''
${desc}
${defaultDesc}
''
${defaultDesc}
''
);
mkNum = default: mkNullable (with nixvimTypes; maybeRaw number) (toString default);
@ -129,137 +140,124 @@ with nixvimUtils; rec {
mkPositiveInt = default: mkNullable (with nixvimTypes; maybeRaw ints.positive) (toString default);
# Unsigned: >=0
mkUnsignedInt = default: mkNullable (with nixvimTypes; maybeRaw ints.unsigned) (toString default);
mkBool = default:
mkNullable (with nixvimTypes; maybeRaw bool) (
if default
then "true"
else "false"
);
mkBool =
default: mkNullable (with nixvimTypes; maybeRaw bool) (if default then "true" else "false");
mkStr = default: mkNullable (with nixvimTypes; maybeRaw str) ''${builtins.toString default}'';
mkAttributeSet = default: mkNullable nixvimTypes.attrs ''${default}'';
mkListOf = ty: default: mkNullable (with nixvimTypes; listOf (maybeRaw ty)) default;
mkAttrsOf = ty: default: mkNullable (with nixvimTypes; attrsOf (maybeRaw ty)) default;
mkEnum = enumValues: default: mkNullable (with nixvimTypes; maybeRaw (enum enumValues)) ''"${default}"'';
mkEnum =
enumValues: default: mkNullable (with nixvimTypes; maybeRaw (enum enumValues)) ''"${default}"'';
mkEnumFirstDefault = enumValues: mkEnum enumValues (head enumValues);
mkBorder = default: name: desc:
mkNullable
(with nixvimTypes; maybeRaw border)
default
(let
defaultDesc = ''
Defines the border to use for ${name}.
Accepts same border values as `nvim_open_win()`. See `:help nvim_open_win()` for more info.
'';
in
if desc == ""
then defaultDesc
else ''
${desc}
${defaultDesc}
'');
mkSeverity = default: desc:
mkOption {
type = with types;
nullOr
(
either ints.unsigned
(
enum
["error" "warn" "info" "hint"]
)
);
default = null;
apply =
mapNullable
(
value:
if isInt value
then value
else mkRaw "vim.diagnostic.severity.${strings.toUpper value}"
);
description = let
defaultDesc = "default: `${toString default}`";
in
if desc == ""
then defaultDesc
else ''
${desc}
${defaultDesc}
mkBorder =
default: name: desc:
mkNullable (with nixvimTypes; maybeRaw border) default (
let
defaultDesc = ''
Defines the border to use for ${name}.
Accepts same border values as `nvim_open_win()`. See `:help nvim_open_win()` for more info.
'';
};
mkLogLevel = default: desc:
mkOption {
type = with types;
nullOr
(
either
ints.unsigned
nixvimTypes.logLevel
);
default = null;
apply =
mapNullable
(
value:
if isInt value
then value
else mkRaw "vim.log.levels.${strings.toUpper value}"
);
description = let
defaultDesc = "default: `${toString default}`";
in
if desc == ""
then defaultDesc
else ''
if desc == "" then
defaultDesc
else
''
${desc}
${defaultDesc}
'';
};
mkHighlight = default: name: desc:
mkNullable
nixvimTypes.highlight
default
(
if desc == ""
then "Highlight settings."
else desc
''
);
mkSeverity =
default: desc:
mkOption {
type =
with types;
nullOr (
either ints.unsigned (enum [
"error"
"warn"
"info"
"hint"
])
);
default = null;
apply = mapNullable (
value: if isInt value then value else mkRaw "vim.diagnostic.severity.${strings.toUpper value}"
);
description =
let
defaultDesc = "default: `${toString default}`";
in
if desc == "" then
defaultDesc
else
''
${desc}
${defaultDesc}
'';
};
mkLogLevel =
default: desc:
mkOption {
type = with types; nullOr (either ints.unsigned nixvimTypes.logLevel);
default = null;
apply = mapNullable (
value: if isInt value then value else mkRaw "vim.log.levels.${strings.toUpper value}"
);
description =
let
defaultDesc = "default: `${toString default}`";
in
if desc == "" then
defaultDesc
else
''
${desc}
${defaultDesc}
'';
};
mkHighlight =
default: name: desc:
mkNullable nixvimTypes.highlight default (if desc == "" then "Highlight settings." else desc);
};
mkPackageOption = name: default:
mkPackageOption =
name: default:
mkOption {
type = types.package;
inherit default;
description = "Plugin to use for ${name}";
};
mkSettingsOption = {
options ? {},
description,
example ? null,
}:
mkSettingsOption =
{
options ? { },
description,
example ? null,
}:
mkOption {
type = with types;
type =
with types;
submodule {
freeformType = attrsOf anything;
inherit options;
};
default = {};
default = { };
inherit description;
example =
if example == null
then {
foo_bar = 42;
hostname = "localhost:8080";
callback.__raw = ''
function()
print('nixvim')
end
'';
}
else example;
if example == null then
{
foo_bar = 42;
hostname = "localhost:8080";
callback.__raw = ''
function()
print('nixvim')
end
'';
}
else
example;
};
}

View file

@ -1,46 +1,44 @@
{lib}:
with lib; rec {
{ lib }:
with lib;
rec {
# Black functional magic that converts a bunch of different Nix types to their
# lua equivalents!
toLuaObject = args:
if builtins.isAttrs args
then
if hasAttr "__raw" args
then args.__raw
else if hasAttr "__empty" args
then "{ }"
toLuaObject =
args:
if builtins.isAttrs args then
if hasAttr "__raw" args then
args.__raw
else if hasAttr "__empty" args then
"{ }"
else
"{"
+ (concatStringsSep ","
(mapAttrsToList
(n: v:
if (builtins.match "__unkeyed.*" n) != null
then toLuaObject v
else if n == "__emptyString"
then "[''] = " + (toLuaObject v)
else "[${toLuaObject n}] = " + (toLuaObject v))
(filterAttrs
(
n: v:
v != null && (toLuaObject v != "{}")
)
args)))
+ (concatStringsSep "," (
mapAttrsToList (
n: v:
if (builtins.match "__unkeyed.*" n) != null then
toLuaObject v
else if n == "__emptyString" then
"[''] = " + (toLuaObject v)
else
"[${toLuaObject n}] = " + (toLuaObject v)
) (filterAttrs (n: v: v != null && (toLuaObject v != "{}")) args)
))
+ "}"
else if builtins.isList args
then "{" + concatMapStringsSep "," toLuaObject args + "}"
else if builtins.isString args
then
else if builtins.isList args then
"{" + concatMapStringsSep "," toLuaObject args + "}"
else if builtins.isString args then
# This should be enough!
builtins.toJSON args
else if builtins.isPath args
then builtins.toJSON (toString args)
else if builtins.isBool args
then "${boolToString args}"
else if builtins.isFloat args
then "${toString args}"
else if builtins.isInt args
then "${toString args}"
else if (args == null)
then "nil"
else "";
else if builtins.isPath args then
builtins.toJSON (toString args)
else if builtins.isBool args then
"${boolToString args}"
else if builtins.isFloat args then
"${toString args}"
else if builtins.isInt args then
"${toString args}"
else if (args == null) then
"nil"
else
"";
}

View file

@ -1,12 +1,10 @@
{
lib,
nixvimOptions,
...
}:
{ lib, nixvimOptions, ... }:
with lib;
with nixvimOptions;
with lib.types; let
strLikeType = description:
with lib.types;
let
strLikeType =
description:
mkOptionType {
name = "str";
inherit description;
@ -15,68 +13,73 @@ with lib.types; let
merge = lib.options.mergeEqualOption;
};
in
rec {
isRawType = v: lib.isAttrs v && lib.hasAttr "__raw" v && lib.isString v.__raw;
rec {
isRawType = v: lib.isAttrs v && lib.hasAttr "__raw" v && lib.isString v.__raw;
rawLua = mkOptionType {
name = "rawLua";
description = "raw lua code";
descriptionClass = "noun";
merge = mergeEqualOption;
check = isRawType;
rawLua = mkOptionType {
name = "rawLua";
description = "raw lua code";
descriptionClass = "noun";
merge = mergeEqualOption;
check = isRawType;
};
maybeRaw = type: types.either type rawLua;
border =
with types;
oneOf [
str
(listOf str)
(listOf (listOf str))
];
logLevel = types.enum [
"off"
"error"
"warn"
"info"
"debug"
"trace"
];
highlight = types.submodule {
# Adds flexibility for other keys
freeformType = types.attrs;
# :help nvim_set_hl()
options = with types; {
fg = mkNullOrStr "Color for the foreground (color name or '#RRGGBB').";
bg = mkNullOrStr "Color for the background (color name or '#RRGGBB').";
sp = mkNullOrStr "Special color (color name or '#RRGGBB').";
blend = mkNullOrOption (numbers.between 0 100) "Integer between 0 and 100.";
bold = mkNullOrOption bool "";
standout = mkNullOrOption bool "";
underline = mkNullOrOption bool "";
undercurl = mkNullOrOption bool "";
underdouble = mkNullOrOption bool "";
underdotted = mkNullOrOption bool "";
underdashed = mkNullOrOption bool "";
strikethrough = mkNullOrOption bool "";
italic = mkNullOrOption bool "";
reverse = mkNullOrOption bool "";
nocombine = mkNullOrOption bool "";
link = mkNullOrStr "Name of another highlight group to link to.";
default = mkNullOrOption bool "Don't override existing definition.";
ctermfg = mkNullOrStr "Sets foreground of cterm color.";
ctermbg = mkNullOrStr "Sets background of cterm color.";
cterm = mkNullOrOption (either str attrs) ''
cterm attribute map, like |highlight-args|.
If not set, cterm attributes will match those from the attribute map documented above.
'';
};
};
maybeRaw = type:
types.either
type
rawLua;
strLua = strLikeType "lua code string";
strLuaFn = strLikeType "lua function string";
border = with types;
oneOf [
str
(listOf str)
(listOf (listOf str))
];
logLevel = types.enum ["off" "error" "warn" "info" "debug" "trace"];
highlight = types.submodule {
# Adds flexibility for other keys
freeformType = types.attrs;
# :help nvim_set_hl()
options = with types; {
fg = mkNullOrStr "Color for the foreground (color name or '#RRGGBB').";
bg = mkNullOrStr "Color for the background (color name or '#RRGGBB').";
sp = mkNullOrStr "Special color (color name or '#RRGGBB').";
blend = mkNullOrOption (numbers.between 0 100) "Integer between 0 and 100.";
bold = mkNullOrOption bool "";
standout = mkNullOrOption bool "";
underline = mkNullOrOption bool "";
undercurl = mkNullOrOption bool "";
underdouble = mkNullOrOption bool "";
underdotted = mkNullOrOption bool "";
underdashed = mkNullOrOption bool "";
strikethrough = mkNullOrOption bool "";
italic = mkNullOrOption bool "";
reverse = mkNullOrOption bool "";
nocombine = mkNullOrOption bool "";
link = mkNullOrStr "Name of another highlight group to link to.";
default = mkNullOrOption bool "Don't override existing definition.";
ctermfg = mkNullOrStr "Sets foreground of cterm color.";
ctermbg = mkNullOrStr "Sets background of cterm color.";
cterm = mkNullOrOption (either str attrs) ''
cterm attribute map, like |highlight-args|.
If not set, cterm attributes will match those from the attribute map documented above.
'';
};
};
strLua = strLikeType "lua code string";
strLuaFn = strLikeType "lua function string";
# Overridden when building the documentation
eitherRecursive = either;
}
# Allow to do `with nixvimTypes;` instead of `with types;`
// lib.types
# Overridden when building the documentation
eitherRecursive = either;
}
# Allow to do `with nixvimTypes;` instead of `with types;`
// lib.types

View file

@ -1,45 +1,38 @@
{ lib, _nixvimTests }:
with lib;
{
lib,
_nixvimTests,
}:
with lib; {
listToUnkeyedAttrs = list:
builtins.listToAttrs
(lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list);
listToUnkeyedAttrs =
list:
builtins.listToAttrs (lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list);
enableExceptInTests = !_nixvimTests;
emptyTable = {"__empty" = null;};
emptyTable = {
"__empty" = null;
};
/*
Convert a string from camelCase to snake_case
Type: string -> string
Convert a string from camelCase to snake_case
Type: string -> string
*/
toSnakeCase = let
splitByWords = builtins.split "([A-Z])";
processWord = s:
if isString s
then s
else "_" + toLower (elemAt s 0);
in
string: let
toSnakeCase =
let
splitByWords = builtins.split "([A-Z])";
processWord = s: if isString s then s else "_" + toLower (elemAt s 0);
in
string:
let
words = splitByWords string;
in
concatStrings (map processWord words);
concatStrings (map processWord words);
mkIfNonNull' = x: y: (mkIf (x != null) y);
mkIfNonNull = x: (mkIfNonNull' x x);
ifNonNull' = x: y:
if (x == null)
then null
else y;
ifNonNull' = x: y: if (x == null) then null else y;
mkRaw = r:
if (isString r && (r != ""))
then {__raw = r;}
else null;
mkRaw = r: if (isString r && (r != "")) then { __raw = r; } else null;
wrapDo = string: ''
do

View file

@ -3,56 +3,51 @@
nixvimOptions,
nixvimUtils,
}:
with lib; {
mkVimPlugin = config: {
name,
url ?
if defaultPackage != null
then defaultPackage.meta.homepage
else null,
maintainers,
imports ? [],
description ? null,
# deprecations
deprecateExtraConfig ? false,
optionsRenamedToSettings ? [],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
defaultPackage ? null,
settingsOptions ? {},
settingsExample ? null,
globalPrefix ? "",
extraOptions ? {},
# config
extraConfig ? cfg: {},
extraPlugins ? [],
extraPackages ? [],
}: let
namespace =
if isColorscheme
then "colorschemes"
else "plugins";
with lib;
{
mkVimPlugin =
config:
{
name,
url ? if defaultPackage != null then defaultPackage.meta.homepage else null,
maintainers,
imports ? [ ],
description ? null,
# deprecations
deprecateExtraConfig ? false,
optionsRenamedToSettings ? [ ],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
defaultPackage ? null,
settingsOptions ? { },
settingsExample ? null,
globalPrefix ? "",
extraOptions ? { },
# config
extraConfig ? cfg: { },
extraPlugins ? [ ],
extraPackages ? [ ],
}:
let
namespace = if isColorscheme then "colorschemes" else "plugins";
cfg = config.${namespace}.${name};
cfg = config.${namespace}.${name};
globals = cfg.settings or {};
globals = cfg.settings or { };
# does this evaluate package?
packageOption =
if defaultPackage == null
then {}
else {
package = nixvimOptions.mkPackageOption name defaultPackage;
};
# does this evaluate package?
packageOption =
if defaultPackage == null then
{ }
else
{ package = nixvimOptions.mkPackageOption name defaultPackage; };
createSettingsOption = (isString globalPrefix) && (globalPrefix != "");
createSettingsOption = (isString globalPrefix) && (globalPrefix != "");
settingsOption =
optionalAttrs createSettingsOption
{
settingsOption = optionalAttrs createSettingsOption {
settings = nixvimOptions.mkSettingsOption {
options = settingsOptions;
example = settingsExample;
@ -68,73 +63,50 @@ with lib; {
'';
};
};
in {
meta = {
inherit maintainers;
nixvimInfo = {
inherit
description
name
url
;
kind = namespace;
};
};
options.${namespace}.${name} =
{
enable = mkEnableOption originalName;
}
// settingsOption
// packageOption
// extraOptions;
imports = let
basePluginPath = [namespace name];
settingsPath = basePluginPath ++ ["settings"];
in
imports
++ (
optional
(deprecateExtraConfig && createSettingsOption)
(
mkRenamedOptionModule
(basePluginPath ++ ["extraConfig"])
settingsPath
)
)
++ (
map
(
option: let
optionPath =
if isString option
then [option]
else option; # option is already a path (i.e. a list)
{
meta = {
inherit maintainers;
nixvimInfo = {
inherit description name url;
kind = namespace;
};
};
options.${namespace}.${name} = {
enable = mkEnableOption originalName;
} // settingsOption // packageOption // extraOptions;
imports =
let
basePluginPath = [
namespace
name
];
settingsPath = basePluginPath ++ [ "settings" ];
in
imports
++ (optional (deprecateExtraConfig && createSettingsOption) (
mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath
))
++ (map (
option:
let
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath;
in
mkRenamedOptionModule
(basePluginPath ++ optionPath)
(settingsPath ++ optionPathSnakeCase)
)
optionsRenamedToSettings
);
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings);
config =
mkIf cfg.enable
(
mkMerge [
{
inherit extraPackages;
globals = mapAttrs' (n: nameValuePair (globalPrefix + n)) globals;
# does this evaluate package? it would not be desired to evaluate package if we use another package.
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
}
(optionalAttrs (isColorscheme && (colorscheme != null)) {
inherit colorscheme;
})
(extraConfig cfg)
]
);
};
config = mkIf cfg.enable (mkMerge [
{
inherit extraPackages;
globals = mapAttrs' (n: nameValuePair (globalPrefix + n)) globals;
# does this evaluate package? it would not be desired to evaluate package if we use another package.
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
}
(optionalAttrs (isColorscheme && (colorscheme != null)) { inherit colorscheme; })
(extraConfig cfg)
]);
};
}