Compare commits

..

No commits in common. "7224c1e6afd23535f8607d292c6d9c70699f752e" and "cc0aba4e218a17fd81b10d957fcd4b5caaf5572e" have entirely different histories.

2 changed files with 23 additions and 52 deletions

View file

@ -73,7 +73,6 @@ inputs: let
go.enable = isMaximal; go.enable = isMaximal;
elixir.enable = isMaximal; elixir.enable = isMaximal;
zig.enable = isMaximal; zig.enable = isMaximal;
ocaml.enable = isMaximal;
python.enable = isMaximal; python.enable = isMaximal;
dart.enable = isMaximal; dart.enable = isMaximal;
bash.enable = isMaximal; bash.enable = isMaximal;

View file

@ -4,49 +4,15 @@
lib, lib,
... ...
}: let }: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe; inherit (lib.meta) getExe;
inherit (lib.lists) isList; inherit (lib.lists) isList;
inherit (lib.types) either enum listOf package str; inherit (lib.types) either listOf package str;
inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) expToLua; inherit (lib.nvim.lua) expToLua;
cfg = config.vim.languages.ocaml; cfg = config.vim.languages.ocaml;
defaultServer = "ocaml-lsp";
servers = {
ocaml-lsp = {
package = pkgs.ocamlPackages.ocaml-lsp;
lspConfig = ''
lspconfig.ocamllsp.setup {
capabilities = capabilities,
on_attach = default_on_attach,
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${getExe cfg.lsp.package}"}''
};
}
'';
};
};
defaultFormat = "ocamlformat";
formats = {
ocamlformat = {
package = pkgs.ocamlPackages.ocamlformat;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.ocamlformat.with({
command = "${cfg.format.package}/bin/ocamlformat",
})
)
'';
};
};
in { in {
options.vim.languages.ocaml = { options.vim.languages.ocaml = {
enable = mkEnableOption "OCaml language support"; enable = mkEnableOption "OCaml language support";
@ -58,29 +24,19 @@ in {
lsp = { lsp = {
enable = mkEnableOption "OCaml LSP support (ocaml-lsp)" // {default = config.vim.languages.enableLSP;}; enable = mkEnableOption "OCaml LSP support (ocaml-lsp)" // {default = config.vim.languages.enableLSP;};
server = mkOption {
description = "OCaml LSP server to user";
type = enum (attrNames servers);
default = defaultServer;
};
package = mkOption { package = mkOption {
description = "OCaml language server package, or the command to run as a list of strings"; description = "ocaml language server package, or the command to run as a list of strings";
type = either package (listOf str); type = either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = pkgs.ocamlPackages.ocaml-lsp;
}; };
}; };
format = { format = {
enable = mkEnableOption "OCaml formatting support (ocamlformat)" // {default = config.vim.languages.enableFormat;}; enable = mkEnableOption "OCaml formatting support (ocamlformat)" // {default = config.vim.languages.enableFormat;};
type = mkOption {
description = "OCaml formatter to use";
type = enum (attrNames formats);
default = defaultFormat;
};
package = mkOption { package = mkOption {
description = "OCaml formatter package"; description = "OCaml formatter package";
type = package; type = package;
default = formats.${cfg.format.type}.package; default = pkgs.ocamlPackages.ocamlformat;
}; };
}; };
}; };
@ -88,7 +44,17 @@ in {
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [
(mkIf cfg.lsp.enable { (mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.ocaml-lsp = servers.${cfg.lsp.server}.lspConfig; vim.lsp.lspconfig.sources.ocaml-lsp = ''
lspconfig.ocamllsp.setup {
capabilities = capabilities,
on_attach = default_on_attach,
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${getExe cfg.lsp.package}"}''
};
}
'';
}) })
(mkIf cfg.treesitter.enable { (mkIf cfg.treesitter.enable {
@ -98,8 +64,14 @@ in {
(mkIf cfg.format.enable { (mkIf cfg.format.enable {
vim.lsp.null-ls.enable = true; vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources.ocamlformat = formats.${cfg.format.type}.nullConfig; vim.lsp.null-ls.sources.ocamlformat = ''
vim.extraPackages = [formats.${cfg.format.type}.package]; table.insert(
ls_sources,
null_ls.builtins.formatting.ocamlformat.with({
command = "${cfg.format.package}/bin/ocamlformat",
})
)
'';
}) })
]); ]);
} }