languages/ocaml: add formatting support

This commit is contained in:
jacekpoz 2024-05-15 20:55:04 +02:00
parent db810bbf9f
commit cc0aba4e21
No known key found for this signature in database

View file

@ -30,6 +30,15 @@ in {
default = pkgs.ocamlPackages.ocaml-lsp; default = pkgs.ocamlPackages.ocaml-lsp;
}; };
}; };
format = {
enable = mkEnableOption "OCaml formatting support (ocamlformat)" // {default = config.vim.languages.enableFormat;};
package = mkOption {
description = "OCaml formatter package";
type = package;
default = pkgs.ocamlPackages.ocamlformat;
};
};
}; };
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [
@ -52,5 +61,17 @@ in {
vim.treesitter.enable = true; vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package]; vim.treesitter.grammars = [cfg.treesitter.package];
}) })
(mkIf cfg.format.enable {
vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources.ocamlformat = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.ocamlformat.with({
command = "${cfg.format.package}/bin/ocamlformat",
})
)
'';
})
]); ]);
} }