From 0b69e17e0d3b80873f3890a70634a74a01915d84 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 26 Feb 2024 08:05:23 +0300 Subject: [PATCH] modules: make lib calls explicit where possible --- modules/assistant/copilot/config.nix | 15 +++--- modules/assistant/copilot/copilot.nix | 47 ++++++++++++------- modules/assistant/copilot/default.nix | 2 +- modules/autopairs/default.nix | 2 +- modules/autopairs/nvim-autopairs/config.nix | 36 +++++++------- modules/autopairs/nvim-autopairs/default.nix | 2 +- .../nvim-autopairs/nvim-autopairs.nix | 11 +++-- .../comments/comment-nvim/comment-nvim.nix | 3 +- modules/comments/comment-nvim/config.nix | 12 ++--- modules/comments/comment-nvim/default.nix | 2 +- modules/comments/default.nix | 2 +- modules/completion/default.nix | 2 +- modules/completion/nvim-cmp/config.nix | 13 +++-- modules/completion/nvim-cmp/nvim-cmp.nix | 10 ++-- modules/dashboard/default.nix | 2 +- 15 files changed, 92 insertions(+), 69 deletions(-) diff --git a/modules/assistant/copilot/config.nix b/modules/assistant/copilot/config.nix index 18f540dda..5cfe95530 100644 --- a/modules/assistant/copilot/config.nix +++ b/modules/assistant/copilot/config.nix @@ -1,11 +1,14 @@ { - pkgs, config, lib, ... }: let inherit (builtins) toJSON; - inherit (lib) mkIf nvim mkLuaBinding mkMerge; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.lists) optionals; + inherit (lib.trivial) boolToString; + inherit (lib.nvim.binds) mkLuaBinding; cfg = config.vim.assistant.copilot; @@ -27,16 +30,16 @@ in { "copilot-lua" cfg.copilotNodePackage ] - ++ lib.optionals (cfg.cmp.enable) [ + ++ optionals (cfg.cmp.enable) [ "copilot-cmp" ]; - vim.luaConfigRC.copilot = nvim.dag.entryAnywhere '' + vim.luaConfigRC.copilot = entryAnywhere '' require("copilot").setup({ -- available options: https://github.com/zbirenbaum/copilot.lua copilot_node_command = "${cfg.copilotNodeCommand}", panel = { - enabled = ${lib.boolToString (!cfg.cmp.enable)}, + enabled = ${boolToString (!cfg.cmp.enable)}, keymap = { jump_prev = false, jump_next = false, @@ -50,7 +53,7 @@ in { }, }, suggestion = { - enabled = ${lib.boolToString (!cfg.cmp.enable)}, + enabled = ${boolToString (!cfg.cmp.enable)}, keymap = { accept = false, accept_word = false, diff --git a/modules/assistant/copilot/copilot.nix b/modules/assistant/copilot/copilot.nix index 858386948..283a0b6e0 100644 --- a/modules/assistant/copilot/copilot.nix +++ b/modules/assistant/copilot/copilot.nix @@ -1,10 +1,12 @@ { - pkgs, config, + pkgs, lib, ... }: let - inherit (lib) mkEnableOption mkOption types; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) enum float nullOr str package; + inherit (lib.meta) getExe; cfg = config.vim.assistant.copilot; in { @@ -14,7 +16,7 @@ in { panel = { position = mkOption { - type = types.enum [ + type = enum [ "bottom" "top" "left" @@ -24,7 +26,7 @@ in { description = "Panel position"; }; ratio = mkOption { - type = types.float; + type = float; default = 0.4; description = "Panel size"; }; @@ -33,59 +35,68 @@ in { mappings = { panel = { jumpPrev = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = "[["; description = "Jump to previous suggestion"; }; + jumpNext = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = "]]"; description = "Jump to next suggestion"; }; + accept = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Accept suggestion"; }; + refresh = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = "gr"; description = "Refresh suggestions"; }; + open = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Open suggestions"; }; }; suggestion = { accept = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Accept suggetion"; }; + acceptWord = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = null; description = "Accept next word"; }; + acceptLine = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = null; description = "Accept next line"; }; + prev = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Previous suggestion"; }; + next = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Next suggestion"; }; + dismiss = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Dismiss suggestion"; }; @@ -93,8 +104,8 @@ in { }; copilotNodeCommand = mkOption { - type = types.str; - default = "${lib.getExe cfg.copilotNodePackage}"; + type = str; + default = "${getExe cfg.copilotNodePackage}"; description = '' The command that will be executed to initiate nodejs for GitHub Copilot. Recommended to leave as default. @@ -102,7 +113,7 @@ in { }; copilotNodePackage = mkOption { - type = with types; nullOr package; + type = nullOr package; default = pkgs.nodejs-slim; description = '' The nodeJS package that will be used for GitHub Copilot. If you are using a custom node command diff --git a/modules/assistant/copilot/default.nix b/modules/assistant/copilot/default.nix index fb291bdf2..2b890451b 100644 --- a/modules/assistant/copilot/default.nix +++ b/modules/assistant/copilot/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./copilot.nix ./config.nix diff --git a/modules/autopairs/default.nix b/modules/autopairs/default.nix index 742665c7b..cc2f69c60 100644 --- a/modules/autopairs/default.nix +++ b/modules/autopairs/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-autopairs ]; diff --git a/modules/autopairs/nvim-autopairs/config.nix b/modules/autopairs/nvim-autopairs/config.nix index 0aceca5d2..1502db84b 100644 --- a/modules/autopairs/nvim-autopairs/config.nix +++ b/modules/autopairs/nvim-autopairs/config.nix @@ -1,26 +1,28 @@ { - lib, config, + lib, ... }: let - inherit (lib) mkIf nvim optionalString boolToString; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.strings) optionalString; + inherit (lib.trivial) boolToString; cfg = config.vim.autopairs; in { - config = - mkIf (cfg.enable) - { - vim.startPlugins = ["nvim-autopairs"]; + config = mkIf cfg.enable { + vim.startPlugins = ["nvim-autopairs"]; - vim.luaConfigRC.autopairs = nvim.dag.entryAnywhere '' - require("nvim-autopairs").setup{} - ${optionalString (config.vim.autocomplete.type == "nvim-compe") '' - require('nvim-autopairs.completion.compe').setup({ - map_cr = ${boolToString cfg.nvim-compe.map_cr}, - map_complete = ${boolToString cfg.nvim-compe.map_complete}, - auto_select = ${boolToString cfg.nvim-compe.auto_select}, - }) - ''} - ''; - }; + vim.luaConfigRC.autopairs = entryAnywhere '' + require("nvim-autopairs").setup{} + ${optionalString (config.vim.autocomplete.type == "nvim-compe") '' + -- nvim-compe integration + require('nvim-autopairs.completion.compe').setup({ + map_cr = ${boolToString cfg.nvim-compe.map_cr}, + map_complete = ${boolToString cfg.nvim-compe.map_complete}, + auto_select = ${boolToString cfg.nvim-compe.auto_select}, + }) + ''} + ''; + }; } diff --git a/modules/autopairs/nvim-autopairs/default.nix b/modules/autopairs/nvim-autopairs/default.nix index f22833105..709804942 100644 --- a/modules/autopairs/nvim-autopairs/default.nix +++ b/modules/autopairs/nvim-autopairs/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./nvim-autopairs.nix diff --git a/modules/autopairs/nvim-autopairs/nvim-autopairs.nix b/modules/autopairs/nvim-autopairs/nvim-autopairs.nix index 330d11869..940a60c79 100644 --- a/modules/autopairs/nvim-autopairs/nvim-autopairs.nix +++ b/modules/autopairs/nvim-autopairs/nvim-autopairs.nix @@ -1,31 +1,32 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkOption types; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) enum bool; in { options.vim = { autopairs = { enable = mkEnableOption "autopairs" // {default = false;}; type = mkOption { - type = types.enum ["nvim-autopairs"]; + type = enum ["nvim-autopairs"]; default = "nvim-autopairs"; description = "Set the autopairs type. Options: nvim-autopairs [nvim-autopairs]"; }; nvim-compe = { map_cr = mkOption { - type = types.bool; + type = bool; default = true; description = ''map on insert mode''; }; map_complete = mkOption { - type = types.bool; + type = bool; default = true; description = "auto insert `(` after select function or method item"; }; auto_select = mkOption { - type = types.bool; + type = bool; default = false; description = "auto select first item"; }; diff --git a/modules/comments/comment-nvim/comment-nvim.nix b/modules/comments/comment-nvim/comment-nvim.nix index 13ca47533..61a917155 100644 --- a/modules/comments/comment-nvim/comment-nvim.nix +++ b/modules/comments/comment-nvim/comment-nvim.nix @@ -1,5 +1,6 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption; + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; in { options.vim.comments.comment-nvim = { enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim"; diff --git a/modules/comments/comment-nvim/config.nix b/modules/comments/comment-nvim/config.nix index ea2f1e194..40ccb0ab5 100644 --- a/modules/comments/comment-nvim/config.nix +++ b/modules/comments/comment-nvim/config.nix @@ -3,13 +3,13 @@ lib, ... }: let - inherit (lib) mkIf mkMerge mkExprBinding mkBinding nvim; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.binds) mkExprBinding mkBinding; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.comments.comment-nvim; - self = import ./comment-nvim.nix { - inherit lib; - }; - mappings = self.options.vim.comments.comment-nvim.mappings; + self = import ./comment-nvim.nix {inherit lib;}; + inherit (self.options.vim.comments.comment-nvim) mappings; in { config = mkIf cfg.enable { vim.startPlugins = [ @@ -41,7 +41,7 @@ in { (mkBinding cfg.mappings.toggleSelectedBlock "(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description) ]; - vim.luaConfigRC.comment-nvim = nvim.dag.entryAnywhere '' + vim.luaConfigRC.comment-nvim = entryAnywhere '' require('Comment').setup({ mappings = { basic = false, extra = false, }, }) diff --git a/modules/comments/comment-nvim/default.nix b/modules/comments/comment-nvim/default.nix index db4eb4241..6a6dbcb68 100644 --- a/modules/comments/comment-nvim/default.nix +++ b/modules/comments/comment-nvim/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./comment-nvim.nix diff --git a/modules/comments/default.nix b/modules/comments/default.nix index cb6ac1911..afc1a8799 100644 --- a/modules/comments/default.nix +++ b/modules/comments/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./comment-nvim ]; diff --git a/modules/completion/default.nix b/modules/completion/default.nix index 77d51b419..0cae45f68 100644 --- a/modules/completion/default.nix +++ b/modules/completion/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-cmp ]; diff --git a/modules/completion/nvim-cmp/config.nix b/modules/completion/nvim-cmp/config.nix index b20f71b78..142a1189b 100644 --- a/modules/completion/nvim-cmp/config.nix +++ b/modules/completion/nvim-cmp/config.nix @@ -4,8 +4,11 @@ ... }: let inherit (builtins) toJSON; - inherit (lib) addDescriptionsToMappings concatMapStringsSep attrNames concatStringsSep mapAttrsToList mkIf mkSetLuaBinding mkMerge optionalString; - inherit (lib.nvim) dag; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.attrsets) attrNames mapAttrsToList; + inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding; + inherit (lib.nvim.dag) entryAnywhere entryAfter; cfg = config.vim.autocomplete; lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable; @@ -33,8 +36,8 @@ dagPlacement = if lspkindEnabled - then dag.entryAfter ["lspkind"] - else dag.entryAnywhere; + then entryAfter ["lspkind"] + else entryAnywhere; in { config = mkIf cfg.enable { vim.startPlugins = [ @@ -195,7 +198,7 @@ in { local cmp = require'cmp' cmp.setup({ - ${optionalString (config.vim.ui.borders.enable) '' + ${optionalString config.vim.ui.borders.enable '' -- explicitly enabled by setting ui.borders.enable = true -- TODO: try to get nvim-cmp to follow global border style window = { diff --git a/modules/completion/nvim-cmp/nvim-cmp.nix b/modules/completion/nvim-cmp/nvim-cmp.nix index 38c861989..59c32db16 100644 --- a/modules/completion/nvim-cmp/nvim-cmp.nix +++ b/modules/completion/nvim-cmp/nvim-cmp.nix @@ -1,5 +1,7 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption mkOption types; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.types) enum attrsOf nullOr str; in { options.vim = { autocomplete = { @@ -16,7 +18,7 @@ in { }; type = mkOption { - type = types.enum ["nvim-cmp"]; + type = enum ["nvim-cmp"]; default = "nvim-cmp"; description = "Set the autocomplete plugin. Options: [nvim-cmp]"; }; @@ -31,7 +33,7 @@ in { Note: only use a single attribute name per attribute set ''; - type = with types; attrsOf (nullOr str); + type = attrsOf (nullOr str); default = {}; example = '' {nvim-cmp = null; buffer = "[Buffer]";} @@ -48,7 +50,7 @@ in { Default is to call the menu mapping function. ''; - type = types.str; + type = str; default = "nvim_cmp_menu_map"; example = lib.literalMD '' ```lua diff --git a/modules/dashboard/default.nix b/modules/dashboard/default.nix index c63ad3ef4..365ea8d04 100644 --- a/modules/dashboard/default.nix +++ b/modules/dashboard/default.nix @@ -1,4 +1,4 @@ -{...}: { +{ imports = [ ./alpha ./dashboard-nvim