diff --git a/plugins/utils/nvim-autopairs.nix b/plugins/utils/nvim-autopairs.nix index 31347c86..07169e7c 100644 --- a/plugins/utils/nvim-autopairs.nix +++ b/plugins/utils/nvim-autopairs.nix @@ -5,104 +5,208 @@ pkgs, ... }: -with lib; let - cfg = config.plugins.nvim-autopairs; -in { - options.plugins.nvim-autopairs = - helpers.neovim-plugin.extraOptionsOptions - // { - enable = mkEnableOption "nvim-autopairs"; +with lib; + helpers.neovim-plugin.mkNeovimPlugin config { + name = "nvim-autopairs"; + defaultPackage = pkgs.vimPlugins.nvim-autopairs; - package = helpers.mkPackageOption "nvim-autopairs" pkgs.vimPlugins.nvim-autopairs; + maintainers = [maintainers.GaetanLepage]; - pairs = helpers.mkNullOrOption (types.attrsOf types.str) "Characters to pair up"; + # TODO: introduced 2024-03-27, remove on 2024-05-27 + deprecateExtraOptions = true; + optionsRenamedToSettings = [ + "disableInMacro" + "disableInVisualblock" + "disableInReplaceMode" + "ignoredNextChar" + "enableMoveright" + "enableCheckBracketLine" + "enableBracketInQuote" + "enableAbbr" + "breakUndo" + "checkTs" + "tsConfig" + "mapCr" + "mapBs" + "mapCH" + "mapCW" + ]; + imports = let + basePluginPaths = ["plugins" "nvim-autopairs"]; + settingsPath = basePluginPaths ++ ["settings"]; + in [ + ( + mkRenamedOptionModule + (basePluginPaths ++ ["disabledFiletypes"]) + (settingsPath ++ ["disable_filetype"]) + ) + ( + mkRenamedOptionModule + (basePluginPaths ++ ["enableAfterQuote"]) + (settingsPath ++ ["enable_afterquote"]) + ) + ( + mkRemovedOptionModule + (basePluginPaths ++ ["pairs"]) + '' + This option was having no effect. + If you want to customize pairs, please use `extraConfigLua` to define them as described in the plugin documentation. + '' + ) + ]; - disabledFiletypes = - helpers.defaultNullOpts.mkNullable - (types.listOf types.str) - ''[ "TelescopePrompt" "spectre_panel" ]'' - "Disabled filetypes"; + settingsOptions = { + disable_filetype = + helpers.defaultNullOpts.mkListOf types.str + ''["TelescopePrompt" "spectre_panel"]'' + "Disabled filetypes."; - disableInMacro = helpers.defaultNullOpts.mkBool false '' + disable_in_macro = helpers.defaultNullOpts.mkBool false '' Disable when recording or executing a macro. ''; - disableInVisualblock = helpers.defaultNullOpts.mkBool false '' + disable_in_visualblock = helpers.defaultNullOpts.mkBool false '' Disable when insert after visual block mode. ''; - disableInReplaceMode = helpers.defaultNullOpts.mkBool true "Disable in replace mode."; + disable_in_replace_mode = helpers.defaultNullOpts.mkBool true '' + Disable in replace mode. + ''; - ignoredNextChar = helpers.defaultNullOpts.mkLua "[=[[%w%%%'%[%\"%.%`%$]]=]" '' + ignored_next_char = helpers.defaultNullOpts.mkLua "[=[[%w%%%'%[%\"%.%`%$]]=]" '' Regexp to ignore if it matches the next character. ''; - enableMoveright = helpers.defaultNullOpts.mkBool true "Enable moveright."; - - enableAfterQuote = helpers.defaultNullOpts.mkBool true "Add bracket pairs after quote."; - - enableCheckBracketLine = helpers.defaultNullOpts.mkBool true "Check bracket in same line."; - - enableBracketInQuote = helpers.defaultNullOpts.mkBool true "Enable bracket in quote."; - - enableAbbr = helpers.defaultNullOpts.mkBool false "Trigger abbreviation."; - - breakUndo = helpers.defaultNullOpts.mkBool true "Switch for basic rule break undo sequence."; - - checkTs = helpers.defaultNullOpts.mkBool false "Use treesitter to check for a pair."; - - tsConfig = helpers.mkNullOrOption (types.nullOr types.attrs) '' - Configuration for TreeSitter. - - Default: - ``` - { - lua = [ "string" "source" ]; - javascript = [ "string" "template_string" ]; - }; - ``` + enable_moveright = helpers.defaultNullOpts.mkBool true '' + Enable moveright. ''; - mapCr = helpers.defaultNullOpts.mkBool true "Map the key to confirm the completion."; - - mapBs = helpers.defaultNullOpts.mkBool true "Map the key to delete the pair."; - - mapCH = helpers.defaultNullOpts.mkBool false "Map the key to delete a pair."; - - mapCW = helpers.defaultNullOpts.mkBool false "Map the key to delete a pair if possible."; - }; - - config = let - options = - { - pairs_map = cfg.pairs; - - disable_filetype = cfg.disabledFiletypes; - disable_in_macro = cfg.disableInMacro; - disable_in_visualblock = cfg.disableInVisualblock; - disable_in_replace_mode = cfg.disableInReplaceMode; - ignored_next_char = cfg.ignoredNextChar; - enable_moveright = cfg.enableMoveright; - enable_afterquote = cfg.enableAfterQuote; - enable_check_bracket_line = cfg.enableCheckBracketLine; - enable_bracket_in_quote = cfg.enableBracketInQuote; - enable_abbr = cfg.enableAbbr; - break_undo = cfg.breakUndo; - check_ts = cfg.checkTs; - map_cr = cfg.mapCr; - map_bs = cfg.mapBs; - map_c_h = cfg.mapCH; - map_c_w = cfg.mapCW; - } - // cfg.extraOptions; - in - mkIf cfg.enable { - extraPlugins = [cfg.package]; - - plugins.treesitter.enable = mkIf (cfg.checkTs != null && cfg.checkTs) true; - - extraConfigLua = '' - require('nvim-autopairs').setup(${helpers.toLuaObject options}) + enable_afterquote = helpers.defaultNullOpts.mkBool true '' + Add bracket pairs after quote. ''; + + enable_check_bracket_line = helpers.defaultNullOpts.mkBool true '' + Check bracket in same line. + ''; + + enable_bracket_in_quote = helpers.defaultNullOpts.mkBool true '' + Enable bracket in quote. + ''; + + enable_abbr = helpers.defaultNullOpts.mkBool false '' + Trigger abbreviation. + ''; + + break_undo = helpers.defaultNullOpts.mkBool true '' + Switch for basic rule break undo sequence. + ''; + + check_ts = helpers.defaultNullOpts.mkBool false '' + Use treesitter to check for a pair. + ''; + + ts_config = + helpers.defaultNullOpts.mkAttrsOf types.anything + '' + { + lua = [ + "string" + "source" + "string_content" + ]; + javascript = [ + "string" + "template_string" + ]; + } + '' + "Configuration for TreeSitter."; + + map_cr = helpers.defaultNullOpts.mkBool true '' + Map the `` key to confirm the completion. + ''; + + map_bs = helpers.defaultNullOpts.mkBool true '' + Map the `` key to delete the pair. + ''; + + map_c_h = helpers.defaultNullOpts.mkBool false '' + Map the `` key to delete a pair. + ''; + + map_c_w = helpers.defaultNullOpts.mkBool false '' + Map the `` key to delete a pair if possible. + ''; + + fast_wrap = { + map = helpers.defaultNullOpts.mkStr "" '' + The key to trigger fast_wrap. + ''; + + chars = helpers.defaultNullOpts.mkListOf types.str ''["{" "[" "(" "\"" "'"]'' '' + Characters for which to enable fast wrap. + ''; + + pattern = helpers.defaultNullOpts.mkLua ''[=[[%'%"%>%]%)%}%,%`]]=]'' '' + The pattern to match against. + ''; + + end_key = helpers.defaultNullOpts.mkStr "$" '' + End key. + ''; + + before_key = helpers.defaultNullOpts.mkStr "h" '' + Before key. + ''; + + after_key = helpers.defaultNullOpts.mkStr "l" '' + After key. + ''; + + cursor_pos_before = helpers.defaultNullOpts.mkBool true '' + Whether the cursor should be placed before or after the substitution. + ''; + + keys = + helpers.defaultNullOpts.mkStr "qwertyuiopzxcvbnmasdfghjkl" '' + ''; + + highlight = helpers.defaultNullOpts.mkStr "Search" '' + Which highlight group to use for the match. + ''; + + highlight_grey = helpers.defaultNullOpts.mkStr "Comment" '' + Which highlight group to use for the grey part. + ''; + + manual_position = helpers.defaultNullOpts.mkBool true '' + Whether to enable manual position. + ''; + + use_virt_lines = helpers.defaultNullOpts.mkBool true '' + Whether to use `virt_lines`. + ''; + }; }; -} + + settingsExample = { + disable_filetype = ["TelescopePrompt"]; + fast_wrap = { + map = ""; + end_key = "$"; + }; + }; + + extraConfig = cfg: { + warnings = + optional ( + (isBool cfg.settings.check_ts) + && cfg.settings.check_ts + && !config.plugins.treesitter.enable + ) + '' + Nixvim (plugins.nvim-autopairs): You have set `settings.check_ts` to `true` but have not enabled the treesitter plugin. + We suggest you to set `plugins.treesitter.enable` to `true`. + ''; + }; + } diff --git a/tests/test-sources/plugins/utils/nvim-autopairs.nix b/tests/test-sources/plugins/utils/nvim-autopairs.nix index 4f5b7559..21f7e9d9 100644 --- a/tests/test-sources/plugins/utils/nvim-autopairs.nix +++ b/tests/test-sources/plugins/utils/nvim-autopairs.nix @@ -7,27 +7,49 @@ plugins.nvim-autopairs = { enable = true; - pairs = null; - disabledFiletypes = ["TelescopePrompt" "spectre_panel"]; - disableInMacro = false; - disableInVisualblock = false; - disableInReplaceMode = true; - ignoredNextChar = "[=[[%w%%%'%[%\"%.%`%$]]=]"; - enableMoveright = true; - enableAfterQuote = true; - enableCheckBracketLine = true; - enableBracketInQuote = true; - enableAbbr = false; - breakUndo = true; - checkTs = false; - tsConfig = { - lua = ["string" "source"]; - javascript = ["string" "template_string"]; + settings = { + disable_filetype = ["TelescopePrompt" "spectre_panel"]; + disable_in_macro = false; + disable_in_visualblock = false; + disable_in_replace_mode = true; + ignored_next_char = "[=[[%w%%%'%[%\"%.%`%$]]=]"; + enable_moveright = true; + enable_afterquote = true; + enable_check_bracket_line = true; + enable_bracket_in_quote = true; + enable_abbr = false; + break_undo = true; + check_ts = false; + ts_config = { + lua = [ + "string" + "source" + "string_content" + ]; + javascript = [ + "string" + "template_string" + ]; + }; + map_cr = true; + map_bs = true; + map_c_h = false; + map_c_w = false; + fast_wrap = { + map = ""; + chars = ["{" "[" "(" "\"" "'"]; + pattern = ''[=[[%'%"%>%]%)%}%,%`]]=]''; + end_key = "$"; + before_key = "h"; + after_key = "l"; + cursor_pos_before = true; + keys = "qwertyuiopzxcvbnmasdfghjkl"; + highlight = "Search"; + highlight_grey = "Comment"; + manual_position = true; + use_virt_lines = true; + }; }; - mapCr = true; - mapBs = true; - mapCH = false; - mapCW = false; }; }; }