From 2799e830b2be8cdc5a6be141dbbdeed6c2c45f9d Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sun, 10 Mar 2024 00:44:02 +0100 Subject: [PATCH] plugins/indent-blankline: swith to mkNeovimPlugin --- plugins/utils/indent-blankline.nix | 157 ++++++++---------- .../plugins/utils/indent-blankline.nix | 136 +++++++++------ 2 files changed, 157 insertions(+), 136 deletions(-) diff --git a/plugins/utils/indent-blankline.nix b/plugins/utils/indent-blankline.nix index c03e1aad..9a15ff2e 100644 --- a/plugins/utils/indent-blankline.nix +++ b/plugins/utils/indent-blankline.nix @@ -5,19 +5,49 @@ pkgs, ... }: -with lib; { - options.plugins.indent-blankline = - helpers.neovim-plugin.extraOptionsOptions - // { - enable = mkEnableOption "indent-blankline.nvim"; +with lib; + helpers.neovim-plugin.mkNeovimPlugin config { + name = "indent-blankline"; + originalName = "indent-blankline.nvim"; + luaName = "ibl"; + defaultPackage = pkgs.vimPlugins.indent-blankline-nvim; - package = helpers.mkPackageOption "indent-blankline" pkgs.vimPlugins.indent-blankline-nvim; + maintainers = [maintainers.GaetanLepage]; + # TODO introduced 2024-03-10: remove 2024-05-10 + deprecateExtraOptions = true; + optionsRenamedToSettings = [ + "debounce" + ["viewportBuffer" "min"] + ["viewportBuffer" "max"] + ["indent" "char"] + ["indent" "tabChar"] + ["indent" "highlight"] + ["indent" "smartIndentCap"] + ["indent" "priority"] + ["whitespace" "highlight"] + ["whitespace" "removeBlanklineTrail"] + ["scope" "enabled"] + ["scope" "char"] + ["scope" "showStart"] + ["scope" "showEnd"] + ["scope" "showExactScope"] + ["scope" "injectedLanguages"] + ["scope" "highlight"] + ["scope" "priority"] + ["scope" "include" "nodeType"] + ["scope" "exclude" "language"] + ["scope" "exclude" "nodeType"] + ["exclude" "filetypes"] + ["exclude" "buftypes"] + ]; + + settingsOptions = { debounce = helpers.defaultNullOpts.mkUnsignedInt 200 '' Sets the amount indent-blankline debounces refreshes in milliseconds. ''; - viewportBuffer = { + viewport_buffer = { min = helpers.defaultNullOpts.mkUnsignedInt 30 '' Minimum number of lines above and below of what is currently visible in the window for which indentation guides will be generated. @@ -35,7 +65,7 @@ with lib; { Each character has to have a display width of 0 or 1. ''; - tabChar = helpers.mkNullOrOption (with types; either str (listOf str)) '' + tab_char = helpers.mkNullOrOption (with types; either str (listOf str)) '' Character, or list of characters, that get used to display the indentation guide for tabs. Each character has to have a display width of 0 or 1. @@ -49,7 +79,7 @@ with lib; { Default: `|hl-IblIndent|` ''; - smartIndentCap = helpers.defaultNullOpts.mkBool true '' + smart_indent_cap = helpers.defaultNullOpts.mkBool true '' Caps the number of indentation levels by looking at the surrounding code. ''; @@ -65,7 +95,7 @@ with lib; { Default: `|hl-IblWhitespace|` ''; - removeBlanklineTrail = helpers.defaultNullOpts.mkBool true '' + remove_blankline_trail = helpers.defaultNullOpts.mkBool true '' Removes trailing whitespace on blanklines. Turn this off if you want to add background color to the whitespace highlight group. @@ -83,21 +113,21 @@ with lib; { Default: `indent.char` ''; - showStart = helpers.defaultNullOpts.mkBool true '' + show_start = helpers.defaultNullOpts.mkBool true '' Shows an underline on the first line of the scope. ''; - showEnd = helpers.defaultNullOpts.mkBool true '' + show_end = helpers.defaultNullOpts.mkBool true '' Shows an underline on the last line of the scope. ''; - showExactScope = helpers.defaultNullOpts.mkBool false '' + show_exact_scope = helpers.defaultNullOpts.mkBool false '' Shows an underline on the first line of the scope starting at the exact start of the scope (even if this is to the right of the indent guide) and an underline on the last line of the scope ending at the exact end of the scope. ''; - injectedLanguages = helpers.defaultNullOpts.mkBool true '' + injected_languages = helpers.defaultNullOpts.mkBool true '' Checks for the current scope in injected treesitter languages. This also influences if the scope gets excluded or not. ''; @@ -113,7 +143,7 @@ with lib; { ''; include = { - nodeType = helpers.defaultNullOpts.mkNullable (with types; attrsOf (listOf str)) "{}" '' + node_type = helpers.defaultNullOpts.mkAttrsOf (with types; listOf str) "{}" '' Map of language to a list of node types which can be used as scope. - Use `*` as the language to act as a wildcard for all languages. @@ -122,13 +152,12 @@ with lib; { }; exclude = { - language = helpers.defaultNullOpts.mkNullable (with types; listOf str) "[]" '' + language = helpers.defaultNullOpts.mkListOf types.str "[]" '' List of treesitter languages for which scope is disabled. ''; - nodeType = - helpers.defaultNullOpts.mkNullable - (with types; attrsOf (listOf str)) + node_type = + helpers.defaultNullOpts.mkAttrsOf (with types; (listOf str)) '' { "*" = ["source_file" "program"]; @@ -146,8 +175,7 @@ with lib; { exclude = { filetypes = - helpers.defaultNullOpts.mkNullable - (with types; listOf str) + helpers.defaultNullOpts.mkListOf types.str '' [ "lspinfo" @@ -164,8 +192,7 @@ with lib; { "List of filetypes for which indent-blankline is disabled."; buftypes = - helpers.defaultNullOpts.mkNullable - (with types; listOf str) + helpers.defaultNullOpts.mkListOf types.str '' [ "terminal" @@ -178,65 +205,27 @@ with lib; { }; }; - config = let - cfg = config.plugins.indent-blankline; - in - mkIf cfg.enable { - extraPlugins = [cfg.package]; - - extraConfigLua = let - setupOptions = with cfg; - { - enabled = true; - inherit debounce; - viewport_buffer = with viewportBuffer; { - inherit - min - max - ; - }; - indent = with indent; { - inherit char; - tab_char = tabChar; - inherit highlight; - smart_indent_cap = smartIndentCap; - inherit priority; - }; - whitespace = with whitespace; { - inherit highlight; - remove_blankline_trail = removeBlanklineTrail; - }; - scope = with scope; { - inherit - enabled - char - ; - show_start = showStart; - show_end = showEnd; - show_exact_scope = showExactScope; - injected_languages = injectedLanguages; - inherit - highlight - priority - ; - include = with include; { - node_type = nodeType; - }; - exclude = with exclude; { - inherit language; - node_type = nodeType; - }; - }; - exclude = with exclude; { - inherit - filetypes - buftypes - ; - }; - } - // cfg.extraOptions; - in '' - require("ibl").setup(${helpers.toLuaObject setupOptions}) - ''; + settingsExample = { + indent = { + char = "│"; + }; + scope = { + show_start = false; + show_end = false; + show_exact_scope = true; + }; + exclude = { + filetypes = [ + "" + "checkhealth" + "help" + "lspinfo" + "packer" + "TelescopePrompt" + "TelescopeResults" + "yaml" + ]; + buftypes = ["terminal" "quickfix"]; + }; }; -} + } diff --git a/tests/test-sources/plugins/utils/indent-blankline.nix b/tests/test-sources/plugins/utils/indent-blankline.nix index 98bc0f72..17342cb1 100644 --- a/tests/test-sources/plugins/utils/indent-blankline.nix +++ b/tests/test-sources/plugins/utils/indent-blankline.nix @@ -3,65 +3,97 @@ plugins.indent-blankline.enable = true; }; + example = { + plugins.indent-blankline = { + enable = true; + + settings = { + indent = { + char = "│"; + }; + scope = { + show_start = false; + show_end = false; + show_exact_scope = true; + }; + exclude = { + filetypes = [ + "" + "checkhealth" + "help" + "lspinfo" + "packer" + "TelescopePrompt" + "TelescopeResults" + "yaml" + ]; + buftypes = ["terminal" "quickfix"]; + }; + }; + }; + }; + defaults = { plugins.indent-blankline = { enable = true; - debounce = 200; - viewportBuffer = { - min = 30; - max = 500; - }; - indent = { - char = "▎"; - tabChar = null; - highlight = null; - smartIndentCap = true; - priority = 1; - }; - whitespace = { - highlight = null; - removeBlanklineTrail = true; - }; - scope = { - enabled = true; - char = null; - showStart = true; - showEnd = true; - showExactScope = false; - injectedLanguages = true; - highlight = null; - priority = 1024; - include = { - nodeType = {}; + settings = { + debounce = 200; + viewport_buffer = { + min = 30; + max = 500; }; - exclude = { - language = []; - nodeType = { - "*" = ["source_file" "program"]; - lua = ["chunk"]; - python = ["module"]; + indent = { + char = "▎"; + tab_char = null; + highlight = null; + smart_indent_cap = true; + priority = 1; + }; + whitespace = { + highlight = null; + remove_blankline_trail = true; + }; + scope = { + enabled = true; + char = null; + show_start = true; + show_end = true; + show_exact_scope = false; + injected_languages = true; + highlight = null; + priority = 1024; + include = { + node_type = {}; + }; + exclude = { + language = []; + node_type = { + "*" = ["source_file" "program"]; + lua = ["chunk"]; + python = ["module"]; + }; }; }; - }; - exclude = { - filetypes = [ - "lspinfo" - "packer" - "checkhealth" - "help" - "man" - "gitcommit" - "TelescopePrompt" - "TelescopeResults" - "\'\'" - ]; - buftypes = [ - "terminal" - "nofile" - "quickfix" - "prompt" - ]; + exclude = { + filetypes = [ + "lspinfo" + "packer" + "checkhealth" + "help" + "man" + "gitcommit" + "TelescopePrompt" + "TelescopeResults" + "\'\'" + ]; + buftypes = [ + "terminal" + "nofile" + "quickfix" + "prompt" + ]; + }; }; }; };