blob: 29a18551422f8fd3c611ac976597873ffda2adb5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
{
config,
pkgs,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.types) enum listOf;
inherit (lib.attrsets) genAttrs;
inherit (lib.nvim.types) mkGrammarOption;
cfg = config.vim.languages.json5;
defaultFormat = ["prettier"];
formats = ["prettier" "injected"];
in {
options.vim.languages.json5 = {
enable = mkEnableOption "JSON5 language support";
treesitter = {
enable =
mkEnableOption "JSON5 treesitter"
// {
default = config.vim.languages.enableTreesitter;
defaultText = literalExpression "config.vim.languages.enableTreesitter";
};
package = mkGrammarOption pkgs "json5";
};
format = {
enable =
mkEnableOption "JSON5 formatting"
// {
default = config.vim.languages.enableFormat;
defaultText = literalExpression "config.vim.languages.enableFormat";
};
type = mkOption {
description = "JSON5 formatter to use";
type = listOf (enum formats);
default = defaultFormat;
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter = {
enable = true;
grammars = [cfg.treesitter.package];
};
})
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
presets = genAttrs cfg.format.type (_: {enable = true;});
setupOpts.formatters_by_ft = {json5 = cfg.format.type;};
};
})
]);
}
|