From 36585be18c6a4348f6e0a0529e1ef16ec38e8152 Mon Sep 17 00:00:00 2001 From: Jannik Donker Date: Sun, 2 Nov 2025 20:37:33 +0100 Subject: [PATCH] added better jdtls config --- init.lua | 96 +++++++++++++++++++++++++++++++++++++++++++-- nvim-pack-lock.json | 4 ++ 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index a67d632..fe12293 100644 --- a/init.lua +++ b/init.lua @@ -63,8 +63,9 @@ require("autoclose").setup() -- LSP START -- -vim.lsp.enable({ "lua_ls", "ts_ls", "svelte", "tailwindcss", "cssls", "bashls", "rust_analyzer", "clangd", "clang-format", "taplo", - "sourcekit", "lemminx", "tinymist", "jdtls", "jsonls" }) +vim.lsp.enable({ "lua_ls", "ts_ls", "svelte", "tailwindcss", "cssls", "bashls", "rust_analyzer", "clangd", "clang-format", + "taplo", + "sourcekit", "lemminx", "tinymist", "jsonls" }) vim.lsp.config["tinymist"] = { cmd = { "tinymist" }, @@ -78,11 +79,100 @@ vim.lsp.config("jdtls", { root_dir = vim.fn.getcwd(), settings = { java = { - -- Custom eclipse.jdt.ls options go here }, }, }) +vim.api.nvim_create_autocmd('FileType', { + pattern = 'java', + callback = function(args) + local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") + local workspace_dir = vim.fn.stdpath("data") .. + package.config:sub(1, 1) .. "jdtls-workspace" .. package.config:sub(1, 1) .. project_name + local os_name = vim.loop.os_uname().sysname + local config = { + -- The command that starts the language server + -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line + cmd = { + + -- 💀 + "java", -- or '/path/to/java17_or_newer/bin/java' + -- depends on if `java` is in your $PATH env variable and if it points to the right version. + + "-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", + "-Xmx1g", + "--add-modules=ALL-SYSTEM", + "--add-opens", + "java.base/java.util=ALL-UNNAMED", + "--add-opens", + "java.base/java.lang=ALL-UNNAMED", + + -- 💀 + "-jar", + vim.fn.stdpath("data") .. + package.config:sub(1, 1) .. + "mason" .. + package.config:sub(1, 1) .. + "packages" .. + package.config:sub(1, 1) .. + "jdtls" .. + package.config:sub(1, 1) .. + "plugins" .. package.config:sub(1, 1) .. "org.eclipse.equinox.launcher_1.7.100.v20251014-1222.jar", + -- Must point to the Change this to + -- eclipse.jdt.ls installation the actual version + + -- 💀 + "-configuration", + vim.fn.stdpath("data") .. + package.config:sub(1, 1) .. + "mason" .. + package.config:sub(1, 1) .. + "packages" .. + package.config:sub(1, 1) .. + "jdtls" .. + package.config:sub(1, 1) .. + "config_" .. (os_name == "Windows_NT" and "win" or os_name == "Linux" and "linux" or "mac"), + -- eclipse.jdt.ls installation Depending on your system. + + -- 💀 + -- See `data directory configuration` section in the README + "-data", + workspace_dir, + }, + + -- 💀 + -- This is the default if not provided, you can remove it. Or adjust as needed. + -- One dedicated LSP server & client will be started per unique root_dir + root_dir = require("jdtls.setup").find_root({ ".git", "mvnw", "gradlew" }), + + -- Here you can configure eclipse.jdt.ls specific settings + -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request + -- for a list of options + settings = { + java = {}, + }, + + -- Language server `initializationOptions` + -- You need to extend the `bundles` with paths to jar files + -- if you want to use additional eclipse.jdt.ls plugins. + -- + -- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation + -- + -- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this + init_options = { + bundles = {}, + }, + } + -- This starts a new client & server, + -- or attaches to an existing client & server depending on the `root_dir`. + require("jdtls").start_or_attach(config) + end +}) + -- LSP END -- -- KEYMAP START -- diff --git a/nvim-pack-lock.json b/nvim-pack-lock.json index df079f0..8dea1b1 100644 --- a/nvim-pack-lock.json +++ b/nvim-pack-lock.json @@ -1,5 +1,9 @@ { "plugins": { + "autoclose.nvim": { + "rev": "3f86702", + "src": "https://github.com/m4xshen/autoclose.nvim" + }, "blink.cmp": { "version": "'v1.6.0'" },