diff --git a/modules/plugins/languages/ocaml.nix b/modules/plugins/languages/ocaml.nix index c6ff5a5..1817cc4 100644 --- a/modules/plugins/languages/ocaml.nix +++ b/modules/plugins/languages/ocaml.nix @@ -30,6 +30,15 @@ in { 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 [ @@ -52,5 +61,17 @@ in { vim.treesitter.enable = true; 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", + }) + ) + ''; + }) ]); }