languages/ocaml: refactor lsp.servers to use lsp/presets/<name>

This commit is contained in:
Snoweuph 2026-04-11 18:15:09 +02:00
commit cf981331a3
No known key found for this signature in database
GPG key ID: BEFC41DA223CEC55

View file

@ -7,53 +7,16 @@
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption literalExpression;
inherit (lib.modules) mkIf mkMerge;
inherit (lib) genAttrs;
inherit (lib.meta) getExe;
inherit (lib.types) enum;
inherit (lib.types) enum listOf;
inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.ocaml;
defaultServers = ["ocaml-lsp"];
servers = {
ocaml-lsp = {
enable = true;
cmd = [(getExe pkgs.ocamlPackages.ocaml-lsp)];
filetypes = ["ocaml" "menhir" "ocamlinterface" "ocamllex" "reason" "dune"];
root_dir =
mkLuaInline
/*
lua
*/
''
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
/*
lua
*/
''
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
'';
};
};
servers = ["ocaml-lsp"];
defaultFormat = ["ocamlformat"];
formats = {
@ -84,7 +47,7 @@ in {
};
servers = mkOption {
type = deprecatedSingleOrListOf "vim.language.ocaml.lsp.servers" (enum (attrNames servers));
type = listOf (enum servers);
default = defaultServers;
description = "OCaml LSP server to use";
};
@ -102,12 +65,12 @@ in {
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.lsp.enable {
vim.lsp.servers =
mapListToAttrs (n: {
name = n;
value = servers.${n};
})
cfg.lsp.servers;
vim.lsp = {
presets = genAttrs cfg.lsp.servers (_: {enable = true;});
servers = genAttrs cfg.lsp.servers (_: {
filetypes = ["ocaml" "menhir" "ocamlinterface" "ocamllex" "reason" "dune"];
});
};
})
(mkIf cfg.treesitter.enable {