Some neovim changes I forgot about
This commit is contained in:
parent
2eb3151562
commit
7c7e067c1a
|
@ -84,7 +84,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
# Select your current theme here!
|
# Select your current theme here!
|
||||||
currentTheme = themes.catppuccin-latte;
|
currentTheme = themes.catppuccin-macchiato;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# We apply the current theme here.
|
# We apply the current theme here.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{ pkgs, ... }: {
|
{ config, pkgs, ... }:
|
||||||
|
{
|
||||||
home.packages = [ pkgs.josh ]; # Just One Single History
|
home.packages = [ pkgs.josh ]; # Just One Single History
|
||||||
|
|
||||||
# TODO: use `delta` as a pager, as highlighted here
|
# TODO: use `delta` as a pager, as highlighted here
|
||||||
|
@ -28,7 +29,7 @@
|
||||||
"hie.yaml"
|
"hie.yaml"
|
||||||
];
|
];
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ Aliases
|
# {{{ Aliases
|
||||||
aliases = {
|
aliases = {
|
||||||
# Print history nicely
|
# Print history nicely
|
||||||
graph = "log --decorate --oneline --graph";
|
graph = "log --decorate --oneline --graph";
|
||||||
|
@ -65,5 +66,7 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
settings.git_protocol = "ssh";
|
settings.git_protocol = "ssh";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
satellite.persistence.at.state.apps.gh.files = [ "${config.xdg.configHome}/gh/hosts.yml" ];
|
||||||
# }}}
|
# }}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ let
|
||||||
let
|
let
|
||||||
dmap = mapping: action: desc: {
|
dmap = mapping: action: desc: {
|
||||||
inherit mapping desc;
|
inherit mapping desc;
|
||||||
action = lua "vim.diagnostic.${action}";
|
action = vim /diagnostic/${action};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -161,10 +161,14 @@ let
|
||||||
mode = "i";
|
mode = "i";
|
||||||
mapping = "<c-cr>";
|
mapping = "<c-cr>";
|
||||||
action =
|
action =
|
||||||
# lua
|
_:
|
||||||
thunk ''
|
vim /paste (args [
|
||||||
vim.paste({ "", "" }, -1)
|
[
|
||||||
'';
|
""
|
||||||
|
""
|
||||||
|
]
|
||||||
|
(-1)
|
||||||
|
]);
|
||||||
desc = "Insert newline without continuing the current comment";
|
desc = "Insert newline without continuing the current comment";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -187,7 +191,7 @@ let
|
||||||
(unmap "<C-^>")
|
(unmap "<C-^>")
|
||||||
(nmap "Q" ":wqa<cr>" "Save all files and [q]uit")
|
(nmap "Q" ":wqa<cr>" "Save all files and [q]uit")
|
||||||
(nmap "<leader>rw" ":%s/<C-r><C-w>/" "[R]eplace [w]ord in file")
|
(nmap "<leader>rw" ":%s/<C-r><C-w>/" "[R]eplace [w]ord in file")
|
||||||
(nmap "<leader>sw" (lua ''require("my.helpers.wrap").toggle'') "toggle word [w]rap")
|
(nmap "<leader>sw" (require "my.helpers.wrap" /toggle) "toggle word [w]rap")
|
||||||
(nmap "<leader>ss" (
|
(nmap "<leader>ss" (
|
||||||
# lua
|
# lua
|
||||||
thunk "vim.opt.spell = not vim.o.spell"
|
thunk "vim.opt.spell = not vim.o.spell"
|
||||||
|
@ -215,7 +219,7 @@ let
|
||||||
"tex"
|
"tex"
|
||||||
];
|
];
|
||||||
group = "EnableWrapMovement";
|
group = "EnableWrapMovement";
|
||||||
action = lua ''require("my.helpers.wrap").enable'';
|
action = require "my.helpers.wrap" /enable;
|
||||||
}
|
}
|
||||||
# }}}
|
# }}}
|
||||||
];
|
];
|
||||||
|
@ -239,8 +243,14 @@ let
|
||||||
# {{{ Lsp settings
|
# {{{ Lsp settings
|
||||||
"3:lsp-settings" = {
|
"3:lsp-settings" = {
|
||||||
# {{{ Change lsp on-hover borders
|
# {{{ Change lsp on-hover borders
|
||||||
vim.lsp.handlers."textDocument/hover" = lua ''vim.lsp.with(vim.lsp.handlers.hover, { border = "single" })'';
|
vim.lsp.handlers."textDocument/hover" = vim /lsp/with (args [
|
||||||
vim.lsp.handlers."textDocument/signatureHelp" = lua ''vim.lsp.with(vim.lsp.handlers.signature_help, { border = "single" })'';
|
(vim /lsp/handlers/hover)
|
||||||
|
{ border = "single"; }
|
||||||
|
]);
|
||||||
|
vim.lsp.handlers."textDocument/signatureHelp" = vim /lsp/with (args [
|
||||||
|
(vim /lsp/handlers/signature_help)
|
||||||
|
{ border = "single"; }
|
||||||
|
]);
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ Create on-attach keybinds
|
# {{{ Create on-attach keybinds
|
||||||
autocmds = {
|
autocmds = {
|
||||||
|
@ -250,14 +260,12 @@ let
|
||||||
let
|
let
|
||||||
nmap =
|
nmap =
|
||||||
mapping: action: desc:
|
mapping: action: desc:
|
||||||
nlib.nmap mapping (lua "vim.lsp.buf.${action}") desc;
|
nlib.nmap mapping (vim /lsp/buf/${action}) desc;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
mkContext = event: {
|
mkContext = event: {
|
||||||
bufnr = lua "${event}.buf";
|
bufnr = lua event /buf;
|
||||||
client =
|
client = vim /lsp/get_client_by_id (lua event /data/client_id);
|
||||||
# lua
|
|
||||||
lua "vim.lsp.get_client_by_id(${event}.data.client_id)";
|
|
||||||
};
|
};
|
||||||
keys = [
|
keys = [
|
||||||
(nlib.nmap "<leader>li" "<cmd>LspInfo<cr>" "[L]sp [i]nfo")
|
(nlib.nmap "<leader>li" "<cmd>LspInfo<cr>" "[L]sp [i]nfo")
|
||||||
|
@ -270,18 +278,11 @@ let
|
||||||
(nmap "<leader>wa" "add_workspace_folder" "[W]orkspace [A]dd Folder")
|
(nmap "<leader>wa" "add_workspace_folder" "[W]orkspace [A]dd Folder")
|
||||||
(nmap "<leader>wr" "remove_workspace_folder" "[W]orkspace [R]emove Folder")
|
(nmap "<leader>wr" "remove_workspace_folder" "[W]orkspace [R]emove Folder")
|
||||||
(nlib.nmap "<leader>wl" (
|
(nlib.nmap "<leader>wl" (
|
||||||
# lua
|
_: print (vim /inspect (vim /ps/buf/list_workspace_folders none))
|
||||||
thunk ''
|
|
||||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
||||||
''
|
|
||||||
) "[W]orkspace [L]ist Folders")
|
) "[W]orkspace [L]ist Folders")
|
||||||
];
|
];
|
||||||
callback = {
|
callback = {
|
||||||
cond =
|
cond = ctx: return (lua ctx /client/supports_method "textDocument/hover");
|
||||||
ctx:
|
|
||||||
lua ''
|
|
||||||
return ${ctx}.client.supports_method("textDocument/hover")
|
|
||||||
'';
|
|
||||||
keys = nmap "K" "hover" "Hover";
|
keys = nmap "K" "hover" "Hover";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -293,7 +294,7 @@ let
|
||||||
"4:configure-neovide" = {
|
"4:configure-neovide" = {
|
||||||
cond = whitelist "neovide";
|
cond = whitelist "neovide";
|
||||||
vim.g = {
|
vim.g = {
|
||||||
neovide_transparency = lua ''D.tempest.theme.transparency.applications.value'';
|
neovide_transparency = tempest /theme/transparency/applications/value;
|
||||||
neovide_cursor_animation_length = 4.0e-2;
|
neovide_cursor_animation_length = 4.0e-2;
|
||||||
neovide_cursor_animate_in_insert_mode = false;
|
neovide_cursor_animate_in_insert_mode = false;
|
||||||
};
|
};
|
||||||
|
@ -312,12 +313,11 @@ let
|
||||||
keys = {
|
keys = {
|
||||||
mapping = "<leader>lg";
|
mapping = "<leader>lg";
|
||||||
action =
|
action =
|
||||||
# lua
|
_:
|
||||||
thunk ''
|
let
|
||||||
D.tempest.withSavedCursor(function()
|
cmd = _: vim /cmd ":%!${lib.getExe pkgs.update-nix-fetchgit}";
|
||||||
vim.cmd(":%!${lib.getExe pkgs.update-nix-fetchgit}")
|
in
|
||||||
end)
|
tempest /withSavedCursor cmd;
|
||||||
'';
|
|
||||||
desc = "Update all fetchgit calls";
|
desc = "Update all fetchgit calls";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -381,12 +381,13 @@ let
|
||||||
lazy = false;
|
lazy = false;
|
||||||
|
|
||||||
opts.content.inactive =
|
opts.content.inactive =
|
||||||
# lua
|
_:
|
||||||
thunk ''
|
require "mini.statusline" /combine_groups [
|
||||||
require("mini.statusline").combine_groups({
|
{
|
||||||
{ hl = "MiniStatuslineFilename", strings = { vim.fn.expand("%:t") } },
|
hl = "MiniStatuslineFilename";
|
||||||
})
|
strings = [ (vim /fn/expand "%:t") ];
|
||||||
'';
|
}
|
||||||
|
];
|
||||||
|
|
||||||
opts.content.active =
|
opts.content.active =
|
||||||
# lua
|
# lua
|
||||||
|
@ -446,28 +447,19 @@ let
|
||||||
goto = key: index: {
|
goto = key: index: {
|
||||||
desc = "Goto harpoon file ${toString index}";
|
desc = "Goto harpoon file ${toString index}";
|
||||||
mapping = "<c-s>${key}";
|
mapping = "<c-s>${key}";
|
||||||
action =
|
action = _: require "harpoon.ui" /nav_file (toString index);
|
||||||
thunk
|
|
||||||
# lua
|
|
||||||
''require("harpoon.ui").nav_file(${toString index})'';
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
desc = "Add file to [h]arpoon";
|
desc = "Add file to [h]arpoon";
|
||||||
mapping = "<leader>H";
|
mapping = "<leader>H";
|
||||||
action =
|
action = _: require "harpoon.mark" /add_file none;
|
||||||
thunk
|
|
||||||
# lua
|
|
||||||
''require("harpoon.mark").add_file()'';
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
desc = "Toggle harpoon quickmenu";
|
desc = "Toggle harpoon quickmenu";
|
||||||
mapping = "<c-a>";
|
mapping = "<c-a>";
|
||||||
action =
|
action = _: require "harpoon.ui" /toggle_quick_menu none;
|
||||||
thunk
|
|
||||||
# lua
|
|
||||||
''require("harpoon.ui").toggle_quick_menu()'';
|
|
||||||
}
|
}
|
||||||
(goto "q" 1)
|
(goto "q" 1)
|
||||||
(goto "w" 2)
|
(goto "w" 2)
|
||||||
|
@ -541,11 +533,7 @@ let
|
||||||
};
|
};
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ Load fzf extension
|
# {{{ Load fzf extension
|
||||||
config.callback =
|
config.callback = _: require "telescope" /load_extension "fzf";
|
||||||
# lua
|
|
||||||
thunk ''
|
|
||||||
require("telescope").load_extension("fzf")
|
|
||||||
'';
|
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ Options
|
# {{{ Options
|
||||||
opts.defaults.mappings.i."<C-h>" = "which_key";
|
opts.defaults.mappings.i."<C-h>" = "which_key";
|
||||||
|
@ -681,9 +669,7 @@ let
|
||||||
let
|
let
|
||||||
nmap = mode: mapping: action: desc: {
|
nmap = mode: mapping: action: desc: {
|
||||||
inherit mapping desc mode;
|
inherit mapping desc mode;
|
||||||
action =
|
action = _: require "flash" /${action} none;
|
||||||
# lua
|
|
||||||
thunk ''require("flash").${action}()'';
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
|
@ -792,7 +778,7 @@ let
|
||||||
q = balanced "\"\"";
|
q = balanced "\"\"";
|
||||||
Q = balanced "``";
|
Q = balanced "``";
|
||||||
a = balanced "''";
|
a = balanced "''";
|
||||||
A = lua "require('mini.ai').gen_spec.argument()";
|
A = require "mini.ai" /gen_spec/argument none;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -911,19 +897,19 @@ let
|
||||||
version = "v2";
|
version = "v2";
|
||||||
|
|
||||||
cond = blacklist "vscode";
|
cond = blacklist "vscode";
|
||||||
config = thunk ''
|
config =
|
||||||
require("luasnip").config.setup(${
|
_:
|
||||||
encode {
|
do [
|
||||||
|
(require "luasnip" /config/setup {
|
||||||
enable_autosnippets = true;
|
enable_autosnippets = true;
|
||||||
update_events = [
|
update_events = [
|
||||||
"TextChanged"
|
"TextChanged"
|
||||||
"TextChangedI"
|
"TextChangedI"
|
||||||
];
|
];
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
|
||||||
require("luasnip.loaders.from_lua").lazy_load(${encode { fs_event_providers.libuv = true; }})
|
(require "luasnip.loaders.from_lua" /lazy_load { fs_event_providers.libuv = true; })
|
||||||
'';
|
];
|
||||||
|
|
||||||
# {{{ Keybinds
|
# {{{ Keybinds
|
||||||
keys = [
|
keys = [
|
||||||
|
@ -951,11 +937,7 @@ let
|
||||||
{
|
{
|
||||||
mode = "i";
|
mode = "i";
|
||||||
mapping = "<s-tab>";
|
mapping = "<s-tab>";
|
||||||
action =
|
action = _: require "luasnip" /jump (-1);
|
||||||
# lua
|
|
||||||
thunk ''
|
|
||||||
require("luasnip").jump(-1)
|
|
||||||
'';
|
|
||||||
desc = "Jump to previous snippet tabstop";
|
desc = "Jump to previous snippet tabstop";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1041,14 +1023,11 @@ let
|
||||||
config =
|
config =
|
||||||
_:
|
_:
|
||||||
importFrom ./plugins/lspconfig.lua "config" {
|
importFrom ./plugins/lspconfig.lua "config" {
|
||||||
tsserver = {
|
# We handle formatting using null-ls and prettierd
|
||||||
on_attach = lua ''
|
tsserver.on_attach = client: ''
|
||||||
function(client)
|
${client}.server_capabilities.documentFormattingProvider = false
|
||||||
-- We handle formatting using null-ls and prettierd
|
'';
|
||||||
client.server_capabilities.documentFormattingProvider = false
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
purescriptls.settings.purescript = {
|
purescriptls.settings.purescript = {
|
||||||
censorWarnings = [
|
censorWarnings = [
|
||||||
"UnusedName"
|
"UnusedName"
|
||||||
|
@ -1188,16 +1167,7 @@ let
|
||||||
cond = blacklist "vscode";
|
cond = blacklist "vscode";
|
||||||
event = "VeryLazy";
|
event = "VeryLazy";
|
||||||
|
|
||||||
opts =
|
opts = _: { sources = [ (require "null-ls" /builtins/diagnostics/ruff) ]; };
|
||||||
# lua
|
|
||||||
thunk ''
|
|
||||||
local p = require("null-ls")
|
|
||||||
return {
|
|
||||||
sources = {
|
|
||||||
p.builtins.diagnostics.ruff
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ cmp
|
# {{{ cmp
|
||||||
|
@ -1238,12 +1208,16 @@ let
|
||||||
|
|
||||||
cond = blacklist "vscode";
|
cond = blacklist "vscode";
|
||||||
config = _: {
|
config = _: {
|
||||||
setup.neotest.adapters = [
|
setup.neotest = {
|
||||||
(require "neotest-haskell" {
|
status.virtual_text = true;
|
||||||
build_tools = [ "stack" ];
|
output.open_on_run = true;
|
||||||
frameworks = [ "hspec" ];
|
adapters = [
|
||||||
})
|
(require "neotest-haskell" {
|
||||||
];
|
build_tools = [ "stack" ];
|
||||||
|
frameworks = [ "hspec" ];
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# {{{ Keybinds
|
# {{{ Keybinds
|
||||||
|
@ -1333,11 +1307,7 @@ let
|
||||||
event = "InsertEnter";
|
event = "InsertEnter";
|
||||||
group = "CargoCmpSource";
|
group = "CargoCmpSource";
|
||||||
pattern = "Cargo.toml";
|
pattern = "Cargo.toml";
|
||||||
action =
|
action = _: require "cmp" /setup/buffer { sources = [ { name = "crates"; } ]; };
|
||||||
# lua
|
|
||||||
thunk ''
|
|
||||||
require("cmp").setup.buffer({ sources = { { name = "crates" } } })
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ Load keybinds on attach
|
# {{{ Load keybinds on attach
|
||||||
|
@ -1362,9 +1332,7 @@ let
|
||||||
# {{{ Keymap helpers
|
# {{{ Keymap helpers
|
||||||
nmap = mapping: action: desc: {
|
nmap = mapping: action: desc: {
|
||||||
inherit mapping desc;
|
inherit mapping desc;
|
||||||
action =
|
action = require "crates" /${action};
|
||||||
# lua
|
|
||||||
lua ''require("crates").${action}'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
keyroot = "<leader>lc";
|
keyroot = "<leader>lc";
|
||||||
|
@ -1442,9 +1410,7 @@ let
|
||||||
keymap = mapping: action: desc: {
|
keymap = mapping: action: desc: {
|
||||||
inherit desc;
|
inherit desc;
|
||||||
mapping = "<leader>i${mapping}";
|
mapping = "<leader>i${mapping}";
|
||||||
action =
|
action = require "idris2.code_action" /${action};
|
||||||
# lua
|
|
||||||
lua ''require("idris2.code_action").${action}'';
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
|
|
|
@ -2,69 +2,89 @@
|
||||||
let
|
let
|
||||||
k = korora;
|
k = korora;
|
||||||
|
|
||||||
# {{{ Helpers
|
# {{{ Helpers
|
||||||
helpers = rec {
|
helpers = rec {
|
||||||
removeEmptyLines = str:
|
removeEmptyLines =
|
||||||
|
str:
|
||||||
lib.pipe str [
|
lib.pipe str [
|
||||||
(lib.splitString "\n")
|
(lib.splitString "\n")
|
||||||
(lib.lists.filter
|
(lib.lists.filter (line: lib.any (c: c != " ") (lib.stringToCharacters line)))
|
||||||
(line: lib.any
|
|
||||||
(c: c != " ")
|
|
||||||
(lib.stringToCharacters line)))
|
|
||||||
(lib.concatStringsSep "\n")
|
(lib.concatStringsSep "\n")
|
||||||
];
|
];
|
||||||
|
|
||||||
hasType = type: value:
|
hasType =
|
||||||
let err = type.verify value; in
|
type: value:
|
||||||
|
let
|
||||||
|
err = type.verify value;
|
||||||
|
in
|
||||||
lib.assertMsg (err == null) err;
|
lib.assertMsg (err == null) err;
|
||||||
|
|
||||||
lua = value: assert hasType k.string value;
|
lua =
|
||||||
{
|
value:
|
||||||
inherit value;
|
assert hasType k.string value;
|
||||||
|
lib.fix (self: {
|
||||||
|
inherit value;
|
||||||
__luaEncoderTag = "lua";
|
__luaEncoderTag = "lua";
|
||||||
__functor = _: arg: lua "(${value})(${encode arg})";
|
__functor =
|
||||||
};
|
_: arg:
|
||||||
|
if builtins.typeOf arg == "path" then
|
||||||
|
if arg == /. then
|
||||||
|
self
|
||||||
|
else
|
||||||
|
let
|
||||||
|
object = self (builtins.dirOf arg);
|
||||||
|
attr = builtins.toString (builtins.baseNameOf arg);
|
||||||
|
in
|
||||||
|
lua "${encode object}.${attr}"
|
||||||
|
else
|
||||||
|
lua "${value}(${encode arg})";
|
||||||
|
});
|
||||||
|
|
||||||
# {{{ Verification helpers
|
# {{{ Verification helpers
|
||||||
toPretty = lib.generators.toPretty { indent = " "; };
|
toPretty = lib.generators.toPretty { indent = " "; };
|
||||||
withError = cond: err: if cond then null else err;
|
withError = cond: err: if cond then null else err;
|
||||||
hasProp = obj: p: obj ? ${p};
|
hasProp = obj: p: obj ? ${p};
|
||||||
propExists = p: obj:
|
propExists = p: obj: helpers.withError (helpers.hasProp obj p) "Expected property ${p}";
|
||||||
helpers.withError
|
propXor =
|
||||||
(helpers.hasProp obj p)
|
a: b: obj:
|
||||||
"Expected property ${p}";
|
helpers.withError (
|
||||||
propXor = a: b: obj:
|
(hasProp obj a) != (hasProp obj b)
|
||||||
helpers.withError
|
) "Expected only one of the properties ${a} and ${b} in object ${toPretty obj}";
|
||||||
((hasProp obj a) != (hasProp obj b))
|
propOnlyOne =
|
||||||
"Expected only one of the properties ${a} and ${b} in object ${toPretty obj}";
|
props: obj:
|
||||||
propOnlyOne = props: obj:
|
helpers.withError (
|
||||||
helpers.withError
|
1 == lib.count (hasProp obj) props
|
||||||
(1 == lib.count (hasProp obj) props)
|
) "Expected exactly one property from the list ${toPretty props} in object ${toPretty obj}";
|
||||||
"Expected exactly one property from the list ${toPretty props} in object ${toPretty obj}";
|
propImplies =
|
||||||
propImplies = a: b: obj:
|
a: b: obj:
|
||||||
helpers.withError
|
helpers.withError (
|
||||||
((hasProp obj a) -> (hasProp obj b))
|
(hasProp obj a) -> (hasProp obj b)
|
||||||
"Property ${a} should imply property ${b} in object ${toPretty obj}";
|
) "Property ${a} should imply property ${b} in object ${toPretty obj}";
|
||||||
mkVerify = checks: obj:
|
mkVerify =
|
||||||
|
checks: obj:
|
||||||
assert lib.all lib.isFunction checks;
|
assert lib.all lib.isFunction checks;
|
||||||
let
|
let
|
||||||
results = lib.lists.map (c: c obj) checks;
|
results = lib.lists.map (c: c obj) checks;
|
||||||
errors = lib.lists.filter (v: v != null) results;
|
errors = lib.lists.filter (v: v != null) results;
|
||||||
in
|
in
|
||||||
assert lib.all lib.isString errors;
|
assert lib.all lib.isString errors;
|
||||||
if errors == [ ]
|
if errors == [ ] then
|
||||||
then null
|
null
|
||||||
else
|
else
|
||||||
let prettyErrors =
|
let
|
||||||
lib.lists.map (s: "\n- ${s}") errors;
|
prettyErrors = lib.lists.map (s: "\n- ${s}") errors;
|
||||||
in
|
in
|
||||||
"Multiple errors occured: ${lib.concatStrings prettyErrors}";
|
"Multiple errors occured: ${lib.concatStrings prettyErrors}";
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ Custom types
|
# {{{ Custom types
|
||||||
intersection = l: r:
|
intersection =
|
||||||
k.typedef'
|
l: r:
|
||||||
"${l.name} ∧ ${r.name}"
|
k.typedef' "${l.name} ∧ ${r.name}" (
|
||||||
(helpers.mkVerify [ l r ]);
|
helpers.mkVerify [
|
||||||
|
l
|
||||||
|
r
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
# dependentAttrsOf =
|
# dependentAttrsOf =
|
||||||
# name: mkType:
|
# name: mkType:
|
||||||
|
@ -85,36 +105,54 @@ let
|
||||||
# v));
|
# v));
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ Encoding helpers
|
# {{{ Encoding helpers
|
||||||
mkRawLuaObject = chunks:
|
mkRawLuaObject = chunks: ''
|
||||||
''
|
{
|
||||||
{
|
${lib.concatStringsSep "," (lib.filter (s: s != "") chunks)}
|
||||||
${lib.concatStringsSep "," (lib.filter (s: s != "") chunks)}
|
}
|
||||||
}
|
'';
|
||||||
'';
|
|
||||||
|
|
||||||
encodeString = given:
|
encodeString =
|
||||||
|
given:
|
||||||
if lib.hasInfix "\n" given then
|
if lib.hasInfix "\n" given then
|
||||||
''[[${(toString given)}]]'' # This is not perfect but oh well
|
''[[${(toString given)}]]'' # This is not perfect but oh well
|
||||||
else
|
else
|
||||||
''"${lib.escape ["\"" "\\"] (toString given)}"'';
|
''"${
|
||||||
|
lib.escape [
|
||||||
|
"\""
|
||||||
|
"\\"
|
||||||
|
] (toString given)
|
||||||
|
}"'';
|
||||||
|
|
||||||
mkAttrName = s:
|
mkAttrName =
|
||||||
|
s:
|
||||||
let
|
let
|
||||||
# A "good enough" approach to figuring out the correct encoding for attribute names
|
# A "good enough" approach to figuring out the correct encoding for attribute names
|
||||||
allowedStartingChars = lib.stringToCharacters "abcdefghijklmnopqrstuvwxyz_";
|
allowedStartingChars = lib.stringToCharacters "abcdefghijklmnopqrstuvwxyz_";
|
||||||
allowedChars = allowedStartingChars ++ lib.stringToCharacters "0123456789";
|
allowedChars = allowedStartingChars ++ lib.stringToCharacters "0123456789";
|
||||||
keywords = [ "if" "then" "else" "do" "for" "local" "" ];
|
keywords = [
|
||||||
|
"if"
|
||||||
|
"then"
|
||||||
|
"else"
|
||||||
|
"do"
|
||||||
|
"for"
|
||||||
|
"local"
|
||||||
|
""
|
||||||
|
];
|
||||||
in
|
in
|
||||||
if builtins.match "([a-zA-Z_][a-zA-Z_0-9]*)" s != [ s ] || lib.elem s keywords then
|
if builtins.match "([a-zA-Z_][a-zA-Z_0-9]*)" s != [ s ] || lib.elem s keywords then
|
||||||
"[${helpers.encodeString s}]"
|
"[${helpers.encodeString s}]"
|
||||||
else s;
|
else
|
||||||
|
s;
|
||||||
# }}}
|
# }}}
|
||||||
};
|
};
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ Encoding
|
# {{{ Encoding
|
||||||
isLuaLiteral = given: lib.isAttrs given && given.__luaEncoderTag or null == "lua";
|
isLuaLiteral = given: lib.isAttrs given && given.__luaEncoderTag or null == "lua";
|
||||||
encodeWithDepth = depth: given:
|
encodeWithDepth =
|
||||||
let recurse = encodeWithDepth depth; in
|
depth: given:
|
||||||
|
let
|
||||||
|
recurse = encodeWithDepth depth;
|
||||||
|
in
|
||||||
if lib.isString given || lib.isDerivation given || lib.isPath given then
|
if lib.isString given || lib.isDerivation given || lib.isPath given then
|
||||||
helpers.encodeString given
|
helpers.encodeString given
|
||||||
else if lib.isInt given || lib.isFloat given then
|
else if lib.isInt given || lib.isFloat given then
|
||||||
|
@ -140,40 +178,43 @@ let
|
||||||
else if isLuaLiteral given then
|
else if isLuaLiteral given then
|
||||||
given.value
|
given.value
|
||||||
else if lib.isAttrs given then
|
else if lib.isAttrs given then
|
||||||
helpers.mkRawLuaObject
|
helpers.mkRawLuaObject (
|
||||||
(lib.mapAttrsToList
|
lib.mapAttrsToList (
|
||||||
(name: value:
|
name: value:
|
||||||
let result = recurse value;
|
let
|
||||||
in
|
result = recurse value;
|
||||||
lib.optionalString (result != "nil")
|
in
|
||||||
"${helpers.mkAttrName name} = ${result}"
|
lib.optionalString (result != "nil") "${helpers.mkAttrName name} = ${result}"
|
||||||
)
|
) given
|
||||||
given)
|
)
|
||||||
else if lib.isFunction given then
|
else if lib.isFunction given then
|
||||||
let
|
let
|
||||||
argNames = [ "context" "inner_context" "local_context" ];
|
argNames = [
|
||||||
|
"context"
|
||||||
|
"inner_context"
|
||||||
|
"local_context"
|
||||||
|
];
|
||||||
secretArg =
|
secretArg =
|
||||||
if depth >= builtins.length argNames
|
if depth >= builtins.length argNames then "arg_${depth}" else builtins.elemAt argNames depth;
|
||||||
then "arg_${depth}"
|
|
||||||
else builtins.elemAt argNames depth;
|
|
||||||
body = given secretArg;
|
body = given secretArg;
|
||||||
encoded = encodeWithDepth (depth + 1) body;
|
encoded = encodeWithDepth (depth + 1) body;
|
||||||
encodedBody =
|
encodedBody = if isLuaLiteral body then encoded else "return ${encoded}";
|
||||||
if isLuaLiteral body
|
|
||||||
then encoded
|
|
||||||
else "return ${encoded}";
|
|
||||||
in
|
in
|
||||||
if lib.hasInfix secretArg encoded
|
if lib.hasInfix secretArg encoded then
|
||||||
then ''
|
''
|
||||||
function(${secretArg})
|
function(${secretArg})
|
||||||
${encodedBody}
|
${encodedBody}
|
||||||
end''
|
end''
|
||||||
else ''
|
else
|
||||||
function()
|
''
|
||||||
${encodedBody}
|
function()
|
||||||
end''
|
${encodedBody}
|
||||||
else builtins.throw "Cannot encode value ${helpers.toPretty given}";
|
end''
|
||||||
|
else
|
||||||
|
builtins.throw "Cannot encode value ${helpers.toPretty given}";
|
||||||
# }}}
|
# }}}
|
||||||
encode = encodeWithDepth 0;
|
encode = encodeWithDepth 0;
|
||||||
in
|
in
|
||||||
{ inherit encode helpers; }
|
{
|
||||||
|
inherit encode helpers;
|
||||||
|
}
|
||||||
|
|
|
@ -39,11 +39,12 @@ let
|
||||||
else
|
else
|
||||||
"Expected function, but got ${h.toPretty f} instead"
|
"Expected function, but got ${h.toPretty f} instead"
|
||||||
);
|
);
|
||||||
|
lazy = types.functionCheckedWith "";
|
||||||
luaEagerOrLazy =
|
luaEagerOrLazy =
|
||||||
type:
|
type:
|
||||||
k.union [
|
k.union [
|
||||||
type
|
type
|
||||||
(types.functionCheckedWith "" type)
|
(types.lazy type)
|
||||||
];
|
];
|
||||||
luaLiteral = types.luaEagerOrLazy types.strictLuaLiteral;
|
luaLiteral = types.luaEagerOrLazy types.strictLuaLiteral;
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -128,10 +129,7 @@ let
|
||||||
struct "tempest key"
|
struct "tempest key"
|
||||||
{
|
{
|
||||||
mapping = k.string;
|
mapping = k.string;
|
||||||
action = k.union [
|
action = types.luaValue;
|
||||||
types.luaLiteral
|
|
||||||
k.string
|
|
||||||
];
|
|
||||||
mode = k.string;
|
mode = k.string;
|
||||||
desc = k.string;
|
desc = k.string;
|
||||||
expr = k.bool;
|
expr = k.bool;
|
||||||
|
@ -177,7 +175,7 @@ let
|
||||||
keys = types.luaEagerOrLazy (types.oneOrMany types.tempestKey);
|
keys = types.luaEagerOrLazy (types.oneOrMany types.tempestKey);
|
||||||
autocmds = types.luaEagerOrLazy (types.oneOrMany types.tempestAutocmd);
|
autocmds = types.luaEagerOrLazy (types.oneOrMany types.tempestAutocmd);
|
||||||
mkContext = types.luaValue;
|
mkContext = types.luaValue;
|
||||||
cond = types.oneOrMany types.luaLiteral;
|
cond = types.oneOrMany types.luaValue;
|
||||||
} [ ];
|
} [ ];
|
||||||
|
|
||||||
tempestConfig = lazyType "lazy tempest config" (_: types.strictTempestConfig);
|
tempestConfig = lazyType "lazy tempest config" (_: types.strictTempestConfig);
|
||||||
|
@ -219,8 +217,18 @@ let
|
||||||
__luaEncoderTag = "foldedList";
|
__luaEncoderTag = "foldedList";
|
||||||
};
|
};
|
||||||
thunk = code: _: lua code;
|
thunk = code: _: lua code;
|
||||||
require = module: lua "require(${module})";
|
return = code: lua "return ${encode code}";
|
||||||
tempest =
|
|
||||||
|
vim = lua "vim";
|
||||||
|
print = lua "print";
|
||||||
|
require = lua "require";
|
||||||
|
tempest = lua "D.tempest";
|
||||||
|
|
||||||
|
do = actions: lua (lib.concatStringsSep "\n" (lib.forEach actions encode));
|
||||||
|
args = values: lua (lib.concatStringsSep ", " (lib.forEach values encode));
|
||||||
|
none = lua "";
|
||||||
|
|
||||||
|
tempestConfigure =
|
||||||
given: context:
|
given: context:
|
||||||
lua ''
|
lua ''
|
||||||
D.tempest.configure(
|
D.tempest.configure(
|
||||||
|
|
Loading…
Reference in a new issue