fix(java): only use mason-registry if mason installed

this does make it impossible to use lombok without mason
This commit is contained in:
Ughur Alakbarov 2024-12-11 12:10:44 +01:00
parent 8c79ab601a
commit 8fa1962866

View file

@ -85,8 +85,12 @@ return {
dependencies = { "folke/which-key.nvim" }, dependencies = { "folke/which-key.nvim" },
ft = java_filetypes, ft = java_filetypes,
opts = function() opts = function()
local mason_registry = require("mason-registry") local cmd = { vim.fn.exepath("jdtls") }
local lombok_jar = mason_registry.get_package("jdtls"):get_install_path() .. "/lombok.jar" if LazyVim.has("mason.nvim") then
local mason_registry = require("mason-registry")
local lombok_jar = mason_registry.get_package("jdtls"):get_install_path() .. "/lombok.jar"
table.insert(cmd, string.format("--jvm-arg=-javaagent:%s", lombok_jar))
end
return { return {
-- How to find the root dir for a given filename. The default comes from -- How to find the root dir for a given filename. The default comes from
-- lspconfig which provides a function specifically for java projects. -- lspconfig which provides a function specifically for java projects.
@ -107,10 +111,7 @@ 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,
vim.fn.exepath("jdtls"),
string.format("--jvm-arg=-javaagent:%s", lombok_jar),
},
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)