mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-12-20 02:41:17 +00:00
treewide: make the entire generated config lua based
This commit is contained in:
parent
b42a98696c
commit
eba3fa831e
17 changed files with 168 additions and 288 deletions
|
|
@ -11,9 +11,8 @@
|
|||
inherit (lib.trivial) showWarnings;
|
||||
inherit (lib.types) str nullOr;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort mkLuarcSection mkVimrcSection;
|
||||
inherit (lib.nvim.lua) toLuaObject wrapLuaConfig;
|
||||
inherit (lib.nvim.vim) valToVim;
|
||||
inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort mkLuarcSection;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (lib.nvim.config) mkBool;
|
||||
|
||||
cfg = config.vim;
|
||||
|
|
@ -82,9 +81,9 @@
|
|||
maps);
|
||||
in {
|
||||
config = let
|
||||
filterNonNull = mappings: filterAttrs (_name: value: value != null) mappings;
|
||||
filterNonNull = attrs: filterAttrs (_: value: value != null) attrs;
|
||||
globalsScript =
|
||||
mapAttrsFlatten (name: value: "let g:${name}=${valToVim value}")
|
||||
mapAttrsFlatten (name: value: "vim.g.${name} = ${toLuaObject value}")
|
||||
(filterNonNull cfg.globals);
|
||||
|
||||
toLuaBindings = mode: maps:
|
||||
|
|
@ -123,78 +122,34 @@ in {
|
|||
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
|
||||
in
|
||||
result;
|
||||
|
||||
extraPluginConfigs = resolveDag {
|
||||
name = "extra plugins config";
|
||||
dag = mapAttrs (_: value: entryAfter value.after value.setup) cfg.extraPlugins;
|
||||
mapResult = result: concatLines (map mkLuarcSection result);
|
||||
};
|
||||
|
||||
maps = [
|
||||
nmap
|
||||
imap
|
||||
vmap
|
||||
xmap
|
||||
smap
|
||||
cmap
|
||||
omap
|
||||
tmap
|
||||
lmap
|
||||
icmap
|
||||
allmap
|
||||
];
|
||||
mappings = concatLines (map concatLines maps);
|
||||
in {
|
||||
vim = {
|
||||
configRC = {
|
||||
globalsScript = entryAnywhere (concatLines globalsScript);
|
||||
|
||||
# Call additional lua files with :luafile in Vimscript
|
||||
# section of the configuration, only after
|
||||
# the luaScript section has been evaluated
|
||||
extraLuaFiles = let
|
||||
callLuaFiles = map (file: "luafile ${file}") cfg.extraLuaFiles;
|
||||
in
|
||||
entryAfter ["globalScript"] (concatLines callLuaFiles);
|
||||
|
||||
# wrap the lua config in a lua block
|
||||
# using the wrapLuaConfic function from the lib
|
||||
luaScript = let
|
||||
mapResult = result: (wrapLuaConfig {
|
||||
luaBefore = "${cfg.luaConfigPre}";
|
||||
luaConfig = concatLines (map mkLuarcSection result);
|
||||
luaAfter = "${cfg.luaConfigPost}";
|
||||
});
|
||||
|
||||
luaConfig = resolveDag {
|
||||
name = "lua config script";
|
||||
dag = cfg.luaConfigRC;
|
||||
inherit mapResult;
|
||||
};
|
||||
in
|
||||
entryAnywhere luaConfig;
|
||||
|
||||
extraPluginConfigs = let
|
||||
mapResult = result: (wrapLuaConfig {
|
||||
luaConfig = concatLines (map mkLuarcSection result);
|
||||
});
|
||||
|
||||
extraPluginsDag = mapAttrs (_: {
|
||||
after,
|
||||
setup,
|
||||
...
|
||||
}:
|
||||
entryAfter after setup)
|
||||
cfg.extraPlugins;
|
||||
|
||||
pluginConfig = resolveDag {
|
||||
name = "extra plugins config";
|
||||
dag = extraPluginsDag;
|
||||
inherit mapResult;
|
||||
};
|
||||
in
|
||||
entryAfter ["luaScript"] pluginConfig;
|
||||
|
||||
# This is probably not the right way to set the config. I'm not sure how it should look like.
|
||||
mappings = let
|
||||
maps = [
|
||||
nmap
|
||||
imap
|
||||
vmap
|
||||
xmap
|
||||
smap
|
||||
cmap
|
||||
omap
|
||||
tmap
|
||||
lmap
|
||||
icmap
|
||||
allmap
|
||||
];
|
||||
mapConfig = wrapLuaConfig {luaConfig = concatLines (map concatLines maps);};
|
||||
in
|
||||
entryAfter ["globalsScript"] mapConfig;
|
||||
luaConfigRC = {
|
||||
globalsScript = concatLines globalsScript;
|
||||
};
|
||||
|
||||
builtConfigRC = let
|
||||
builtLuaConfigRC = let
|
||||
# Catch assertions and warnings
|
||||
# and throw for each failed assertion. If no assertions are found, show warnings.
|
||||
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
||||
|
|
@ -203,14 +158,22 @@ in {
|
|||
then throw "\nFailed assertions:\n${concatMapStringsSep "\n" (x: "- ${x}") failedAssertions}"
|
||||
else showWarnings config.warnings;
|
||||
|
||||
mapResult = result: concatMapStringsSep "\n" mkVimrcSection result;
|
||||
vimConfig = resolveDag {
|
||||
name = "vim config script";
|
||||
dag = cfg.configRC;
|
||||
inherit mapResult;
|
||||
luaConfig = resolveDag {
|
||||
name = "lua config script";
|
||||
dag = cfg.luaConfigRC;
|
||||
mapResult = result:
|
||||
concatLines [
|
||||
cfg.luaConfigPre
|
||||
|
||||
(concatMapStringsSep "\n" mkLuarcSection result)
|
||||
extraPluginConfigs
|
||||
mappings
|
||||
|
||||
cfg.luaConfigPost
|
||||
];
|
||||
};
|
||||
in
|
||||
baseSystemAssertWarn vimConfig;
|
||||
baseSystemAssertWarn luaConfig;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,36 +121,15 @@ in {
|
|||
An attribute set containing global variable values
|
||||
for storing vim variables as early as possible. If
|
||||
populated, this soption will set vim variables in the
|
||||
built configRC as the first item.
|
||||
built luaConfigRC as the first item.
|
||||
|
||||
E.g. {foo = "bar"} will set `g:foo` to "bar" where
|
||||
E.g. {foo = "bar"} will set `vim.g.foo` to "bar" where
|
||||
the type of `bar` in the resulting vimscript will be
|
||||
infered from the type of the value in the `{name = value}`
|
||||
pair.
|
||||
'';
|
||||
};
|
||||
|
||||
configRC = mkOption {
|
||||
type = oneOf [(dagOf lines) str];
|
||||
default = {};
|
||||
description = ''
|
||||
Contents of vimrc, either as a string or a DAG.
|
||||
|
||||
If this option is passed as a DAG, it will be resolved
|
||||
according to the DAG resolution rules (e.g. entryBefore
|
||||
or entryAfter) as per the **nvf** extended library.
|
||||
'';
|
||||
|
||||
example = literalMD ''
|
||||
```vim
|
||||
" Set the tab size to 4 spaces
|
||||
set tabstop=4
|
||||
set shiftwidth=4
|
||||
set expandtab
|
||||
```
|
||||
'';
|
||||
};
|
||||
|
||||
luaConfigPre = mkOption {
|
||||
type = str;
|
||||
default = ''
|
||||
|
|
@ -245,10 +224,10 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
builtConfigRC = mkOption {
|
||||
builtLuaConfigRC = mkOption {
|
||||
internal = true;
|
||||
type = lines;
|
||||
description = "The built config for neovim after resolving the DAG";
|
||||
description = "The built lua config for neovim after resolving the DAG";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue