From 9a920427a9ae9143295f9003a22ca56b0700aa7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 11 Jun 2023 10:22:19 +0200 Subject: [PATCH] refactor(nvim): overhaul nix glue and be more lazy --- modules/programs/nvim/default.nix | 49 +++++----- modules/programs/nvim/plugins/default.nix | 92 +++++++------------ modules/programs/nvim/plugins/mini-nvim.lua | 8 +- .../programs/nvim/plugins/nvim-treesitter.lua | 3 + .../plugins/nvim-ts-context-commentstring.lua | 5 - 5 files changed, 63 insertions(+), 94 deletions(-) delete mode 100644 modules/programs/nvim/plugins/nvim-ts-context-commentstring.lua diff --git a/modules/programs/nvim/default.nix b/modules/programs/nvim/default.nix index aacfb4c..47411b9 100644 --- a/modules/programs/nvim/default.nix +++ b/modules/programs/nvim/default.nix @@ -9,7 +9,10 @@ let cfg = config.my.programs.nvim; boolToString = bool: if bool then "true" else "false"; quote = str: ''"${toString str}"''; - listToString = list: ''{ ${concatStringsSep ", " (map quote list)} }''; + id = x: x; + listToString = sep: f: list: ''{ ${concatStringsSep sep (map f list)} }''; + listToStringOneLine = listToString ", "; + listToStringMultiLine = listToString ",\n"; keybinding = { key , cmd @@ -42,31 +45,23 @@ let , priority , keys }: - '' - { - dir = "${plugin}", - name = "${plugin.name}", - lazy = ${boolToString lazy}, - enabled = ${boolToString enabled}, - dependencies = { ${concatStringsSep ", " (map lazySpecFromPlugin dependencies)} }, - ${optionalString (init != null) - "init = function(plugin) - ${toString init} - end," - } - ${optionalString (conf != null) - "config = function(plugin, opts) - ${toString conf} - end," - } - keys = { ${concatStringsSep ",\n" (map keybinding keys)} }, - event = ${listToString event}, - cmd = ${listToString cmd}, - ft = ${listToString ft}, - priority = ${toString priority}, - } - ''; - lazySpecs = concatStringsSep ", " (map lazySpecFromPlugin cfg.plugins); + listToStringMultiLine id + ([ + "dir = ${quote plugin}" + "name = ${quote plugin.name}" + "lazy = ${boolToString lazy}" + ] + ++ (optional (!enabled) "enabled = ${boolToString enabled}") + ++ (optional (dependencies != [ ]) "dependencies = ${listToStringMultiLine id (map lazySpecFromPlugin dependencies)}") + ++ (optional (init != null) "init = function(plugin)\n${toString init}\nend") + ++ (optional (conf != null) "config = function(plugin, opts)\n${toString conf}\nend") + ++ (optional (keys != [ ]) "keys = ${listToStringMultiLine id (map keybinding keys)}") + ++ (optional (event != [ ]) "event = ${listToStringOneLine quote event}") + ++ (optional (cmd != [ ]) "cmd = ${listToStringOneLine quote cmd}") + ++ (optional (ft != [ ]) "ft = ${listToStringOneLine quote ft}") + ++ (optional (priority != 50) "priority = ${toString priority}") + ); + lazySpecs = listToStringMultiLine id (map lazySpecFromPlugin cfg.plugins); lazy = '' require("lazy").setup({ ${lazySpecs} @@ -117,7 +112,7 @@ in }; lazy = mkOption { type = bool; - default = false; + default = true; description = '' Whether to load the plugin lazily. ''; diff --git a/modules/programs/nvim/plugins/default.nix b/modules/programs/nvim/plugins/default.nix index 3b40c98..cf9026b 100644 --- a/modules/programs/nvim/plugins/default.nix +++ b/modules/programs/nvim/plugins/default.nix @@ -5,42 +5,46 @@ with builtins; config.my.programs.nvim.plugins = with pkgs.vimPlugins; [ { plugin = which-key-nvim; + lazy = false; conf = readFile ./which-key-nvim.lua; } { plugin = catppuccin-nvim; conf = readFile ./catppuccin-nvim.lua; + lazy = false; priority = 99; } { plugin = formatter-nvim; - lazy = true; keys = [ { key = "="; cmd = "Format"; desc = "format (formatter)"; } ]; conf = readFile ./formatter-nvim.lua; - dependencies = [{ plugin = which-key-nvim; lazy = true; }]; + dependencies = [{ plugin = which-key-nvim; }]; } { plugin = oil-nvim; + lazy = false; conf = readFile ./oil-nvim.lua; dependencies = [ - { plugin = which-key-nvim; lazy = true; } - { plugin = nvim-web-devicons; lazy = true; } + { plugin = which-key-nvim; } + { plugin = nvim-web-devicons; } ]; } + { plugin = nvim-ts-context-commentstring; } { plugin = mini-nvim; + lazy = false; conf = readFile ./mini-nvim.lua; } { plugin = noice-nvim; + lazy = false; conf = readFile ./noice-nvim.lua; - dependencies = [{ plugin = nui-nvim; lazy = true; }]; + dependencies = [{ plugin = nui-nvim; }]; } { plugin = trouble-nvim; - lazy = true; keys = [ { key = "xx"; cmd = "TroubleToggle document_diagnostics"; desc = "Document Diagnostics (Trouble)"; } { key = "xX"; cmd = "TroubleToggle workspace_diagnostics"; desc = "Workspace Diagnostics (Troule)"; } @@ -75,13 +79,12 @@ with builtins; conf = readFile ./trouble-nvim.lua; dependencies = [ { plugin = which-key-nvim; } - { plugin = nvim-web-devicons; lazy = true; } + { plugin = nvim-web-devicons; } ]; } { plugin = nvim-cmp; conf = readFile ./nvim-cmp.lua; - lazy = true; event = [ "InsertEnter" ]; dependencies = [ { plugin = cmp-async-path; } @@ -98,131 +101,94 @@ with builtins; ]; } { plugin = friendly-snippets; } - { plugin = luasnip; lazy = true; } + { plugin = luasnip; } ]; } { plugin = todo-comments-nvim; - lazy = true; event = [ "BufReadPost" "BufNewFile" ]; conf = readFile ./todo-comments-nvim.lua; - dependencies = [{ plugin = plenary-nvim; lazy = true; }]; + dependencies = [{ plugin = plenary-nvim; }]; } { plugin = direnv-vim; + lazy = false; } { plugin = nvim-treesitter.withAllGrammars; - lazy = true; event = [ "BufReadPost" "BufNewFile" ]; conf = readFile ./nvim-treesitter.lua; dependencies = [ + { plugin = nvim-ts-context-commentstring; } { plugin = orgmode; - lazy = true; conf = readFile ./orgmode.lua; } ]; } { plugin = nvim-lspconfig; - lazy = true; event = [ "BufReadPre" "BufNewFile" ]; conf = readFile ./nvim-lspconfig.lua; dependencies = [ { plugin = null-ls-nvim; - lazy = true; conf = readFile ./null-ls-nvim.lua; dependencies = [ - { plugin = which-key-nvim; lazy = true; } - { plugin = plenary-nvim; lazy = true; } + { plugin = which-key-nvim; } + { plugin = plenary-nvim; } ]; } - { - plugin = which-key-nvim; - lazy = true; - } - { - plugin = lspkind-nvim; - lazy = true; - } - { - plugin = lsp_lines-nvim; - lazy = true; - } + { plugin = which-key-nvim; } + { plugin = lspkind-nvim; } + { plugin = lsp_lines-nvim; } { plugin = lspsaga-nvim-original; - lazy = true; dependencies = [ - { plugin = nvim-web-devicons; lazy = true; } - { plugin = nvim-treesitter.withAllGrammars; lazy = true; } + { plugin = nvim-web-devicons; } + { plugin = nvim-treesitter.withAllGrammars; } ]; } { plugin = nvim-ufo; - lazy = true; dependencies = [ - { plugin = promise-async; lazy = true; } + { plugin = promise-async; } ]; } ]; } { event = [ "VeryLazy" ]; - lazy = true; plugin = vim-fugitive; } { plugin = vim-tmux-navigator; + lazy = false; } { plugin = gitsigns-nvim; - lazy = true; event = [ "BufReadPost" "BufNewFile" ]; conf = readFile ./gitsigns-nvim.lua; dependencies = [{ plugin = which-key-nvim; }]; } { plugin = nvim-lastplace; - lazy = true; event = [ "BufReadPost" "BufNewFile" ]; conf = readFile ./nvim-lastplace.lua; } { plugin = nvim-treesitter-textsubjects; - lazy = true; event = [ "BufReadPost" "BufNewFile" ]; conf = readFile ./nvim-treesitter-textsubjects.lua; - dependencies = [ - { - plugin = nvim-treesitter.withAllGrammars; - lazy = true; - } - ]; - } - { - plugin = nvim-ts-context-commentstring; - lazy = true; - event = [ "BufReadPost" "BufNewFile" ]; - conf = readFile ./nvim-ts-context-commentstring.lua; - dependencies = [ - { - plugin = nvim-treesitter.withAllGrammars; - lazy = true; - } - ]; } { plugin = smartcolumn-nvim; - lazy = true; event = [ "BufReadPost" "BufNewFile" ]; conf = readFile ./smartcolumn-nvim.lua; } { plugin = telescope-fzf-native-nvim; conf = readFile ./telescope-fzf-native-nvim.lua; - lazy = true; keys = [ { key = "ff"; cmd = "Telescope find_files"; desc = "Find files"; } { key = "fb"; cmd = "Telescope buffers"; desc = "Find buffers"; } @@ -242,13 +208,17 @@ with builtins; dependencies = [ { plugin = telescope-nvim; - lazy = true; dependencies = [ - { plugin = plenary-nvim; lazy = true; } - { plugin = which-key-nvim; lazy = true; } + { plugin = plenary-nvim; } + { plugin = which-key-nvim; } ]; } ]; } + { + plugin = vim-startuptime; + cmd = [ "StartupTime" ]; + conf = readFile ./vim-startuptime.lua; + } ]; } diff --git a/modules/programs/nvim/plugins/mini-nvim.lua b/modules/programs/nvim/plugins/mini-nvim.lua index fa40eda..e2824f6 100644 --- a/modules/programs/nvim/plugins/mini-nvim.lua +++ b/modules/programs/nvim/plugins/mini-nvim.lua @@ -1,5 +1,11 @@ require("mini.align").setup() -require("mini.comment").setup() +require("mini.comment").setup({ + options = { + custom_commentstring = function() + return require("ts_context_commentstring.internal").calculate_commentstring() or vim.bo.commentstring + end, + }, +}) require("mini.surround").setup() require("mini.move").setup() require("mini.pairs").setup() diff --git a/modules/programs/nvim/plugins/nvim-treesitter.lua b/modules/programs/nvim/plugins/nvim-treesitter.lua index c856c13..0c13317 100644 --- a/modules/programs/nvim/plugins/nvim-treesitter.lua +++ b/modules/programs/nvim/plugins/nvim-treesitter.lua @@ -9,4 +9,7 @@ require("nvim-treesitter.configs").setup({ -- code block highlights that do not have ts grammar additional_vim_regex_highlighting = { "org" }, }, + context_commentstring = { + enable = true, + }, }) diff --git a/modules/programs/nvim/plugins/nvim-ts-context-commentstring.lua b/modules/programs/nvim/plugins/nvim-ts-context-commentstring.lua deleted file mode 100644 index 42a4bb9..0000000 --- a/modules/programs/nvim/plugins/nvim-ts-context-commentstring.lua +++ /dev/null @@ -1,5 +0,0 @@ -require("nvim-treesitter.configs").setup({ - context_commentstring = { - enable = true, - }, -})