mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
fix(java): avoid using mason if not present
This commit is contained in:
parent
a9a273d041
commit
ac1d7bc106
1 changed files with 61 additions and 52 deletions
|
|
@ -85,8 +85,12 @@ return {
|
|||
dependencies = { "folke/which-key.nvim" },
|
||||
ft = java_filetypes,
|
||||
opts = function()
|
||||
local java_agent = ""
|
||||
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"
|
||||
java_agent = string.format("--jvm-arg=-javaagent:%s", lombok_jar)
|
||||
end
|
||||
return {
|
||||
-- How to find the root dir for a given filename. The default comes from
|
||||
-- lspconfig which provides a function specifically for java projects.
|
||||
|
|
@ -109,7 +113,7 @@ return {
|
|||
-- if the Python wrapper script doesn't suffice.
|
||||
cmd = {
|
||||
vim.fn.exepath("jdtls"),
|
||||
string.format("--jvm-arg=-javaagent:%s", lombok_jar),
|
||||
java_agent,
|
||||
},
|
||||
full_cmd = function(opts)
|
||||
local fname = vim.api.nvim_buf_get_name(0)
|
||||
|
|
@ -145,8 +149,9 @@ 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.
|
||||
local mason_registry = require("mason-registry")
|
||||
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
|
||||
local java_dbg_pkg = mason_registry.get_package("java-debug-adapter")
|
||||
local java_dbg_path = java_dbg_pkg:get_install_path()
|
||||
|
|
@ -167,6 +172,7 @@ return {
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function attach_jdtls()
|
||||
local fname = vim.api.nvim_buf_get_name(0)
|
||||
|
|
@ -239,6 +245,8 @@ 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)
|
||||
|
|
@ -275,6 +283,7 @@ return {
|
|||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- User can set additional keymaps in opts.on_attach
|
||||
if opts.on_attach then
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue