mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 02:11:33 +00:00
treewide: make lib calls explicit
This commit is contained in:
parent
a7531186a8
commit
974bfcc78e
56 changed files with 589 additions and 496 deletions
21
lib/dag.nix
21
lib/dag.nix
|
@ -8,13 +8,16 @@
|
|||
# - the addition of the function `entryBefore` indicating a "wanted
|
||||
# by" relationship.
|
||||
{lib}: let
|
||||
inherit (lib) all filterAttrs nvim mapAttrs toposort;
|
||||
inherit (builtins) isAttrs attrValues attrNames elem all;
|
||||
inherit (lib.attrsets) filterAttrs mapAttrs;
|
||||
inherit (lib.lists) toposort;
|
||||
inherit (lib.nvim.dag) isEntry entryBetween;
|
||||
in {
|
||||
empty = {};
|
||||
|
||||
isEntry = e: e ? data && e ? after && e ? before;
|
||||
isDag = dag:
|
||||
builtins.isAttrs dag && all nvim.dag.isEntry (builtins.attrValues dag);
|
||||
isAttrs dag && all isEntry (attrValues dag);
|
||||
|
||||
/*
|
||||
Takes an attribute set containing entries built by entryAnywhere,
|
||||
|
@ -76,8 +79,8 @@ in {
|
|||
*/
|
||||
topoSort = dag: let
|
||||
dagBefore = dag: name:
|
||||
builtins.attrNames
|
||||
(filterAttrs (_n: v: builtins.elem name v.before) dag);
|
||||
attrNames
|
||||
(filterAttrs (_n: v: elem name v.before) dag);
|
||||
normalizedDag =
|
||||
mapAttrs (n: v: {
|
||||
name = n;
|
||||
|
@ -85,8 +88,8 @@ in {
|
|||
after = v.after ++ dagBefore dag n;
|
||||
})
|
||||
dag;
|
||||
before = a: b: builtins.elem a.name b.after;
|
||||
sorted = toposort before (builtins.attrValues normalizedDag);
|
||||
before = a: b: elem a.name b.after;
|
||||
sorted = toposort before (attrValues normalizedDag);
|
||||
in
|
||||
if sorted ? result
|
||||
then {
|
||||
|
@ -100,8 +103,8 @@ in {
|
|||
entryBetween = before: after: data: {inherit data before after;};
|
||||
|
||||
# Create a DAG entry with no particular dependency information.
|
||||
entryAnywhere = nvim.dag.entryBetween [] [];
|
||||
entryAnywhere = entryBetween [] [];
|
||||
|
||||
entryAfter = nvim.dag.entryBetween [];
|
||||
entryBefore = before: nvim.dag.entryBetween before [];
|
||||
entryAfter = entryBetween [];
|
||||
entryBefore = before: entryBetween before [];
|
||||
}
|
||||
|
|
|
@ -1,32 +1,37 @@
|
|||
# From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/booleans.nix
|
||||
{lib}: {
|
||||
{lib}: let
|
||||
inherit (builtins) isString getAttr;
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.attrsets) listToAttrs;
|
||||
inherit (lib.types) bool;
|
||||
in {
|
||||
# Converts a boolean to a yes/no string. This is used in lots of
|
||||
# configuration formats.
|
||||
diagnosticsToLua = {
|
||||
lang,
|
||||
config,
|
||||
diagnostics,
|
||||
diagnosticsProviders,
|
||||
}:
|
||||
lib.listToAttrs
|
||||
listToAttrs
|
||||
(map (v: let
|
||||
type =
|
||||
if builtins.isString v
|
||||
if isString v
|
||||
then v
|
||||
else builtins.getAttr v.type;
|
||||
else getAttr v.type;
|
||||
package =
|
||||
if builtins.isString v
|
||||
then diagnostics.${type}.package
|
||||
if isString v
|
||||
then diagnosticsProviders.${type}.package
|
||||
else v.package;
|
||||
in {
|
||||
name = "${lang}-diagnostics-${type}";
|
||||
value = diagnostics.${type}.nullConfig package;
|
||||
value = diagnosticsProviders.${type}.nullConfig package;
|
||||
})
|
||||
config);
|
||||
|
||||
mkEnable = desc:
|
||||
lib.mkOption {
|
||||
mkOption {
|
||||
description = "Turn on ${desc} for enabled languages by default";
|
||||
type = lib.types.bool;
|
||||
type = bool;
|
||||
default = false;
|
||||
};
|
||||
}
|
||||
|
|
46
lib/lua.nix
46
lib/lua.nix
|
@ -1,7 +1,9 @@
|
|||
# Helpers for converting values to lua
|
||||
{lib}: let
|
||||
inherit (lib) mapAttrsToList filterAttrs concatStringsSep concatMapStringsSep stringToCharacters boolToString;
|
||||
inherit (builtins) hasAttr head throw typeOf;
|
||||
inherit (builtins) hasAttr head throw typeOf isList isAttrs isBool isInt isString isPath isFloat toJSON;
|
||||
inherit (lib.attrsets) mapAttrsToList filterAttrs;
|
||||
inherit (lib.strings) concatStringsSep concatMapStringsSep stringToCharacters;
|
||||
inherit (lib.trivial) boolToString;
|
||||
in rec {
|
||||
# Convert a null value to lua's nil
|
||||
nullString = value:
|
||||
|
@ -11,29 +13,29 @@ in rec {
|
|||
|
||||
# convert an expression to lua
|
||||
expToLua = exp:
|
||||
if builtins.isList exp
|
||||
if isList exp
|
||||
then listToLuaTable exp # if list, convert to lua table
|
||||
else if builtins.isAttrs exp
|
||||
else if isAttrs exp
|
||||
then attrsetToLuaTable exp # if attrs, convert to table
|
||||
else if builtins.isBool exp
|
||||
then lib.boolToString exp # if bool, convert to string
|
||||
else if builtins.isInt exp
|
||||
then builtins.toString exp # if int, convert to string
|
||||
else if isBool exp
|
||||
then boolToString exp # if bool, convert to string
|
||||
else if isInt exp
|
||||
then toString exp # if int, convert to string
|
||||
else if exp == null
|
||||
then "nil"
|
||||
else (builtins.toJSON exp); # otherwise jsonify the value and print as is
|
||||
else (toJSON exp); # otherwise jsonify the value and print as is
|
||||
|
||||
# convert list to a lua table
|
||||
listToLuaTable = list:
|
||||
"{ " + (builtins.concatStringsSep ", " (map expToLua list)) + " }";
|
||||
"{ " + (concatStringsSep ", " (map expToLua list)) + " }";
|
||||
|
||||
# convert attrset to a lua table
|
||||
attrsetToLuaTable = attrset:
|
||||
"{ "
|
||||
+ (
|
||||
builtins.concatStringsSep ", "
|
||||
concatStringsSep ", "
|
||||
(
|
||||
lib.mapAttrsToList (
|
||||
mapAttrsToList (
|
||||
name: value:
|
||||
name
|
||||
+ " = "
|
||||
|
@ -44,10 +46,10 @@ in rec {
|
|||
)
|
||||
+ " }";
|
||||
# Convert a list of lua expressions to a lua table. The difference to listToLuaTable is that the elements here are expected to be lua expressions already, whereas listToLuaTable converts from nix types to lua first
|
||||
luaTable = items: ''{${builtins.concatStringsSep "," items}}'';
|
||||
luaTable = items: ''{${concatStringsSep "," items}}'';
|
||||
|
||||
toLuaObject = args:
|
||||
if builtins.isAttrs args
|
||||
if isAttrs args
|
||||
then
|
||||
if hasAttr "__raw" args
|
||||
then args.__raw
|
||||
|
@ -68,19 +70,19 @@ in rec {
|
|||
)
|
||||
args)))
|
||||
+ "}"
|
||||
else if builtins.isList args
|
||||
else if isList args
|
||||
then "{" + concatMapStringsSep "," toLuaObject args + "}"
|
||||
else if builtins.isString args
|
||||
else if 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
|
||||
toJSON args
|
||||
else if isPath args
|
||||
then toJSON (toString args)
|
||||
else if isBool args
|
||||
then "${boolToString args}"
|
||||
else if builtins.isFloat args
|
||||
else if isFloat args
|
||||
then "${toString args}"
|
||||
else if builtins.isInt args
|
||||
else if isInt args
|
||||
then "${toString args}"
|
||||
else if (args == null)
|
||||
then "nil"
|
||||
|
|
|
@ -15,13 +15,13 @@ with lib; let
|
|||
in {
|
||||
diagnostics = {
|
||||
langDesc,
|
||||
diagnostics,
|
||||
defaultDiagnostics,
|
||||
diagnosticsProviders,
|
||||
defaultDiagnosticsProvider,
|
||||
}:
|
||||
mkOption {
|
||||
description = "List of ${langDesc} diagnostics to enable";
|
||||
type = with types; listOf (either (enum (attrNames diagnostics)) (submodule diagnosticSubmodule));
|
||||
default = defaultDiagnostics;
|
||||
type = with types; listOf (either (enum (attrNames diagnosticsProviders)) (submodule diagnosticSubmodule));
|
||||
default = defaultDiagnosticsProvider;
|
||||
};
|
||||
|
||||
mkGrammarOption = pkgs: grammar:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
let
|
||||
inherit (builtins) isInt isBool toJSON;
|
||||
inherit (builtins) isInt isBool toJSON toString;
|
||||
in rec {
|
||||
# yes? no.
|
||||
yesNo = value:
|
||||
|
@ -16,7 +16,7 @@ in rec {
|
|||
# convert a literal value to a vim compliant value
|
||||
valToVim = val:
|
||||
if (isInt val)
|
||||
then (builtins.toString val)
|
||||
then (toString val)
|
||||
else
|
||||
(
|
||||
if (isBool val)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue