nixos-configs/homeManagerModules/neovim/langs/java/default.nix

89 lines
2.3 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}: let
2024-12-16 17:44:17 -05:00
inherit (lib) attrValues getExe mkIf;
cfg = config.programs.neovim;
javaSdk = pkgs.temurin-bin-17;
2024-12-16 17:44:17 -05:00
javaPkgs = attrValues {inherit (pkgs) gradle maven;};
in {
config = mkIf cfg.enable {
home.packages = javaPkgs;
xdg.dataFile.".gradle/gradle.properties".text = ''
org.gradle.java.home = ${javaSdk}
'';
programs = {
java = {
enable = true;
package = javaSdk;
};
neovim = {
extraPackages = javaPkgs;
extraLuaConfig =
2024-06-09 22:49:30 -04:00
# lua
''
vim.api.nvim_create_autocmd('FileType', {
pattern = 'java',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
'';
plugins = [
2024-05-11 19:27:26 -04:00
{
# TOOD: setup debugger https://github.com/mfussenegger/nvim-jdtls#debugger-via-nvim-dap
plugin = pkgs.vimPlugins.nvim-jdtls;
2024-05-11 19:27:26 -04:00
type = "lua";
config =
2024-06-09 22:49:30 -04:00
# lua
2024-05-11 19:27:26 -04:00
''
2024-06-09 22:49:30 -04:00
--
2024-05-11 19:27:26 -04:00
local startJdtls = function()
local config = {
capabilities = require('cmp_nvim_lsp').default_capabilities(),
cmd = { '${getExe pkgs.jdt-language-server}' },
2024-05-11 19:27:26 -04:00
root_dir = vim.fs.dirname(vim.fs.find(
{ 'gradlew', '.git', 'mvnw', 'pom.xml' },
{ upward = true }
)[1]),
settings = {
java = {
configuration = {
runtimes = {
{
name = 'JavaSE-17',
path = '${javaSdk}',
},
},
},
},
},
};
2024-05-11 19:27:26 -04:00
require('jdtls').start_or_attach(config);
end
vim.api.nvim_create_autocmd('FileType', {
pattern = 'java',
callback = startJdtls,
});
'';
}
];
};
};
};
# For accurate stack trace
_file = ./default.nix;
}