wrap jdtls config in function for dynamic workspace

This commit is contained in:
Baipyrus 2024-07-28 22:19:32 +02:00
parent d9eca6205a
commit 9373dd686a

View File

@ -200,9 +200,8 @@ return {
}
local function jdtls_setup()
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')
-- calculate workspace dir
local workspace_dir = vim.fn.stdpath 'data' .. '/site/java/workspace-root/' .. project_name
--- @param workspace_dir string
local function generate_config(workspace_dir)
-- get the mason install path
local install_path = require('mason-registry').get_package('jdtls'):get_install_path()
local jdtls_path = vim.fn.glob(install_path .. '/plugins/org.eclipse.equinox.launcher_*.jar')
@ -262,10 +261,15 @@ return {
bundles = {},
},
}
return config
end
vim.api.nvim_create_autocmd('FileType', {
pattern = 'java',
callback = function()
require('jdtls').start_or_attach(config)
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')
-- calculate workspace dir
local workspace_dir = vim.fn.stdpath 'data' .. '/site/java/workspace-root/' .. project_name
require('jdtls').start_or_attach(generate_config(workspace_dir))
end,
})
end