modules/plugin: remove isDependency

do not import to local variable by default. Instead you should
set varName option.
This commit is contained in:
Dmitriy Pleshevskiy 2024-05-10 01:31:47 +03:00
parent c7b8eebba1
commit f3926f6365
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
13 changed files with 55 additions and 53 deletions

View file

@ -40,7 +40,7 @@ in
# Opts
(flip mapAttrsToList config.vim.opt (k: set "vim.opt.${k}"))
# Plugins
(map (v: v.genConfig) (filter (v: !v.isDependency) (attrValues config.plugin)))
(map (v: v.genConfig) (filter (v: v.enable) (attrValues config.plugin)))
# Cmd
(optional (config.vim.cmd != "") (call "vim.cmd" config.vim.cmd))
# Autocommands
@ -53,7 +53,7 @@ in
))
]));
plugins = lib.mapAttrsToList (k: v: v.package) config.plugin;
plugins = map (v: v.package) (filter (v: v.enable) (attrValues config.plugin));
toplevel = pkgs.wrapNeovim pkgs.neovim-unwrapped {
viAlias = false;

View file

@ -2,27 +2,29 @@
let
inherit (lib.nix2lua) require var local set pipe1 call;
pluginOpts = ({ name, config, ... }: {
options = with lib; with types; {
enable = mkEnableOption "Enable plugin <name>" // { default = true; };
name = mkOption {
type = str;
};
extraImports = mkOption {
type = attrsOf str;
type = attrsOf (either str attrs);
default = { };
example = { hint = "hop.hint"; };
};
varName = mkOption {
type = str;
# TODO: add validation
type = nullOr str;
default = null;
};
var = mkOption {
type = attrs;
internal = true;
};
package = mkPackageOption pkgs.vimPlugins name { };
isDependency = mkOption {
type = bool;
default = false;
};
beforeSetup = mkOption {
type = listOf attrs;
default = [ ];
@ -59,16 +61,25 @@ let
config = {
name = lib.mkDefault name;
varName = lib.mkDefault (builtins.replaceStrings [ "-" "/" "." ] [ "_" "_" "_" ] config.name);
genConfig = with lib; with nix2lua; mkIf (!config.isDependency) (flatten [
(local (set config.varName (require config.name)))
(mapAttrsToList (k: v: local (set k (require v))) config.extraImports)
var = if config.varName != null then var config.varName else require config.name;
genConfig = with lib; mkIf config.enable (flatten [
(lib.optional (config.varName != null) (local (set config.varName (require config.name))))
(mapAttrsToList
(k: v: local (set k (if builtins.isString v then require v else v)))
config.extraImports
)
config.beforeSetup
(optional (config.setupSettings != null)
(pipe1 (var config.varName) (call config.setupFnName config.setupSettings))
(pipe1
config.var
(call config.setupFnName config.setupSettings)
)
)
config.afterSetup
config.extra
]);

View file

@ -31,9 +31,7 @@ in
}
(lib.mkIf config.plugins.language-server.lspconfig.enable {
plugin.lualine-lsp-progress = lib.mkDefault {
isDependency = true;
};
plugin.lualine-lsp-progress = { };
})
]);
}

View file

@ -44,6 +44,7 @@ in
config = lib.mkIf cfg.enable {
plugin.hop-nvim = {
name = "hop";
varName = "hop";
extraImports = { hop_hint = "hop.hint"; };
package = cfg.package;
setupSettings = cfg.settings;

View file

@ -64,7 +64,7 @@ in
];
};
plugin.nvim-web-devicons = lib.mkDefault { isDependency = true; };
plugin.nvim-web-devicons = { };
vim.g = lib.mkIf cfg.disableNetrw {
loaded_netrw = 1;

View file

@ -40,7 +40,7 @@ let
config = {
name = lib.mkDefault name;
loadExtension = lib.mkDefault (pipe1
(var config.plugin.telescope-nvim.varName)
config.plugin.telescope-nvim.var
(call "load_extension" sub.config.name)
);
};
@ -84,9 +84,10 @@ in
config = lib.mkIf cfg.enable {
plugin = lib.mkMerge (lib.flatten [
{
plenary-nvim = lib.mkDefault { isDependency = true; };
telescope-nvim = {
plenary-nvim = { };
telescope-nvim = rec {
name = "telescope";
varName = name;
package = cfg.package;
setupSettings = lib.mkMerge (lib.flatten [
cfg.settings
@ -102,10 +103,7 @@ in
# extensions
(lib.flip lib.mapAttrsToList extensions (packageName: ext: {
"${packageName}" = {
inherit (ext) package;
isDependency = lib.mkDefault true;
};
"${packageName}" = { inherit (ext) package; };
}))
]);
};

View file

@ -32,18 +32,16 @@ in
# Backend dependencies
(lib.mkIf snippet.luasnip.enable {
plugin.cmp_luasnip = {
isDependency = true;
};
plugin.cmp_luasnip = { };
})
(lib.mkIf snippet.snippy.enable {
plugin.cmp-snippy = { isDependency = true; };
plugin.cmp-snippy = { };
})
(lib.mkIf snippet.vsnip.enable {
plugin.cmp-vsnip = { isDependency = true; };
plugin.cmp-vsnip = { };
})
(lib.mkIf snippet.ultisnips.enable {
plugin.cmp-nvim-ultisnips = { isDependency = true; };
plugin.cmp-nvim-ultisnips = { };
})
# Lsp configuration
@ -54,9 +52,7 @@ in
};
plugins.language-server.lspconfig.defaultServerSettings.capabilities =
pipe1
(var config.plugin.cmp-nvim-lsp.varName)
(call0 "default_capabilities");
pipe1 config.plugin.cmp-nvim-lsp.var (call0 "default_capabilities");
})
# Base configuration
@ -70,11 +66,11 @@ in
let body = pipe1 args (var "body"); in {
extra =
if snippet.luasnip.enable then
pipe1 (var config.plugin.luasnip.varName) (call "lsp_expand" body)
pipe1 config.plugin.luasnip.var (call "lsp_expand" body)
else if snippet.vsnip.enable then
call "vim.fn[\"${config.plugin.vim-vsnip.name}#anonymous\"]" body
else if snippet.snippy.enable then
pipe1 (var config.plugin.nvim-snippy.varName) (call "expand_snipped" body)
pipe1 config.plugin.nvim-snippy.var (call "expand_snipped" body)
else if snippet.ultisnips.enable then
call "vim.fn[\"${config.plugin.ultisnips.name}#Anon\"]" body
else

View file

@ -12,8 +12,8 @@ in
config = lib.mkIf cfg.enable {
plugin.nvim-snippy = {
name = "snippy";
inherit (cfg) package;
name = "snippy";
};
};
}

View file

@ -14,7 +14,6 @@ in
plugin.ultisnips = {
inherit (cfg) package;
name = "UltiSnips";
isDependency = true;
};
};
}

View file

@ -14,7 +14,6 @@ in
plugin.vim-vsnip = {
inherit (cfg) package;
name = "vsnip";
isDependency = true;
};
};
}

View file

@ -27,11 +27,8 @@ let cfg = config.plugins.style.neoformat; in
};
config = lib.mkIf cfg.enable {
plugin.neoformat = {
# we shouldn't import this plugin
isDependency = true;
package = cfg.package;
};
# we shouldn't import this plugin
plugin.neoformat.package = cfg.package;
vim.g = {
neoformat_try_node_exe = 1;

View file

@ -2,10 +2,13 @@
let
inherit (builtins) elem attrNames;
inherit (lib.nix2lua) pipe1 require call0 set;
cfg = config.plugins.style.nvim-treesitter;
treesitterWithGrammars = (cfg.treesitter.package.override { inherit (cfg) extraGrammars; }).withPlugins (lib.filterAtttrs (k: elem k (attrNames cfg.extraGrammars)));
treesitterWithGrammars = (cfg.treesitter.package.override {
inherit (cfg) extraGrammars;
}).withPlugins (lib.filterAtttrs (k: elem k (attrNames cfg.extraGrammars)));
nvimTreeSitterWithBuiltinGrammars =
if cfg.grammars == null then cfg.package.withAllGrammars
@ -83,13 +86,13 @@ in
name = "nvim-treesitter.configs";
package = finalNvimTreeSitter;
beforeSetup = with lib; with nix2lua; optionals (cfg.extraGrammars != { }) (flatten [
(local (set "parser_config")
(pipe1 (require "nvim-treesitter.parsers") (call0 "get_parser_configs"))
)
extraImports = {
parser_config = pipe1 (require "nvim-treesitter.parsers") (call0 "get_parser_configs");
};
(mapAttrsToList (k: v: set "parser_config.${v.language}" { }) cfg.extraGrammars)
]);
beforeSetup = with lib; optionals (cfg.extraGrammars != { }) (
mapAttrsToList (k: v: set "parser_config.${v.language}" { }) cfg.extraGrammars
);
setupSettings = lib.mkMerge [
# enable hihlight and indent by default

View file

@ -2,7 +2,7 @@
let inherit (lib.nix2lua) nf; in
{
plugin.editorconfig-nvim.isDependency = lib.mkDefault true;
plugin.editorconfig-nvim = { };
plugins = {
interface = {