From 16753bfc5205a11d2e1bc29aee5ba570571845e7 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sat, 11 Apr 2026 18:03:08 +0200 Subject: [PATCH] lsp/presets/ocaml-lsp: init --- modules/plugins/lsp/presets/default.nix | 1 + modules/plugins/lsp/presets/ocaml-lsp.nix | 44 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 modules/plugins/lsp/presets/ocaml-lsp.nix diff --git a/modules/plugins/lsp/presets/default.nix b/modules/plugins/lsp/presets/default.nix index 1a497b49..714c39b5 100644 --- a/modules/plugins/lsp/presets/default.nix +++ b/modules/plugins/lsp/presets/default.nix @@ -5,6 +5,7 @@ ./harper.nix ./intelephense.nix ./lemminx.nix + ./ocaml-lsp.nix ./ols.nix ./openscad-lsp.nix ./phan.nix diff --git a/modules/plugins/lsp/presets/ocaml-lsp.nix b/modules/plugins/lsp/presets/ocaml-lsp.nix new file mode 100644 index 00000000..0e9b0952 --- /dev/null +++ b/modules/plugins/lsp/presets/ocaml-lsp.nix @@ -0,0 +1,44 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.options) mkEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.ocaml-lsp; +in { + options.vim.lsp.presets.ocaml-lsp = { + enable = mkEnableOption "the OCaml Language Server"; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.ocaml-lsp = { + enable = true; + cmd = [(getExe pkgs.ocamlPackages.ocaml-lsp)]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + on_dir(util.root_pattern('*.opam', 'esy.json', 'package.json', '.git', 'dune-project', 'dune-workspace')(fname)) + end + ''; + get_language_id = mkLuaInline '' + function(_, ftype) + local language_id_of = { + menhir = 'ocaml.menhir', + ocaml = 'ocaml', + ocamlinterface = 'ocaml.interface', + ocamllex = 'ocaml.ocamllex', + reason = 'reason', + dune = 'dune', + } + + return language_id_of[ftype] + end + ''; + }; + }; +}