From bf17229fce577172c4886ba8f4d6ea22fd0766b1 Mon Sep 17 00:00:00 2001 From: Zapan Date: Thu, 17 Jul 2025 21:01:01 +0800 Subject: [PATCH 1/5] feat(extra): allow users to add custom bundles through opts.init_options.bundles to jdtls --- lua/lazyvim/plugins/extras/lang/java.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/lazyvim/plugins/extras/lang/java.lua b/lua/lazyvim/plugins/extras/lang/java.lua index 8098b6b3..6bcc7802 100644 --- a/lua/lazyvim/plugins/extras/lang/java.lua +++ b/lua/lazyvim/plugins/extras/lang/java.lua @@ -148,6 +148,12 @@ return { -- Find the extra bundles that should be passed on the jdtls command-line -- if nvim-dap is enabled with java debug/test. local bundles = {} ---@type string[] + + -- Allow users to add custom bundles through opts.init_options.bundles + if opts.init_options and opts.init_options.bundles then + vim.list_extend(bundles, opts.init_options.bundles) + end + if LazyVim.has("mason.nvim") then local mason_registry = require("mason-registry") if opts.dap and LazyVim.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then From 2c68ad40ca2d2153462138919fc0643d38373bb8 Mon Sep 17 00:00:00 2001 From: Zapan Date: Tue, 23 Sep 2025 20:58:23 +0800 Subject: [PATCH 2/5] fix(jdtls): allow config jdtls bundles from user's both opts.init_options.bundles and opts.jdtls.init_options.bundles --- lua/lazyvim/plugins/extras/lang/java.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/java.lua b/lua/lazyvim/plugins/extras/lang/java.lua index 3525f910..f05df20b 100644 --- a/lua/lazyvim/plugins/extras/lang/java.lua +++ b/lua/lazyvim/plugins/extras/lang/java.lua @@ -147,12 +147,6 @@ return { -- Find the extra bundles that should be passed on the jdtls command-line -- if nvim-dap is enabled with java debug/test. local bundles = {} ---@type string[] - - -- Allow users to add custom bundles through opts.init_options.bundles - if opts.init_options and opts.init_options.bundles then - vim.list_extend(bundles, opts.init_options.bundles) - end - if LazyVim.has("mason.nvim") then local mason_registry = require("mason-registry") if opts.dap and LazyVim.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then @@ -163,6 +157,16 @@ return { end end end + + -- Allow users to add custom bundles through opts.init_options.bundles and opts.jdtls.bundles + if opts.init_options and opts.init_options.bundles then + vim.list_extend(bundles, opts.init_options.bundles) + end + if opts.jdtls and opts.jdtls.init_options and opts.jdtls.init_options.bundles then + vim.list_extend(bundles, opts.jdtls.init_options.bundles) + opts.jdtls.init_options.bundles = nil + end + local function attach_jdtls() local fname = vim.api.nvim_buf_get_name(0) From 524b89536787f1fe1e15ed975d30df340ac5c332 Mon Sep 17 00:00:00 2001 From: Zapan Date: Tue, 23 Sep 2025 20:58:53 +0800 Subject: [PATCH 3/5] fix(jdtls): allow config jdtls bundles from user's both opts.init_options.bundles and opts.jdtls.init_options.bundles --- lua/lazyvim/plugins/extras/lang/java.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/extras/lang/java.lua b/lua/lazyvim/plugins/extras/lang/java.lua index f05df20b..1c866682 100644 --- a/lua/lazyvim/plugins/extras/lang/java.lua +++ b/lua/lazyvim/plugins/extras/lang/java.lua @@ -158,7 +158,7 @@ return { end end - -- Allow users to add custom bundles through opts.init_options.bundles and opts.jdtls.bundles + -- Allow users to add custom bundles through opts.init_options.bundles and opts.jdtls.init_options.bundles if opts.init_options and opts.init_options.bundles then vim.list_extend(bundles, opts.init_options.bundles) end From c7291614dab6843ec616adb653170c673d69a044 Mon Sep 17 00:00:00 2001 From: Zapan Gao Date: Tue, 16 Dec 2025 16:14:43 +0800 Subject: [PATCH 4/5] Allow users to add custom bundles through opts.init_options.bundles only --- lua/lazyvim/plugins/extras/lang/java.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/java.lua b/lua/lazyvim/plugins/extras/lang/java.lua index 80507476..f4423d7d 100644 --- a/lua/lazyvim/plugins/extras/lang/java.lua +++ b/lua/lazyvim/plugins/extras/lang/java.lua @@ -158,14 +158,10 @@ return { end end - -- Allow users to add custom bundles through opts.init_options.bundles and opts.jdtls.init_options.bundles + -- Allow users to add custom bundles through opts.init_options.bundles if opts.init_options and opts.init_options.bundles then vim.list_extend(bundles, opts.init_options.bundles) end - if opts.jdtls and opts.jdtls.init_options and opts.jdtls.init_options.bundles then - vim.list_extend(bundles, opts.jdtls.init_options.bundles) - opts.jdtls.init_options.bundles = nil - end local function attach_jdtls() local fname = vim.api.nvim_buf_get_name(0) From 8796dfc84084f66ae2bcdcdd4b19404401fdb856 Mon Sep 17 00:00:00 2001 From: Zapan Gao Date: Thu, 18 Jun 2026 22:11:21 +0800 Subject: [PATCH 5/5] refactor(java): remove mason dependency for nixos compatibility - Remove mason auto-install for java-debug-adapter/java-test - Make lombok.jar path configurable via opts.lombok_jar - Support cmd as a function for lazy evaluation - Collect bundles solely from opts.init_options.bundles - Gate dap/test keymaps on opts.dap/opts.test instead of mason Co-Authored-By: Claude Opus 4.8 (1M context) --- lua/lazyvim/plugins/extras/lang/java.lua | 111 ++++++++++------------- 1 file changed, 50 insertions(+), 61 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/java.lua b/lua/lazyvim/plugins/extras/lang/java.lua index f4423d7d..cdd3542e 100644 --- a/lua/lazyvim/plugins/extras/lang/java.lua +++ b/lua/lazyvim/plugins/extras/lang/java.lua @@ -54,16 +54,9 @@ return { }, } end, - dependencies = { - { - "mason-org/mason.nvim", - opts = { ensure_installed = { "java-debug-adapter", "java-test" } }, - }, - }, }, - -- Configure nvim-lspconfig to install the server automatically via mason, but - -- defer actually starting it to our configuration of nvim-jtdls below. + -- Configure nvim-lspconfig to defer starting jdtls to nvim-jdtls below. { "neovim/nvim-lspconfig", opts = { @@ -85,12 +78,10 @@ return { dependencies = { "folke/which-key.nvim" }, ft = java_filetypes, opts = function() - local cmd = { vim.fn.exepath("jdtls") } - if LazyVim.has("mason.nvim") then - local lombok_jar = vim.fn.expand("$MASON/share/jdtls/lombok.jar") - table.insert(cmd, string.format("--jvm-arg=-javaagent:%s", lombok_jar)) - end return { + -- Path to lombok.jar. Provide this via your nix config. + lombok_jar = nil, + root_dir = function(path) return vim.fs.root(path, vim.lsp.config.jdtls.root_markers) end, @@ -110,12 +101,18 @@ return { -- How to run jdtls. This can be overridden to a full java command-line -- if the Python wrapper script doesn't suffice. - cmd = cmd, + cmd = function(opts) + local cmd = { vim.fn.exepath("jdtls") } + if opts.lombok_jar then + table.insert(cmd, string.format("--jvm-arg=-javaagent:%s", opts.lombok_jar)) + end + return cmd + end, full_cmd = function(opts) local fname = vim.api.nvim_buf_get_name(0) local root_dir = opts.root_dir(fname) local project_name = opts.project_name(root_dir) - local cmd = vim.deepcopy(opts.cmd) + local cmd = type(opts.cmd) == "function" and opts.cmd(opts) or vim.deepcopy(opts.cmd) if project_name then vim.list_extend(cmd, { "-configuration", @@ -146,17 +143,12 @@ return { config = function(_, opts) -- Find the extra bundles that should be passed on the jdtls command-line -- if nvim-dap is enabled with java debug/test. + -- + -- In nixos/lazyvim-nix, these bundles must be provided explicitly via + -- opts.init_options.bundles. For reference, the mason equivalents were: + -- - $MASON/share/java-debug-adapter/com.microsoft.java.debug.plugin-*.jar + -- - $MASON/share/java-test/*.jar local bundles = {} ---@type string[] - if LazyVim.has("mason.nvim") then - local mason_registry = require("mason-registry") - if opts.dap and LazyVim.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then - bundles = vim.fn.glob("$MASON/share/java-debug-adapter/com.microsoft.java.debug.plugin-*jar", false, true) - -- java-test also depends on java-debug-adapter. - if opts.test and mason_registry.is_installed("java-test") then - vim.list_extend(bundles, vim.fn.glob("$MASON/share/java-test/*.jar", false, true)) - end - end - end -- Allow users to add custom bundles through opts.init_options.bundles if opts.init_options and opts.init_options.bundles then @@ -236,45 +228,42 @@ return { }, }) - if LazyVim.has("mason.nvim") then - local mason_registry = require("mason-registry") - if opts.dap and LazyVim.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then - -- custom init for Java debugger - require("jdtls").setup_dap(opts.dap) - if opts.dap_main then - require("jdtls.dap").setup_dap_main_class_configs(opts.dap_main) - end + if opts.dap and LazyVim.has("nvim-dap") then + -- custom init for Java debugger + require("jdtls").setup_dap(opts.dap) + if opts.dap_main then + require("jdtls.dap").setup_dap_main_class_configs(opts.dap_main) + end - -- Java Test require Java debugger to work - if opts.test and mason_registry.is_installed("java-test") then - -- custom keymaps for Java test runner (not yet compatible with neotest) - wk.add({ + -- Java Test require Java debugger to work + if opts.test then + -- custom keymaps for Java test runner (not yet compatible with neotest) + wk.add({ + { + mode = "n", + buffer = args.buf, + { "t", group = "test" }, { - mode = "n", - buffer = args.buf, - { "t", group = "test" }, - { - "tt", - function() - require("jdtls.dap").test_class({ - config_overrides = type(opts.test) ~= "boolean" and opts.test.config_overrides or nil, - }) - end, - desc = "Run All Test", - }, - { - "tr", - function() - require("jdtls.dap").test_nearest_method({ - config_overrides = type(opts.test) ~= "boolean" and opts.test.config_overrides or nil, - }) - end, - desc = "Run Nearest Test", - }, - { "tT", require("jdtls.dap").pick_test, desc = "Run Test" }, + "tt", + function() + require("jdtls.dap").test_class({ + config_overrides = type(opts.test) ~= "boolean" and opts.test.config_overrides or nil, + }) + end, + desc = "Run All Test", }, - }) - end + { + "tr", + function() + require("jdtls.dap").test_nearest_method({ + config_overrides = type(opts.test) ~= "boolean" and opts.test.config_overrides or nil, + }) + end, + desc = "Run Nearest Test", + }, + { "tT", require("jdtls.dap").pick_test, desc = "Run Test" }, + }, + }) end end