plugins: switch to mkLuaInline

This commit is contained in:
Ching Pei Yang 2024-03-16 09:29:32 +00:00
parent 77d3cd5e0c
commit 5d8eb192d7
8 changed files with 80 additions and 79 deletions

View file

@ -12,6 +12,7 @@
inherit (lib.types) bool str listOf oneOf attrsOf nullOr attrs submodule unspecified lines; inherit (lib.types) bool str listOf oneOf attrsOf nullOr attrs submodule unspecified lines;
inherit (lib.nvim.types) dagOf pluginsOpt extraPluginType; inherit (lib.nvim.types) dagOf pluginsOpt extraPluginType;
inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort; inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.vim) valToVim; inherit (lib.nvim.vim) valToVim;
@ -86,7 +87,7 @@
else config; else config;
action = action =
if action.lua if action.lua
then {"__raw" = action.action;} then mkLuaInline action.action
else action.action; else action.action;
}; };
in in

View file

@ -2,6 +2,7 @@
inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule; inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule;
inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.options) mkEnableOption mkOption literalExpression;
inherit (lib.types) bool int str enum nullOr listOf; inherit (lib.types) bool int str enum nullOr listOf;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
imports = imports =
[ [
@ -22,7 +23,7 @@ in {
options.vim.presence.neocord = { options.vim.presence.neocord = {
enable = mkEnableOption "neocord plugin for discord rich presence"; enable = mkEnableOption "neocord plugin for discord rich presence";
setupOpts = lib.nvim.mkPluginSetupOption "neocord" { setupOpts = mkPluginSetupOption "neocord" {
logo = mkOption { logo = mkOption {
type = str; # TODO: can the default be documented better, maybe with an enum? type = str; # TODO: can the default be documented better, maybe with an enum?
default = "auto"; default = "auto";

View file

@ -6,10 +6,11 @@
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.trivial) boolToString; inherit (lib.trivial) boolToString;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.generators) mkLuaInline;
cfg = config.vim.statusline.lualine; cfg = config.vim.statusline.lualine;
breadcrumbsCfg = config.vim.ui.breadcrumbs; breadcrumbsCfg = config.vim.ui.breadcrumbs;
rawLua = code: {"__raw" = code;};
in { in {
config = mkMerge [ config = mkMerge [
# TODO: move into nvim-tree file # TODO: move into nvim-tree file
@ -23,7 +24,7 @@ in {
# TODO: rewrite in new syntax # TODO: rewrite in new syntax
winbar.lualine_c = [ winbar.lualine_c = [
"navic" "navic"
(rawLua "draw_empty = ${boolToString config.vim.ui.breadcrumbs.alwaysRender}") (mkLuaInline "draw_empty = ${boolToString config.vim.ui.breadcrumbs.alwaysRender}")
]; ];
}; };
}) })
@ -49,20 +50,20 @@ in {
}; };
sections = { sections = {
lualine_a = builtins.map rawLua (cfg.activeSection.a ++ cfg.extraActiveSection.a); lualine_a = builtins.map mkLuaInline (cfg.activeSection.a ++ cfg.extraActiveSection.a);
lualine_b = builtins.map rawLua (cfg.activeSection.b ++ cfg.extraActiveSection.b); lualine_b = builtins.map mkLuaInline (cfg.activeSection.b ++ cfg.extraActiveSection.b);
lualine_c = builtins.map rawLua (cfg.activeSection.c ++ cfg.extraActiveSection.c); lualine_c = builtins.map mkLuaInline (cfg.activeSection.c ++ cfg.extraActiveSection.c);
lualine_x = builtins.map rawLua (cfg.activeSection.x ++ cfg.extraActiveSection.x); lualine_x = builtins.map mkLuaInline (cfg.activeSection.x ++ cfg.extraActiveSection.x);
lualine_y = builtins.map rawLua (cfg.activeSection.y ++ cfg.extraActiveSection.y); lualine_y = builtins.map mkLuaInline (cfg.activeSection.y ++ cfg.extraActiveSection.y);
lualine_z = builtins.map rawLua (cfg.activeSection.z ++ cfg.extraActiveSection.z); lualine_z = builtins.map mkLuaInline (cfg.activeSection.z ++ cfg.extraActiveSection.z);
}; };
inactive_sections = { inactive_sections = {
lualine_a = builtins.map rawLua (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a); lualine_a = builtins.map mkLuaInline (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a);
lualine_b = builtins.map rawLua (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b); lualine_b = builtins.map mkLuaInline (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b);
lualine_c = builtins.map rawLua (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c); lualine_c = builtins.map mkLuaInline (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c);
lualine_x = builtins.map rawLua (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x); lualine_x = builtins.map mkLuaInline (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x);
lualine_y = builtins.map rawLua (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y); lualine_y = builtins.map mkLuaInline (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y);
lualine_z = builtins.map rawLua (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z); lualine_z = builtins.map mkLuaInline (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z);
}; };
# probably don't need this? # probably don't need this?
tabline = []; tabline = [];

View file

@ -7,7 +7,8 @@
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.types) nullOr str enum bool package either int; inherit (lib.types) nullOr str enum bool package either int;
inherit (lib) mkRenamedOptionModule; inherit (lib) mkRenamedOptionModule;
inherit (lib.nvim.types) mkPluginSetupOption rawLua; inherit (lib.nvim.types) mkPluginSetupOption luaInline;
inherit (lib.generators) mkLuaInline;
in { in {
imports = [ imports = [
(mkRenamedOptionModule ["vim" "terminal" "toggleterm" "direction"] ["vim" "terminal" "toggleterm" "setupOpts" "direction"]) (mkRenamedOptionModule ["vim" "terminal" "toggleterm" "direction"] ["vim" "terminal" "toggleterm" "setupOpts" "direction"])
@ -38,10 +39,9 @@ in {
}; };
size = mkOption { size = mkOption {
type = either rawLua int; type = either luaInline int;
description = "Number or lua function which is passed to the current terminal"; description = "Number or lua function which is passed to the current terminal";
default = { default = mkLuaInline ''
__raw = ''
function(term) function(term)
if term.direction == "horizontal" then if term.direction == "horizontal" then
return 15 return 15
@ -51,14 +51,12 @@ in {
end end
''; '';
}; };
};
winbar = { winbar = {
enabled = mkEnableOption "winbar in terminal" // {default = true;}; enabled = mkEnableOption "winbar in terminal" // {default = true;};
name_formatter = mkOption { name_formatter = mkOption {
type = rawLua; type = luaInline;
description = "Winbar formatter function."; description = "Winbar formatter function.";
default = { default = mkLuaInline ''
__raw = ''
function(term) function(term)
return term.name return term.name
end end
@ -66,7 +64,6 @@ in {
}; };
}; };
}; };
};
lazygit = { lazygit = {
enable = mkEnableOption "LazyGit integration"; enable = mkEnableOption "LazyGit integration";

View file

@ -8,9 +8,9 @@
inherit (lib.lists) optionals; inherit (lib.lists) optionals;
inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.dag) entryAfter;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.generators) mkLuaInline;
cfg = config.vim.ui.breadcrumbs; cfg = config.vim.ui.breadcrumbs;
mkRawLua = code: {__raw = code;};
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = vim.startPlugins =
@ -31,40 +31,40 @@ in {
vim.ui.breadcrumbs.navbuddy.setupOpts = { vim.ui.breadcrumbs.navbuddy.setupOpts = {
mappings = { mappings = {
${cfg.navbuddy.mappings.close} = mkRawLua "actions.close()"; ${cfg.navbuddy.mappings.close} = mkLuaInline "actions.close()";
${cfg.navbuddy.mappings.nextSibling} = mkRawLua "actions.next_sibling()"; ${cfg.navbuddy.mappings.nextSibling} = mkLuaInline "actions.next_sibling()";
${cfg.navbuddy.mappings.previousSibling} = mkRawLua "actions.previous_sibling()"; ${cfg.navbuddy.mappings.previousSibling} = mkLuaInline "actions.previous_sibling()";
${cfg.navbuddy.mappings.parent} = mkRawLua "actions.parent()"; ${cfg.navbuddy.mappings.parent} = mkLuaInline "actions.parent()";
${cfg.navbuddy.mappings.children} = mkRawLua "actions.children()"; ${cfg.navbuddy.mappings.children} = mkLuaInline "actions.children()";
${cfg.navbuddy.mappings.root} = mkRawLua "actions.root()"; ${cfg.navbuddy.mappings.root} = mkLuaInline "actions.root()";
${cfg.navbuddy.mappings.visualName} = mkRawLua "actions.visual_name()"; ${cfg.navbuddy.mappings.visualName} = mkLuaInline "actions.visual_name()";
${cfg.navbuddy.mappings.visualScope} = mkRawLua "actions.visual_scope()"; ${cfg.navbuddy.mappings.visualScope} = mkLuaInline "actions.visual_scope()";
${cfg.navbuddy.mappings.yankName} = mkRawLua "actions.yank_name()"; ${cfg.navbuddy.mappings.yankName} = mkLuaInline "actions.yank_name()";
${cfg.navbuddy.mappings.yankScope} = mkRawLua "actions.yank_scope()"; ${cfg.navbuddy.mappings.yankScope} = mkLuaInline "actions.yank_scope()";
${cfg.navbuddy.mappings.insertName} = mkRawLua "actions.insert_name()"; ${cfg.navbuddy.mappings.insertName} = mkLuaInline "actions.insert_name()";
${cfg.navbuddy.mappings.insertScope} = mkRawLua "actions.insert_scope()"; ${cfg.navbuddy.mappings.insertScope} = mkLuaInline "actions.insert_scope()";
${cfg.navbuddy.mappings.appendName} = mkRawLua "actions.append_name()"; ${cfg.navbuddy.mappings.appendName} = mkLuaInline "actions.append_name()";
${cfg.navbuddy.mappings.appendScope} = mkRawLua "actions.append_scope()"; ${cfg.navbuddy.mappings.appendScope} = mkLuaInline "actions.append_scope()";
${cfg.navbuddy.mappings.rename} = mkRawLua "actions.rename()"; ${cfg.navbuddy.mappings.rename} = mkLuaInline "actions.rename()";
${cfg.navbuddy.mappings.delete} = mkRawLua "actions.delete()"; ${cfg.navbuddy.mappings.delete} = mkLuaInline "actions.delete()";
${cfg.navbuddy.mappings.foldCreate} = mkRawLua "actions.fold_create()"; ${cfg.navbuddy.mappings.foldCreate} = mkLuaInline "actions.fold_create()";
${cfg.navbuddy.mappings.foldDelete} = mkRawLua "actions.fold_delete()"; ${cfg.navbuddy.mappings.foldDelete} = mkLuaInline "actions.fold_delete()";
${cfg.navbuddy.mappings.comment} = mkRawLua "actions.comment()"; ${cfg.navbuddy.mappings.comment} = mkLuaInline "actions.comment()";
${cfg.navbuddy.mappings.select} = mkRawLua "actions.select()"; ${cfg.navbuddy.mappings.select} = mkLuaInline "actions.select()";
${cfg.navbuddy.mappings.moveDown} = mkRawLua "actions.move_down()"; ${cfg.navbuddy.mappings.moveDown} = mkLuaInline "actions.move_down()";
${cfg.navbuddy.mappings.moveUp} = mkRawLua "actions.move_up()"; ${cfg.navbuddy.mappings.moveUp} = mkLuaInline "actions.move_up()";
${cfg.navbuddy.mappings.telescope} = mkRawLua '' ${cfg.navbuddy.mappings.telescope} = mkLuaInline ''
actions.telescope({ actions.telescope({
layout_strategy = "horizontal", layout_strategy = "horizontal",
layout_config = { layout_config = {
@ -74,7 +74,7 @@ in {
preview_width = 0.50 preview_width = 0.50
}, },
})''; })'';
${cfg.navbuddy.mappings.help} = mkRawLua "actions.help()"; ${cfg.navbuddy.mappings.help} = mkLuaInline "actions.help()";
}; };
}; };

View file

@ -13,8 +13,9 @@ in {
vim = { vim = {
startPlugins = ["smartcolumn"]; startPlugins = ["smartcolumn"];
vim.luaConfigRC.smartcolumn = entryAnywhere '' luaConfigRC.smartcolumn = entryAnywhere ''
require("smartcolumn").setup(${toLuaObject cfg.setupOpts}) require("smartcolumn").setup(${toLuaObject cfg.setupOpts})
''; '';
}; };
};
} }

View file

@ -9,6 +9,7 @@
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
# TODO: move this to its own module # TODO: move this to its own module
inherit (lib) pushDownDefault; inherit (lib) pushDownDefault;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.telescope; cfg = config.vim.telescope;
self = import ./telescope.nix {inherit pkgs lib;}; self = import ./telescope.nix {inherit pkgs lib;};
@ -66,7 +67,7 @@ in {
vim.luaConfigRC.telescope = entryAnywhere '' vim.luaConfigRC.telescope = entryAnywhere ''
local telescope = require('telescope') local telescope = require('telescope')
telescope.setup(${nvim.lua.toLuaObject cfg.setupOpts}) telescope.setup(${toLuaObject cfg.setupOpts})
${ ${
if config.vim.ui.noice.enable if config.vim.ui.noice.enable

View file

@ -9,8 +9,7 @@
inherit (lib.strings) toUpper; inherit (lib.strings) toUpper;
inherit (lib.types) int float bool str enum listOf attrsOf; inherit (lib.types) int float bool str enum listOf attrsOf;
inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.nvim.types) mkPluginSetupOption;
inherit (lib.generators) mkLuaInline;
rawLua = lua: {__raw = lua;};
in { in {
imports = [ imports = [
(mkRenamedOptionModule ["vim" "visuals" "fidget-nvim" "align" "bottom"] ["vim" "visuals" "fidget-nvim" "setupOpts" "notification" "window" "align"]) (mkRenamedOptionModule ["vim" "visuals" "fidget-nvim" "align" "bottom"] ["vim" "visuals" "fidget-nvim" "setupOpts" "notification" "window" "align"])
@ -50,7 +49,7 @@ in {
apply = clear: apply = clear:
if clear if clear
then then
rawLua '' mkLuaInline ''
function(client_id) function(client_id)
local client = vim.lsp.get_client_by_id(client_id) local client = vim.lsp.get_client_by_id(client_id)
return client and client.name or nil return client and client.name or nil
@ -66,7 +65,7 @@ in {
return msg.lsp_client.name return msg.lsp_client.name
end end
''; '';
apply = rawLua; apply = mkLuaInline;
}; };
ignore = mkOption { ignore = mkOption {
description = "Ignore LSP servers by name"; description = "Ignore LSP servers by name";
@ -177,7 +176,7 @@ in {
default = '' default = ''
require("fidget.progress.display").default_format_message require("fidget.progress.display").default_format_message
''; '';
apply = rawLua; apply = mkLuaInline;
}; };
format_annote = mkOption { format_annote = mkOption {
description = "How to format a progress annotation"; description = "How to format a progress annotation";
@ -185,7 +184,7 @@ in {
default = '' default = ''
function(msg) return msg.title end function(msg) return msg.title end
''; '';
apply = rawLua; apply = mkLuaInline;
}; };
format_group_name = mkOption { format_group_name = mkOption {
description = "How to format a progress notification group's name"; description = "How to format a progress notification group's name";
@ -193,13 +192,13 @@ in {
default = '' default = ''
function(group) return tostring(group) end function(group) return tostring(group) end
''; '';
apply = rawLua; apply = mkLuaInline;
}; };
overrides = mkOption { overrides = mkOption {
description = "Override options from the default notification config"; description = "Override options from the default notification config";
type = attrsOf str; type = attrsOf str;
default = {rust_analyzer = "{ name = 'rust-analyzer' }";}; default = {rust_analyzer = "{ name = 'rust-analyzer' }";};
apply = mapAttrs (key: lua: rawLua lua); apply = mapAttrs (key: lua: mkLuaInline lua);
}; };
}; };
@ -227,7 +226,7 @@ in {
description = "Minimum notifications level"; description = "Minimum notifications level";
type = enum ["debug" "info" "warn" "error"]; type = enum ["debug" "info" "warn" "error"];
default = "info"; default = "info";
apply = filter: rawLua "vim.log.levels.${toUpper filter}"; apply = filter: mkLuaInline "vim.log.levels.${toUpper filter}";
}; };
history_size = mkOption { history_size = mkOption {
description = "Number of removed messages to retain in history"; description = "Number of removed messages to retain in history";
@ -243,7 +242,7 @@ in {
description = "How to configure notification groups when instantiated"; description = "How to configure notification groups when instantiated";
type = attrsOf str; type = attrsOf str;
default = {default = "require('fidget.notification').default_config";}; default = {default = "require('fidget.notification').default_config";};
apply = mapAttrs (key: lua: rawLua lua); apply = mapAttrs (key: lua: mkLuaInline lua);
}; };
redirect = mkOption { redirect = mkOption {
description = "Conditionally redirect notifications to another backend"; description = "Conditionally redirect notifications to another backend";
@ -255,7 +254,7 @@ in {
end end
end end
''; '';
apply = rawLua; apply = mkLuaInline;
}; };
view = { view = {
@ -287,7 +286,7 @@ in {
return cnt == 1 and msg or string.format("(%dx) %s", cnt, msg) return cnt == 1 and msg or string.format("(%dx) %s", cnt, msg)
end end
''; '';
apply = rawLua; apply = mkLuaInline;
}; };
}; };
@ -373,7 +372,7 @@ in {
description = "Minimum logging level"; description = "Minimum logging level";
type = enum ["debug" "error" "info" "trace" "warn" "off"]; type = enum ["debug" "error" "info" "trace" "warn" "off"];
default = "warn"; default = "warn";
apply = logLevel: rawLua "vim.log.levels.${toUpper logLevel}"; apply = logLevel: mkLuaInline "vim.log.levels.${toUpper logLevel}";
}; };
max_size = mkOption { max_size = mkOption {
description = "Maximum log file size, in KB"; description = "Maximum log file size, in KB";
@ -391,7 +390,7 @@ in {
default = '' default = ''
string.format("%s/fidget.nvim.log", vim.fn.stdpath("cache")) string.format("%s/fidget.nvim.log", vim.fn.stdpath("cache"))
''; '';
apply = rawLua; apply = mkLuaInline;
}; };
}; };
}; };