neovim-flake/modules/plugins/languages/java.nix

58 lines
1.7 KiB
Nix
Raw Normal View History

2023-08-09 06:41:48 +02:00
{
config,
pkgs,
2023-08-09 06:41:48 +02:00
lib,
...
}: let
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.lists) isList;
inherit (lib.types) either listOf package str;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) expToLua;
2023-08-09 06:41:48 +02:00
cfg = config.vim.languages.java;
in {
options.vim.languages.java = {
enable = mkEnableOption "Java language support";
treesitter = {
enable = mkEnableOption "Java treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "java";
2023-08-09 06:41:48 +02:00
};
lsp = {
enable = mkEnableOption "Java LSP support (java-language-server)" // {default = config.vim.languages.enableLSP;};
package = mkOption {
description = "java language server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = either package (listOf str);
2023-08-09 06:41:48 +02:00
default = pkgs.jdt-language-server;
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.jdtls = ''
lspconfig.jdtls.setup {
2023-09-15 00:20:55 +02:00
capabilities = capabilities,
on_attach = default_on_attach,
2023-09-15 00:17:12 +02:00
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${getExe cfg.lsp.package}", "-data", vim.fn.stdpath("cache").."/jdtls/workspace"}''
2023-09-15 00:17:12 +02:00
},
2023-08-09 06:41:48 +02:00
}
'';
})
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
]);
}