mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-21 16:39:06 +02:00
fix(java): only use mason-registry if mason installed (#4991)
## Description The current config breaks when mason is not installed (e.g. for Nix users). This PR makes the mason-related functionality (which, as of now, consists only of finding `lombok`) dependent on mason being installed. As noted in the commit, this does make it impossible to use lombok without mason, but I'm unaware of any other method of finding it (which is why mason-registry was used in the first place, I assume) Please note that I'm not very experienced with Lua and the code might be not the most idiomatic one. ## Related Issue(s) <!-- If this PR fixes any issues, please link to the issue here. - Fixes #<issue_number> --> ## Screenshots <!-- Add screenshots of the changes if applicable. --> ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
parent
8b8e322b68
commit
21b02f056d
1 changed files with 7 additions and 6 deletions
|
@ -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 cmd = { vim.fn.exepath("jdtls") }
|
||||||
|
if LazyVim.has("mason.nvim") then
|
||||||
local mason_registry = require("mason-registry")
|
local mason_registry = require("mason-registry")
|
||||||
local lombok_jar = mason_registry.get_package("jdtls"):get_install_path() .. "/lombok.jar"
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue