nixvim
nixvim copied to clipboard
mkNeovimPlugin should put a local variable into scope
Motivation
Many plugins use the following pattern:
pluginName = require('plugin-name')
pluginName.setup()
Usually this is done because the plugin table itself makes various constants, functions, or other utilities available that may be useful within settings or other config.
For example:
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.completion.spell,
require("none-ls.diagnostics.eslint"), -- requires none-ls-extras.nvim
},
})
Proposal
mkNeovimPlugin could do this semi-automatically either:
- always
- when
callSetup = true - based on some other flag
Example implementation
(simplified)
extraConfigLua = let
toLuaSymbol = s: /* a function that produces a lua variable name */;
in ''
(function() -- closure
local ${toLuaSymbol name} = require('${luaName}')
${optionalString callSetup "${toLuaSymbol name}.setup(${toLuaObject cfg.settings})"}
end)() -- invoke immediately
'';
The closure scope might be unnecessary if we want the variable available throughout init.lua?
Docs
We would then want to document in the user-guide that a plugin variable is made available for most/many plugins. In the specific plugin's docs we should document the exact variable name.
Alternative
If we decide we don't want to do this, we might consider documenting somewhere in the user-guide that upstream examples often use a local variable, but nixvim users should explicitly require instead.
@GaetanLepage I've marked you as the assignee because you mentioned planning to go over the mk*Plugin functions soon, not because I'm demanding you work on this :smile:. Of course, you can unassign if you've no interest in this.