Skip to content

Commit

Permalink
plugins/ts-autotag: switch to mkNeovimPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jun 17, 2024
1 parent 7087b60 commit b822078
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 98 deletions.
143 changes: 84 additions & 59 deletions plugins/languages/treesitter/ts-autotag.nix
Original file line number Diff line number Diff line change
@@ -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.";
"filetypes"
"skipTags"
];

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.";
extraConfig = cfg: {
warnings = mkIf (!config.plugins.treesitter.enable) [
"Nixvim: ts-autotag needs treesitter to function as intended"
];
};

config =
settingsOptions =
let
cfg = config.plugins.ts-autotag;
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
mkIf cfg.enable {
warnings = mkIf (!config.plugins.treesitter.enable) [
"Nixvim: ts-autotag needs treesitter to function as intended"
];
{
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.";

extraPlugins = [ cfg.package ];
per_filetype = helpers.defaultNullOpts.mkAttrsOf (types.submodule {
freeformType = with types; attrsOf anything;
options = opts;
}) { } "Per filetype config overrides.";
};

plugins.treesitter.moduleConfig.autotag = {
enable = true;
inherit (cfg) filetypes;
skip_tags = cfg.skipTags;
} // cfg.extraOptions;
settingsExample = {
opts = {
enable_close = true;
enable_rename = true;
enable_close_on_slash = false;
};
per_filetype = {
html = {
enable_close = false;
};
};
};
}
89 changes: 50 additions & 39 deletions tests/test-sources/plugins/languages/treesitter/ts-autotag.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
};
};
};
Expand Down

0 comments on commit b822078

Please sign in to comment.