From b822078ec1b2bbf666af767061e29575edc5ec05 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Mon, 17 Jun 2024 09:54:18 +0200 Subject: [PATCH] plugins/ts-autotag: switch to mkNeovimPlugin --- plugins/languages/treesitter/ts-autotag.nix | 151 ++++++++++-------- .../languages/treesitter/ts-autotag.nix | 89 ++++++----- 2 files changed, 138 insertions(+), 102 deletions(-) diff --git a/plugins/languages/treesitter/ts-autotag.nix b/plugins/languages/treesitter/ts-autotag.nix index 99ca02a6..e8065b14 100644 --- a/plugins/languages/treesitter/ts-autotag.nix +++ b/plugins/languages/treesitter/ts-autotag.nix @@ -1,78 +1,103 @@ { - pkgs, lib, helpers, config, + pkgs, ... }: with lib; -{ - options.plugins.ts-autotag = helpers.neovim-plugin.extraOptionsOptions // { - enable = mkEnableOption "nvim-ts-autotag"; +helpers.neovim-plugin.mkNeovimPlugin config { + name = "ts-autotag"; + originalName = "nvim-ts-autotag"; + luaName = "nvim-ts-autotag"; + defaultPackage = pkgs.vimPlugins.nvim-ts-autotag; - package = helpers.mkPluginPackageOption "ts-autotag" pkgs.vimPlugins.nvim-ts-autotag; + maintainers = [ maintainers.GaetanLepage ]; - filetypes = helpers.defaultNullOpts.mkNullable (with types; listOf str) '' + # TODO introduced 2024-06-17: remove 2024-08-17 + deprecateExtraOptions = true; + imports = + map + ( + optionName: + mkRemovedOptionModule + [ + "plugins" + "ts-autotag" + optionName + ] + '' + The `ts-autotag` plugin is no longer configured using `nvim-treesitter.configs`. + Please, refer to upstream documentation: + https://github.com/windwp/nvim-ts-autotag#setup + '' + ) [ - "html" - "javascript" - "typescript" - "javascriptreact" - "typescriptreact" - "svelte" - "vue" - "tsx" - "jsx" - "rescript" - "xml" - "php" - "markdown" - "astro" - "glimmer" - "handlebars" - "hbs" - ] - '' "Filetypes for which ts-autotag should be enabled."; - - skipTags = helpers.defaultNullOpts.mkNullable (with types; listOf str) '' - [ - "area" - "base" - "br" - "col" - "command" - "embed" - "hr" - "img" - "slot" - "input" - "keygen" - "link" - "meta" - "param" - "source" - "track" - "wbr" - "menuitem" - ] - '' "Which tags to skip."; - }; - - config = - let - cfg = config.plugins.ts-autotag; - in - mkIf cfg.enable { - warnings = mkIf (!config.plugins.treesitter.enable) [ - "Nixvim: ts-autotag needs treesitter to function as intended" + "filetypes" + "skipTags" ]; - extraPlugins = [ cfg.package ]; + extraConfig = cfg: { + warnings = mkIf (!config.plugins.treesitter.enable) [ + "Nixvim: ts-autotag needs treesitter to function as intended" + ]; + }; - plugins.treesitter.moduleConfig.autotag = { - enable = true; - inherit (cfg) filetypes; - skip_tags = cfg.skipTags; - } // cfg.extraOptions; + settingsOptions = + let + opts = { + enable_close = helpers.defaultNullOpts.mkBool true '' + Whether or not to auto close tags. + ''; + + enable_rename = helpers.defaultNullOpts.mkBool true '' + Whether or not to auto rename paired tags. + ''; + + enable_close_on_slash = helpers.defaultNullOpts.mkBool true '' + Whether or not to auto close tags when a `/` is inserted. + ''; + }; + in + { + inherit opts; + + aliases = helpers.defaultNullOpts.mkAttrsOf types.str { + "astro" = "html"; + "eruby" = "html"; + "vue" = "html"; + "htmldjango" = "html"; + "markdown" = "html"; + "php" = "html"; + "twig" = "html"; + "blade" = "html"; + "javascriptreact" = "typescriptreact"; + "javascript.jsx" = "typescriptreact"; + "typescript.tsx" = "typescriptreact"; + "javascript" = "typescriptreact"; + "typescript" = "typescriptreact"; + "rescript" = "typescriptreact"; + "handlebars" = "glimmer"; + "hbs" = "glimmer"; + "rust" = "rust"; + } "Filetype aliases."; + + per_filetype = helpers.defaultNullOpts.mkAttrsOf (types.submodule { + freeformType = with types; attrsOf anything; + options = opts; + }) { } "Per filetype config overrides."; }; + + settingsExample = { + opts = { + enable_close = true; + enable_rename = true; + enable_close_on_slash = false; + }; + per_filetype = { + html = { + enable_close = false; + }; + }; + }; } diff --git a/tests/test-sources/plugins/languages/treesitter/ts-autotag.nix b/tests/test-sources/plugins/languages/treesitter/ts-autotag.nix index f50fdce5..d214a640 100644 --- a/tests/test-sources/plugins/languages/treesitter/ts-autotag.nix +++ b/tests/test-sources/plugins/languages/treesitter/ts-autotag.nix @@ -11,45 +11,56 @@ treesitter.enable = true; ts-autotag = { enable = true; - filetypes = [ - "html" - "javascript" - "typescript" - "javascriptreact" - "typescriptreact" - "svelte" - "vue" - "tsx" - "jsx" - "rescript" - "xml" - "php" - "markdown" - "astro" - "glimmer" - "handlebars" - "hbs" - ]; - skipTags = [ - "area" - "base" - "br" - "col" - "command" - "embed" - "hr" - "img" - "slot" - "input" - "keygen" - "link" - "meta" - "param" - "source" - "track" - "wbr" - "menuitem" - ]; + + settings = { + opts = { + enable_close = true; + enable_rename = true; + enable_close_on_slash = true; + }; + aliases = { + "astro" = "html"; + "eruby" = "html"; + "vue" = "html"; + "htmldjango" = "html"; + "markdown" = "html"; + "php" = "html"; + "twig" = "html"; + "blade" = "html"; + "javascriptreact" = "typescriptreact"; + "javascript.jsx" = "typescriptreact"; + "typescript.tsx" = "typescriptreact"; + "javascript" = "typescriptreact"; + "typescript" = "typescriptreact"; + "rescript" = "typescriptreact"; + "handlebars" = "glimmer"; + "hbs" = "glimmer"; + "rust" = "rust"; + }; + per_filetype = { }; + }; + }; + }; + }; + + example = { + plugins = { + treesitter.enable = true; + ts-autotag = { + enable = true; + + settings = { + opts = { + enable_close = true; + enable_rename = true; + enable_close_on_slash = false; + }; + per_filetype = { + html = { + enable_close = false; + }; + }; + }; }; }; };