Skip to content

Commit b822078

Browse files
committed
plugins/ts-autotag: switch to mkNeovimPlugin
1 parent 7087b60 commit b822078

File tree

2 files changed

+134
-98
lines changed

2 files changed

+134
-98
lines changed
Lines changed: 84 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,103 @@
11
{
2-
pkgs,
32
lib,
43
helpers,
54
config,
5+
pkgs,
66
...
77
}:
88
with lib;
9-
{
10-
options.plugins.ts-autotag = helpers.neovim-plugin.extraOptionsOptions // {
11-
enable = mkEnableOption "nvim-ts-autotag";
9+
helpers.neovim-plugin.mkNeovimPlugin config {
10+
name = "ts-autotag";
11+
originalName = "nvim-ts-autotag";
12+
luaName = "nvim-ts-autotag";
13+
defaultPackage = pkgs.vimPlugins.nvim-ts-autotag;
1214

13-
package = helpers.mkPluginPackageOption "ts-autotag" pkgs.vimPlugins.nvim-ts-autotag;
15+
maintainers = [ maintainers.GaetanLepage ];
1416

15-
filetypes = helpers.defaultNullOpts.mkNullable (with types; listOf str) ''
17+
# TODO introduced 2024-06-17: remove 2024-08-17
18+
deprecateExtraOptions = true;
19+
imports =
20+
map
21+
(
22+
optionName:
23+
mkRemovedOptionModule
24+
[
25+
"plugins"
26+
"ts-autotag"
27+
optionName
28+
]
29+
''
30+
The `ts-autotag` plugin is no longer configured using `nvim-treesitter.configs`.
31+
Please, refer to upstream documentation:
32+
https://github.com/windwp/nvim-ts-autotag#setup
33+
''
34+
)
1635
[
17-
"html"
18-
"javascript"
19-
"typescript"
20-
"javascriptreact"
21-
"typescriptreact"
22-
"svelte"
23-
"vue"
24-
"tsx"
25-
"jsx"
26-
"rescript"
27-
"xml"
28-
"php"
29-
"markdown"
30-
"astro"
31-
"glimmer"
32-
"handlebars"
33-
"hbs"
34-
]
35-
'' "Filetypes for which ts-autotag should be enabled.";
36+
"filetypes"
37+
"skipTags"
38+
];
3639

37-
skipTags = helpers.defaultNullOpts.mkNullable (with types; listOf str) ''
38-
[
39-
"area"
40-
"base"
41-
"br"
42-
"col"
43-
"command"
44-
"embed"
45-
"hr"
46-
"img"
47-
"slot"
48-
"input"
49-
"keygen"
50-
"link"
51-
"meta"
52-
"param"
53-
"source"
54-
"track"
55-
"wbr"
56-
"menuitem"
57-
]
58-
'' "Which tags to skip.";
40+
extraConfig = cfg: {
41+
warnings = mkIf (!config.plugins.treesitter.enable) [
42+
"Nixvim: ts-autotag needs treesitter to function as intended"
43+
];
5944
};
6045

61-
config =
46+
settingsOptions =
6247
let
63-
cfg = config.plugins.ts-autotag;
48+
opts = {
49+
enable_close = helpers.defaultNullOpts.mkBool true ''
50+
Whether or not to auto close tags.
51+
'';
52+
53+
enable_rename = helpers.defaultNullOpts.mkBool true ''
54+
Whether or not to auto rename paired tags.
55+
'';
56+
57+
enable_close_on_slash = helpers.defaultNullOpts.mkBool true ''
58+
Whether or not to auto close tags when a `/` is inserted.
59+
'';
60+
};
6461
in
65-
mkIf cfg.enable {
66-
warnings = mkIf (!config.plugins.treesitter.enable) [
67-
"Nixvim: ts-autotag needs treesitter to function as intended"
68-
];
62+
{
63+
inherit opts;
64+
65+
aliases = helpers.defaultNullOpts.mkAttrsOf types.str {
66+
"astro" = "html";
67+
"eruby" = "html";
68+
"vue" = "html";
69+
"htmldjango" = "html";
70+
"markdown" = "html";
71+
"php" = "html";
72+
"twig" = "html";
73+
"blade" = "html";
74+
"javascriptreact" = "typescriptreact";
75+
"javascript.jsx" = "typescriptreact";
76+
"typescript.tsx" = "typescriptreact";
77+
"javascript" = "typescriptreact";
78+
"typescript" = "typescriptreact";
79+
"rescript" = "typescriptreact";
80+
"handlebars" = "glimmer";
81+
"hbs" = "glimmer";
82+
"rust" = "rust";
83+
} "Filetype aliases.";
6984

70-
extraPlugins = [ cfg.package ];
85+
per_filetype = helpers.defaultNullOpts.mkAttrsOf (types.submodule {
86+
freeformType = with types; attrsOf anything;
87+
options = opts;
88+
}) { } "Per filetype config overrides.";
89+
};
7190

72-
plugins.treesitter.moduleConfig.autotag = {
73-
enable = true;
74-
inherit (cfg) filetypes;
75-
skip_tags = cfg.skipTags;
76-
} // cfg.extraOptions;
91+
settingsExample = {
92+
opts = {
93+
enable_close = true;
94+
enable_rename = true;
95+
enable_close_on_slash = false;
96+
};
97+
per_filetype = {
98+
html = {
99+
enable_close = false;
100+
};
77101
};
102+
};
78103
}

tests/test-sources/plugins/languages/treesitter/ts-autotag.nix

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,56 @@
1111
treesitter.enable = true;
1212
ts-autotag = {
1313
enable = true;
14-
filetypes = [
15-
"html"
16-
"javascript"
17-
"typescript"
18-
"javascriptreact"
19-
"typescriptreact"
20-
"svelte"
21-
"vue"
22-
"tsx"
23-
"jsx"
24-
"rescript"
25-
"xml"
26-
"php"
27-
"markdown"
28-
"astro"
29-
"glimmer"
30-
"handlebars"
31-
"hbs"
32-
];
33-
skipTags = [
34-
"area"
35-
"base"
36-
"br"
37-
"col"
38-
"command"
39-
"embed"
40-
"hr"
41-
"img"
42-
"slot"
43-
"input"
44-
"keygen"
45-
"link"
46-
"meta"
47-
"param"
48-
"source"
49-
"track"
50-
"wbr"
51-
"menuitem"
52-
];
14+
15+
settings = {
16+
opts = {
17+
enable_close = true;
18+
enable_rename = true;
19+
enable_close_on_slash = true;
20+
};
21+
aliases = {
22+
"astro" = "html";
23+
"eruby" = "html";
24+
"vue" = "html";
25+
"htmldjango" = "html";
26+
"markdown" = "html";
27+
"php" = "html";
28+
"twig" = "html";
29+
"blade" = "html";
30+
"javascriptreact" = "typescriptreact";
31+
"javascript.jsx" = "typescriptreact";
32+
"typescript.tsx" = "typescriptreact";
33+
"javascript" = "typescriptreact";
34+
"typescript" = "typescriptreact";
35+
"rescript" = "typescriptreact";
36+
"handlebars" = "glimmer";
37+
"hbs" = "glimmer";
38+
"rust" = "rust";
39+
};
40+
per_filetype = { };
41+
};
42+
};
43+
};
44+
};
45+
46+
example = {
47+
plugins = {
48+
treesitter.enable = true;
49+
ts-autotag = {
50+
enable = true;
51+
52+
settings = {
53+
opts = {
54+
enable_close = true;
55+
enable_rename = true;
56+
enable_close_on_slash = false;
57+
};
58+
per_filetype = {
59+
html = {
60+
enable_close = false;
61+
};
62+
};
63+
};
5364
};
5465
};
5566
};

0 commit comments

Comments
 (0)