mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
fix: PR#1300
This commit is contained in:
parent
69f5a30af8
commit
ebc5375401
1 changed files with 23 additions and 25 deletions
|
|
@ -44,7 +44,6 @@ return {
|
||||||
{
|
{
|
||||||
"mfussenegger/nvim-jdtls",
|
"mfussenegger/nvim-jdtls",
|
||||||
dependencies = { "folke/which-key.nvim" },
|
dependencies = { "folke/which-key.nvim" },
|
||||||
ft = { "java" },
|
|
||||||
config = function()
|
config = function()
|
||||||
-- The configuration for jdtls contains two useful items:
|
-- The configuration for jdtls contains two useful items:
|
||||||
-- 1. The list of filetypes on which to match.
|
-- 1. The list of filetypes on which to match.
|
||||||
|
|
@ -72,36 +71,35 @@ return {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local fname = vim.api.nvim_buf_get_name(0)
|
|
||||||
local root_dir = find_java_project_root(fname)
|
|
||||||
local project_name = root_dir and vim.fs.basename(root_dir)
|
|
||||||
local cmd = { "jdtls" }
|
|
||||||
if project_name then
|
|
||||||
local jdtls_cache_dir = vim.fn.stdpath("cache") .. "/jdtls/" .. project_name
|
|
||||||
vim.list_extend(cmd, {
|
|
||||||
"-configuration",
|
|
||||||
jdtls_cache_dir .. "/config",
|
|
||||||
"-data",
|
|
||||||
jdtls_cache_dir .. "/workspace",
|
|
||||||
})
|
|
||||||
end
|
|
||||||
local jdtls_base_config = {
|
|
||||||
cmd = cmd,
|
|
||||||
root_dir = root_dir,
|
|
||||||
init_options = {
|
|
||||||
bundles = bundles,
|
|
||||||
},
|
|
||||||
-- enable CMP capabilities
|
|
||||||
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Attach jdtls for the proper filetypes (i.e. java).
|
-- Attach jdtls for the proper filetypes (i.e. java).
|
||||||
-- Existing server will be reused if the root_dir matches.
|
-- Existing server will be reused if the root_dir matches.
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
pattern = filetypes,
|
pattern = filetypes,
|
||||||
callback = function()
|
callback = function()
|
||||||
|
local fname = vim.api.nvim_buf_get_name(0)
|
||||||
|
local root_dir = find_java_project_root(fname)
|
||||||
|
local project_name = root_dir and vim.fs.basename(root_dir)
|
||||||
|
local cmd = { "jdtls" }
|
||||||
|
if project_name then
|
||||||
|
local jdtls_cache_dir = vim.fn.stdpath("cache") .. "/jdtls/" .. project_name
|
||||||
|
vim.list_extend(cmd, {
|
||||||
|
"-configuration",
|
||||||
|
jdtls_cache_dir .. "/config",
|
||||||
|
"-data",
|
||||||
|
jdtls_cache_dir .. "/workspace",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
local jdtls_base_config = {
|
||||||
|
cmd = cmd,
|
||||||
|
root_dir = root_dir,
|
||||||
|
init_options = {
|
||||||
|
bundles = bundles,
|
||||||
|
},
|
||||||
|
-- enable CMP capabilities
|
||||||
|
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
||||||
|
}
|
||||||
local jdtls_opts = require("lazyvim.util").opts("nvim-jdtls")
|
local jdtls_opts = require("lazyvim.util").opts("nvim-jdtls")
|
||||||
require("jdtls").start_or_attach(vim.tbl_deep_extend("force", jdtls_opts or {}, jdtls_base_config))
|
require("jdtls").start_or_attach(vim.tbl_deep_extend("force", jdtls_base_config, jdtls_opts or {}))
|
||||||
-- not need to require("jdtls.setup").add_commands(), start automatically adds commands
|
-- not need to require("jdtls.setup").add_commands(), start automatically adds commands
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue