-
-
Notifications
You must be signed in to change notification settings - Fork 340
lib/vim-plugin: Add support for luaConfig
#2624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,12 @@ | |
- `other_toggle = false` -> `:setglobal no${globalPrefix}other_toggle` | ||
''; | ||
}; | ||
|
||
luaConfig = lib.mkOption { | ||
type = lib.types.pluginLuaConfig { hasContent = false; }; | ||
default = { }; | ||
description = "The plugin's lua configuration"; | ||
}; | ||
}; | ||
|
||
module = | ||
|
@@ -115,6 +121,10 @@ | |
]; | ||
globals = lib.mapAttrs' (n: lib.nameValuePair (globalPrefix + n)) (cfg.settings or { }); | ||
} | ||
(lib.optionalAttrs createSettingsOption { | ||
globalsPre = lib.nixvim.mkIfNonNull cfg.luaConfig.pre; | ||
globalsPost = lib.nixvim.mkIfNonNull cfg.luaConfig.post; | ||
}) | ||
Comment on lines
+124
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initial reaction: I'm not a fan of this. I don't think it makes sense to assign lua code to an option named "globals*". |
||
(lib.optionalAttrs (isColorscheme && (colorscheme != null)) { | ||
colorscheme = lib.mkDefault colorscheme; | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,15 +36,29 @@ let | |
}; | ||
in | ||
{ | ||
options = lib.mapAttrs ( | ||
_: | ||
{ description, ... }: | ||
lib.mkOption { | ||
type = with lib.types; attrsOf anything; | ||
default = { }; | ||
inherit description; | ||
} | ||
) optionsAttrs; | ||
options = | ||
(lib.mapAttrs ( | ||
_: | ||
{ description, ... }: | ||
lib.mkOption { | ||
type = with lib.types; attrsOf anything; | ||
default = { }; | ||
inherit description; | ||
} | ||
) optionsAttrs) | ||
// { | ||
globalsPre = lib.mkOption { | ||
type = lib.types.lines; | ||
default = ""; | ||
internal = true; | ||
}; | ||
|
||
globalsPost = lib.mkOption { | ||
type = lib.types.lines; | ||
default = ""; | ||
internal = true; | ||
}; | ||
}; | ||
Comment on lines
+49
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the intention is that this is lua code injected pre/post the lua impl for the But reading the option name I'd half-expect to be able to assign This feels like working around a poor design rather than an objective improvement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if instead, each plugin should be responsible for using Yes, this would mean vim-plugins aren't taking advantage of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another idea: Perhaps the (maybe rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really a fan of any of the three solutions, tbh. So open to alternative proposals too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I though about that, but I think setting the global options in nix is a bit better, as it allows to do more compile time stuff (though you could still do compile time stuff by accessing the plugin's settings) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There could be a use for it, for example to define helpers for keymaps, or options There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still like the global option interface being used, too. I guess I am not too sure of when a vim plugin would use it, though. Almost feels like we would start blending the |
||
|
||
# Added 2024-03-29 (do not remove) | ||
imports = lib.mapAttrsToList (old: new: lib.mkRenamedOptionModule [ old ] [ new ]) { | ||
|
@@ -68,18 +82,27 @@ in | |
let | ||
varName = "nixvim_${luaVariableName}"; | ||
optionDefinitions = helpers.toLuaObject config.${optionName}; | ||
ifGlobals = lib.optionalString (optionName == "globals"); | ||
in | ||
lib.optionalString (optionDefinitions != "{ }") '' | ||
-- Set up ${prettyName} {{{ | ||
do | ||
local ${varName} = ${optionDefinitions} | ||
lib.optionalString (optionDefinitions != "{ }") ( | ||
'' | ||
-- Set up ${prettyName} {{{ | ||
'' | ||
+ (ifGlobals config.globalsPre) | ||
+ '' | ||
do | ||
local ${varName} = ${optionDefinitions} | ||
|
||
for k,v in pairs(${varName}) do | ||
vim.${luaApi}[k] = v | ||
for k,v in pairs(${varName}) do | ||
vim.${luaApi}[k] = v | ||
end | ||
end | ||
end | ||
-- }}} | ||
'' | ||
'' | ||
+ (ifGlobals config.globalsPost) | ||
+ '' | ||
-- }}} | ||
'' | ||
) | ||
) optionsAttrs | ||
); | ||
in | ||
|
Uh oh!
There was an error while loading. Please reload this page.