mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-24 05:21:07 +00:00
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) <noreply@anthropic.com>
This commit is contained in:
parent
6cc0bbb960
commit
8796dfc840
1 changed files with 50 additions and 61 deletions
|
|
@ -54,16 +54,9 @@ return {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end,
|
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
|
-- Configure nvim-lspconfig to defer starting jdtls to nvim-jdtls below.
|
||||||
-- defer actually starting it to our configuration of nvim-jtdls below.
|
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
opts = {
|
opts = {
|
||||||
|
|
@ -85,12 +78,10 @@ return {
|
||||||
dependencies = { "folke/which-key.nvim" },
|
dependencies = { "folke/which-key.nvim" },
|
||||||
ft = java_filetypes,
|
ft = java_filetypes,
|
||||||
opts = function()
|
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 {
|
return {
|
||||||
|
-- Path to lombok.jar. Provide this via your nix config.
|
||||||
|
lombok_jar = nil,
|
||||||
|
|
||||||
root_dir = function(path)
|
root_dir = function(path)
|
||||||
return vim.fs.root(path, vim.lsp.config.jdtls.root_markers)
|
return vim.fs.root(path, vim.lsp.config.jdtls.root_markers)
|
||||||
end,
|
end,
|
||||||
|
|
@ -110,12 +101,18 @@ return {
|
||||||
|
|
||||||
-- How to run jdtls. This can be overridden to a full java command-line
|
-- How to run jdtls. This can be overridden to a full java command-line
|
||||||
-- if the Python wrapper script doesn't suffice.
|
-- 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)
|
full_cmd = function(opts)
|
||||||
local fname = vim.api.nvim_buf_get_name(0)
|
local fname = vim.api.nvim_buf_get_name(0)
|
||||||
local root_dir = opts.root_dir(fname)
|
local root_dir = opts.root_dir(fname)
|
||||||
local project_name = opts.project_name(root_dir)
|
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
|
if project_name then
|
||||||
vim.list_extend(cmd, {
|
vim.list_extend(cmd, {
|
||||||
"-configuration",
|
"-configuration",
|
||||||
|
|
@ -146,17 +143,12 @@ return {
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
-- Find the extra bundles that should be passed on the jdtls command-line
|
-- Find the extra bundles that should be passed on the jdtls command-line
|
||||||
-- if nvim-dap is enabled with java debug/test.
|
-- 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[]
|
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
|
-- Allow users to add custom bundles through opts.init_options.bundles
|
||||||
if opts.init_options and opts.init_options.bundles then
|
if opts.init_options and opts.init_options.bundles then
|
||||||
|
|
@ -236,45 +228,42 @@ return {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if LazyVim.has("mason.nvim") then
|
if opts.dap and LazyVim.has("nvim-dap") then
|
||||||
local mason_registry = require("mason-registry")
|
-- custom init for Java debugger
|
||||||
if opts.dap and LazyVim.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
|
require("jdtls").setup_dap(opts.dap)
|
||||||
-- custom init for Java debugger
|
if opts.dap_main then
|
||||||
require("jdtls").setup_dap(opts.dap)
|
require("jdtls.dap").setup_dap_main_class_configs(opts.dap_main)
|
||||||
if opts.dap_main then
|
end
|
||||||
require("jdtls.dap").setup_dap_main_class_configs(opts.dap_main)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Java Test require Java debugger to work
|
-- Java Test require Java debugger to work
|
||||||
if opts.test and mason_registry.is_installed("java-test") then
|
if opts.test then
|
||||||
-- custom keymaps for Java test runner (not yet compatible with neotest)
|
-- custom keymaps for Java test runner (not yet compatible with neotest)
|
||||||
wk.add({
|
wk.add({
|
||||||
|
{
|
||||||
|
mode = "n",
|
||||||
|
buffer = args.buf,
|
||||||
|
{ "<leader>t", group = "test" },
|
||||||
{
|
{
|
||||||
mode = "n",
|
"<leader>tt",
|
||||||
buffer = args.buf,
|
function()
|
||||||
{ "<leader>t", group = "test" },
|
require("jdtls.dap").test_class({
|
||||||
{
|
config_overrides = type(opts.test) ~= "boolean" and opts.test.config_overrides or nil,
|
||||||
"<leader>tt",
|
})
|
||||||
function()
|
end,
|
||||||
require("jdtls.dap").test_class({
|
desc = "Run All Test",
|
||||||
config_overrides = type(opts.test) ~= "boolean" and opts.test.config_overrides or nil,
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
desc = "Run All Test",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"<leader>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",
|
|
||||||
},
|
|
||||||
{ "<leader>tT", require("jdtls.dap").pick_test, desc = "Run Test" },
|
|
||||||
},
|
},
|
||||||
})
|
{
|
||||||
end
|
"<leader>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",
|
||||||
|
},
|
||||||
|
{ "<leader>tT", require("jdtls.dap").pick_test, desc = "Run Test" },
|
||||||
|
},
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue