From cc0aba4e218a17fd81b10d957fcd4b5caaf5572e Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Wed, 15 May 2024 20:55:04 +0200 Subject: [PATCH] languages/ocaml: add formatting support --- modules/plugins/languages/ocaml.nix | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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", + }) + ) + ''; + }) ]); }