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 # Opts
(flip mapAttrsToList config.vim.opt (k: set "vim.opt.${k}")) (flip mapAttrsToList config.vim.opt (k: set "vim.opt.${k}"))
# Plugins # Plugins
(map (v: v.genConfig) (filter (v: !v.isDependency) (attrValues config.plugin))) (map (v: v.genConfig) (filter (v: v.enable) (attrValues config.plugin)))
# Cmd # Cmd
(optional (config.vim.cmd != "") (call "vim.cmd" config.vim.cmd)) (optional (config.vim.cmd != "") (call "vim.cmd" config.vim.cmd))
# Autocommands # 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 { toplevel = pkgs.wrapNeovim pkgs.neovim-unwrapped {
viAlias = false; viAlias = false;

View file

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

View file

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

View file

@ -44,6 +44,7 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
plugin.hop-nvim = { plugin.hop-nvim = {
name = "hop"; name = "hop";
varName = "hop";
extraImports = { hop_hint = "hop.hint"; }; extraImports = { hop_hint = "hop.hint"; };
package = cfg.package; package = cfg.package;
setupSettings = cfg.settings; 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 { vim.g = lib.mkIf cfg.disableNetrw {
loaded_netrw = 1; loaded_netrw = 1;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,10 +2,13 @@
let let
inherit (builtins) elem attrNames; inherit (builtins) elem attrNames;
inherit (lib.nix2lua) pipe1 require call0 set;
cfg = config.plugins.style.nvim-treesitter; 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 = nvimTreeSitterWithBuiltinGrammars =
if cfg.grammars == null then cfg.package.withAllGrammars if cfg.grammars == null then cfg.package.withAllGrammars
@ -83,13 +86,13 @@ in
name = "nvim-treesitter.configs"; name = "nvim-treesitter.configs";
package = finalNvimTreeSitter; package = finalNvimTreeSitter;
beforeSetup = with lib; with nix2lua; optionals (cfg.extraGrammars != { }) (flatten [ extraImports = {
(local (set "parser_config") parser_config = pipe1 (require "nvim-treesitter.parsers") (call0 "get_parser_configs");
(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 [ setupSettings = lib.mkMerge [
# enable hihlight and indent by default # enable hihlight and indent by default

View file

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