From 960e9588684467f93cf35e6f69ced9ab62dfcc61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Wed, 20 Jul 2022 13:01:06 +0100 Subject: [PATCH] add jdtls maybe --- config/programs/vim/default.nix | 19 ++++++++++++++++ config/programs/vim/nvim-jdtls.lua | 36 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 config/programs/vim/nvim-jdtls.lua diff --git a/config/programs/vim/default.nix b/config/programs/vim/default.nix index 3f6e6d83..cd06330a 100644 --- a/config/programs/vim/default.nix +++ b/config/programs/vim/default.nix @@ -1,5 +1,20 @@ {pkgs, ...}: let dsquotes = "''"; + nvim-jdtls = pkgs.stdenvNoCC.mkDerivation rec { + name = "nvim-jdtls.lua"; + src = ./nvim-jdtls.lua; + dontUnpack = true; + java = pkgs.openjdk; + jdtLanguageServer = pkgs.jdt-language-server; + buildInputs = [java jdtLanguageServer]; + buildPhase = '' + export launcher="$(ls $jdtLanguageServer/share/java/plugins/org.eclipse.equinox.launcher_* | sort -V | tail -n1)" + substituteAll $src nvim-jdtls.lua + ''; + installPhase = '' + cp nvim-jdtls.lua $out + ''; + }; in { programs.neovim = { enable = true; @@ -65,6 +80,10 @@ in { plugin = rust-tools-nvim; config = "lua dofile(\"${./rust-tools.lua}\")"; } + { + plugin = nvim-jdtls; + config = "lua dofile(\"${nvim-jdtls}\")"; + } nvim-dap ]; }; diff --git a/config/programs/vim/nvim-jdtls.lua b/config/programs/vim/nvim-jdtls.lua new file mode 100644 index 00000000..856fe20b --- /dev/null +++ b/config/programs/vim/nvim-jdtls.lua @@ -0,0 +1,36 @@ +vim.api.nvim_create_autocmd({"FileType"}, { + pattern = {"java"}, + callback = function() + local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t') + local workspace_dir = '@userhome@/.cache/jdtls/' .. project_name + + local config = { + cmd = { + '@java@', + '-Declipse.application=org.eclipse.jdt.ls.core.id1', + '-Dosgi.bundles.defaultStartLevel=4', + '-Declipse.product=org.eclipse.jdt.ls.core.product', + '-Dlog.protocol=true', + '-Dlog.level=ALL', + '-Xms1g', + '--add-modules=ALL-SYSTEM', + '--add-opens', 'java.base/java.util=ALL-UNNAMED', + '--add-opens', 'java.base/java.lang=ALL-UNNAMED', + '-jar', '@launcher@', + '-configuration', '@jdtLanguageServer@/share/config', + '-data', workspace_dir, + } + + root_dir = require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'}), + settings = { + java = { + } + }, + init_options = { + bundles = {} + }, + }; + + require('jdtls').start_or_attach(config) + end +})