From df25456aaae76b265c01bc2629b14f5f90c9d37a Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Thu, 1 Jun 2023 10:31:35 +0200 Subject: [PATCH] plugins/ts-autotag: init + test --- plugins/default.nix | 1 + plugins/languages/treesitter/ts-autotag.nix | 89 +++++++++++++++++++ .../languages/treesitter/ts-autotag.nix | 56 ++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 plugins/languages/treesitter/ts-autotag.nix create mode 100644 tests/test-sources/plugins/languages/treesitter/ts-autotag.nix diff --git a/plugins/default.nix b/plugins/default.nix index 5d9b90d6..3ad6c442 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -43,6 +43,7 @@ ./languages/treesitter/treesitter-playground.nix ./languages/treesitter/treesitter-rainbow.nix ./languages/treesitter/treesitter-refactor.nix + ./languages/treesitter/ts-autotag.nix ./languages/typst/typst-vim.nix ./languages/vimtex.nix ./languages/zig.nix diff --git a/plugins/languages/treesitter/ts-autotag.nix b/plugins/languages/treesitter/ts-autotag.nix new file mode 100644 index 00000000..0329576f --- /dev/null +++ b/plugins/languages/treesitter/ts-autotag.nix @@ -0,0 +1,89 @@ +{ + pkgs, + lib, + config, + ... +}: +with lib; let + helpers = import ../../helpers.nix {inherit lib;}; +in { + options.plugins.ts-autotag = + helpers.extraOptionsOptions + // { + enable = mkEnableOption "nvim-ts-autotag"; + + package = helpers.mkPackageOption "ts-autotag" pkgs.vimPlugins.nvim-ts-autotag; + + filetypes = + helpers.defaultNullOpts.mkNullable + (with types; listOf str) + '' + [ + "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" + ]; + + extraPlugins = [cfg.package]; + + plugins.treesitter.moduleConfig.autotag = + { + enable = true; + inherit (cfg) filetypes; + skip_tags = cfg.skipTags; + } + // cfg.extraOptions; + }; +} diff --git a/tests/test-sources/plugins/languages/treesitter/ts-autotag.nix b/tests/test-sources/plugins/languages/treesitter/ts-autotag.nix new file mode 100644 index 00000000..f50fdce5 --- /dev/null +++ b/tests/test-sources/plugins/languages/treesitter/ts-autotag.nix @@ -0,0 +1,56 @@ +{ + empty = { + plugins = { + treesitter.enable = true; + ts-autotag.enable = true; + }; + }; + + default = { + plugins = { + 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" + ]; + }; + }; + }; +}