mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-21 08:35:48 +02:00
add: java dap config
This commit is contained in:
parent
21929ee44d
commit
d44240f988
4 changed files with 176 additions and 186 deletions
|
@ -46,7 +46,7 @@
|
||||||
"nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" },
|
"nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" },
|
||||||
"nvim-scrollview": { "branch": "main", "commit": "06563ae0c9928a2df42aefe66f2aed2f2943e32e" },
|
"nvim-scrollview": { "branch": "main", "commit": "06563ae0c9928a2df42aefe66f2aed2f2943e32e" },
|
||||||
"nvim-tree.lua": { "branch": "master", "commit": "2086e564c4d23fea714e8a6d63b881e551af2f41" },
|
"nvim-tree.lua": { "branch": "master", "commit": "2086e564c4d23fea714e8a6d63b881e551af2f41" },
|
||||||
"nvim-treesitter": { "branch": "master", "commit": "cf7baac35aa5c103b960bcb3f15c690a4aa5c6f1" },
|
"nvim-treesitter": { "branch": "master", "commit": "c11d49cbefb3c22550747840843eb86ab4a3b267" },
|
||||||
"nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" },
|
"nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" },
|
||||||
"nvim-ts-autotag": { "branch": "main", "commit": "ddfccbf0df1b9349c2b9e9b17f4afa8f9b6c1ed1" },
|
"nvim-ts-autotag": { "branch": "main", "commit": "ddfccbf0df1b9349c2b9e9b17f4afa8f9b6c1ed1" },
|
||||||
"nvim-ts-context-commentstring": { "branch": "main", "commit": "cb064386e667def1d241317deed9fd1b38f0dc2e" },
|
"nvim-ts-context-commentstring": { "branch": "main", "commit": "cb064386e667def1d241317deed9fd1b38f0dc2e" },
|
||||||
|
|
|
@ -174,5 +174,5 @@ pcode.active_cpp_config = false
|
||||||
pcode.active_java_config = {
|
pcode.active_java_config = {
|
||||||
active = true,
|
active = true,
|
||||||
project = "gradle", -- gradle or maven
|
project = "gradle", -- gradle or maven
|
||||||
-- use_nvim_jdtls = false, -- mfussenegger/nvim-jdtls
|
use_nvim_jdtls = true, -- mfussenegger/nvim-jdtls
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,164 +17,170 @@ end
|
||||||
|
|
||||||
if pcode.active_java_config.active then
|
if pcode.active_java_config.active then
|
||||||
M = {
|
M = {
|
||||||
-- {
|
{
|
||||||
-- "mfussenegger/nvim-jdtls",
|
"mfussenegger/nvim-jdtls",
|
||||||
-- ft = java_filetypes,
|
ft = java_filetypes,
|
||||||
-- enable = pcode.active_java_config.use_nvim_jdtls or false,
|
enabled = pcode.active_java_config.use_nvim_jdtls or false,
|
||||||
-- opts = function()
|
opts = function()
|
||||||
-- return {
|
return {
|
||||||
-- root_dir = require("jdtls.setup").find_root(root_markers),
|
root_dir = require("jdtls.setup").find_root(root_markers),
|
||||||
-- project_name = function()
|
project_name = function()
|
||||||
-- return vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
return vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
||||||
-- end,
|
end,
|
||||||
--
|
|
||||||
-- -- Where are the config and workspace dirs for a project?
|
-- Where are the config and workspace dirs for a project?
|
||||||
-- jdtls_config_dir = function(project_name)
|
jdtls_config_dir = function(project_name)
|
||||||
-- return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/config"
|
return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/config"
|
||||||
-- end,
|
end,
|
||||||
-- jdtls_workspace_dir = function(project_name)
|
jdtls_workspace_dir = function(project_name)
|
||||||
-- return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/workspace"
|
return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/workspace"
|
||||||
-- end,
|
end,
|
||||||
-- cmd = { vim.fn.exepath("jdtls") },
|
cmd = { vim.fn.exepath("jdtls") },
|
||||||
-- full_cmd = function(opts)
|
full_cmd = function(opts)
|
||||||
-- local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
||||||
-- local cmd = vim.deepcopy(opts.cmd)
|
local cmd = vim.deepcopy(opts.cmd)
|
||||||
-- if project_name then
|
if project_name then
|
||||||
-- vim.list_extend(cmd, {
|
vim.list_extend(cmd, {
|
||||||
-- "-configuration",
|
"-configuration",
|
||||||
-- opts.jdtls_config_dir(project_name),
|
opts.jdtls_config_dir(project_name),
|
||||||
-- "-data",
|
"-data",
|
||||||
-- opts.jdtls_workspace_dir(project_name),
|
opts.jdtls_workspace_dir(project_name),
|
||||||
-- })
|
})
|
||||||
-- end
|
end
|
||||||
-- return cmd
|
return cmd
|
||||||
-- end,
|
end,
|
||||||
--
|
|
||||||
-- -- These depend on nvim-dap, but can additionally be disabled by setting false here.
|
-- These depend on nvim-dap, but can additionally be disabled by setting false here.
|
||||||
-- dap = { hotcodereplace = "auto", config_overrides = {} },
|
dap = { hotcodereplace = "auto", config_overrides = {} },
|
||||||
-- dap_main = {},
|
dap_main = {},
|
||||||
-- test = true,
|
test = true,
|
||||||
-- settings = {
|
settings = {
|
||||||
-- java = {
|
java = {
|
||||||
-- inlayHints = {
|
inlayHints = {
|
||||||
-- parameterNames = {
|
parameterNames = {
|
||||||
-- enabled = "all",
|
enabled = "all",
|
||||||
-- },
|
},
|
||||||
-- },
|
},
|
||||||
-- },
|
},
|
||||||
-- },
|
},
|
||||||
-- }
|
}
|
||||||
-- end,
|
end,
|
||||||
-- config = function(_, opts)
|
config = function(_, opts)
|
||||||
-- local mason_registry = require("mason-registry")
|
vim.opt_local.shiftwidth = 4
|
||||||
-- local bundles = {} ---@type string[]
|
vim.opt_local.tabstop = 4
|
||||||
-- if opts.dap and mason_registry.is_installed("java-debug-adapter") then
|
vim.opt_local.softtabstop = 4
|
||||||
-- local java_dbg_pkg = mason_registry.get_package("java-debug-adapter")
|
vim.opt_local.ts = 4
|
||||||
-- local java_dbg_path = java_dbg_pkg:get_install_path()
|
vim.opt_local.expandtab = true
|
||||||
-- local jar_patterns = {
|
|
||||||
-- java_dbg_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar",
|
local mason_registry = require("mason-registry")
|
||||||
-- }
|
local bundles = {} ---@type string[]
|
||||||
-- -- java-test also depends on java-debug-adapter.
|
if opts.dap and mason_registry.is_installed("java-debug-adapter") then
|
||||||
-- if opts.test and mason_registry.is_installed("java-test") then
|
local java_dbg_pkg = mason_registry.get_package("java-debug-adapter")
|
||||||
-- local java_test_pkg = mason_registry.get_package("java-test")
|
local java_dbg_path = java_dbg_pkg:get_install_path()
|
||||||
-- local java_test_path = java_test_pkg:get_install_path()
|
local jar_patterns = {
|
||||||
-- vim.list_extend(jar_patterns, {
|
java_dbg_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar",
|
||||||
-- java_test_path .. "/extension/server/*.jar",
|
}
|
||||||
-- })
|
-- java-test also depends on java-debug-adapter.
|
||||||
-- end
|
if opts.test and mason_registry.is_installed("java-test") then
|
||||||
-- for _, jar_pattern in ipairs(jar_patterns) do
|
local java_test_pkg = mason_registry.get_package("java-test")
|
||||||
-- for _, bundle in ipairs(vim.split(vim.fn.glob(jar_pattern), "\n")) do
|
local java_test_path = java_test_pkg:get_install_path()
|
||||||
-- table.insert(bundles, bundle)
|
vim.list_extend(jar_patterns, {
|
||||||
-- end
|
java_test_path .. "/extension/server/*.jar",
|
||||||
-- end
|
})
|
||||||
-- end
|
end
|
||||||
--
|
for _, jar_pattern in ipairs(jar_patterns) do
|
||||||
-- local function attach_jdtls()
|
for _, bundle in ipairs(vim.split(vim.fn.glob(jar_pattern), "\n")) do
|
||||||
-- local fname = vim.api.nvim_buf_get_name(0)
|
table.insert(bundles, bundle)
|
||||||
--
|
end
|
||||||
-- -- Configuration can be augmented and overridden by opts.jdtls
|
end
|
||||||
-- local config = extend_or_override({
|
end
|
||||||
-- cmd = opts.full_cmd(opts),
|
|
||||||
-- root_dir = require("jdtls.setup").find_root(root_markers),
|
local function attach_jdtls()
|
||||||
-- init_options = {
|
local fname = vim.api.nvim_buf_get_name(0)
|
||||||
-- bundles = bundles,
|
|
||||||
-- },
|
-- Configuration can be augmented and overridden by opts.jdtls
|
||||||
-- settings = opts.settings,
|
local config = extend_or_override({
|
||||||
-- -- enable CMP capabilities
|
cmd = opts.full_cmd(opts),
|
||||||
-- capabilities = require("user.lsp.handlers").capabilities or nil,
|
root_dir = require("jdtls.setup").find_root(root_markers),
|
||||||
-- }, opts.jdtls)
|
init_options = {
|
||||||
--
|
bundles = bundles,
|
||||||
-- -- Existing server will be reused if the root_dir matches.
|
},
|
||||||
-- require("jdtls").start_or_attach(config)
|
settings = opts.settings,
|
||||||
-- -- not need to require("jdtls.setup").add_commands(), start automatically adds commands
|
-- enable CMP capabilities
|
||||||
-- end
|
capabilities = require("user.lsp.handlers").capabilities or nil,
|
||||||
--
|
}, opts.jdtls)
|
||||||
-- vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
-- pattern = java_filetypes,
|
-- Existing server will be reused if the root_dir matches.
|
||||||
-- callback = attach_jdtls,
|
require("jdtls").start_or_attach(config)
|
||||||
-- })
|
-- not need to require("jdtls.setup").add_commands(), start automatically adds commands
|
||||||
--
|
end
|
||||||
-- -- Setup keymap and dap after the lsp is fully attached.
|
|
||||||
-- -- https://github.com/mfussenegger/nvim-jdtls#nvim-dap-configuration
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
-- -- https://neovim.io/doc/user/lsp.html#LspAttach
|
pattern = java_filetypes,
|
||||||
-- vim.api.nvim_create_autocmd("LspAttach", {
|
callback = attach_jdtls,
|
||||||
-- callback = function(args)
|
})
|
||||||
-- local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
||||||
-- if client and client.name == "jdtls" then
|
-- Setup keymap and dap after the lsp is fully attached.
|
||||||
-- local wk = require("which-key")
|
-- https://github.com/mfussenegger/nvim-jdtls#nvim-dap-configuration
|
||||||
-- wk.register({
|
-- https://neovim.io/doc/user/lsp.html#LspAttach
|
||||||
-- ["<leader>cx"] = { name = "+extract" },
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
-- ["<leader>cxv"] = { require("jdtls").extract_variable_all, "Extract Variable" },
|
callback = function(args)
|
||||||
-- ["<leader>cxc"] = { require("jdtls").extract_constant, "Extract Constant" },
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
-- ["gs"] = { require("jdtls").super_implementation, "Goto Super" },
|
if client and client.name == "jdtls" then
|
||||||
-- ["<leader>co"] = { require("jdtls").organize_imports, "Organize Imports" },
|
local wk = require("which-key")
|
||||||
-- }, { mode = "n", buffer = args.buf })
|
wk.register({
|
||||||
-- wk.register({
|
["<leader>cx"] = { name = "+extract" },
|
||||||
-- ["<leader>c"] = { name = "+code" },
|
["<leader>cxv"] = { require("jdtls").extract_variable_all, "Extract Variable" },
|
||||||
-- ["<leader>cx"] = { name = "+extract" },
|
["<leader>cxc"] = { require("jdtls").extract_constant, "Extract Constant" },
|
||||||
-- ["<leader>cxm"] = {
|
["gs"] = { require("jdtls").super_implementation, "Goto Super" },
|
||||||
-- [[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]],
|
["<leader>co"] = { require("jdtls").organize_imports, "Organize Imports" },
|
||||||
-- "Extract Method",
|
}, { mode = "n", buffer = args.buf })
|
||||||
-- },
|
wk.register({
|
||||||
-- ["<leader>cxv"] = {
|
["<leader>c"] = { name = "+code" },
|
||||||
-- [[<ESC><CMD>lua require('jdtls').extract_variable_all(true)<CR>]],
|
["<leader>cx"] = { name = "+extract" },
|
||||||
-- "Extract Variable",
|
["<leader>cxm"] = {
|
||||||
-- },
|
[[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]],
|
||||||
-- ["<leader>cxc"] = {
|
"Extract Method",
|
||||||
-- [[<ESC><CMD>lua require('jdtls').extract_constant(true)<CR>]],
|
},
|
||||||
-- "Extract Constant",
|
["<leader>cxv"] = {
|
||||||
-- },
|
[[<ESC><CMD>lua require('jdtls').extract_variable_all(true)<CR>]],
|
||||||
-- }, { mode = "v", buffer = args.buf })
|
"Extract Variable",
|
||||||
--
|
},
|
||||||
-- if opts.dap and mason_registry.is_installed("java-debug-adapter") then
|
["<leader>cxc"] = {
|
||||||
-- -- custom init for Java debugger
|
[[<ESC><CMD>lua require('jdtls').extract_constant(true)<CR>]],
|
||||||
-- require("jdtls").setup_dap(opts.dap)
|
"Extract Constant",
|
||||||
-- require("jdtls.dap").setup_dap_main_class_configs(opts.dap_main)
|
},
|
||||||
--
|
}, { mode = "v", buffer = args.buf })
|
||||||
-- -- Java Test require Java debugger to work
|
|
||||||
-- if opts.test and mason_registry.is_installed("java-test") then
|
if opts.dap and mason_registry.is_installed("java-debug-adapter") then
|
||||||
-- -- custom keymaps for Java test runner (not yet compatible with neotest)
|
-- custom init for Java debugger
|
||||||
-- wk.register({
|
require("jdtls").setup_dap(opts.dap)
|
||||||
-- ["<leader>t"] = { name = "+test" },
|
require("jdtls.dap").setup_dap_main_class_configs(opts.dap_main)
|
||||||
-- ["<leader>tt"] = { require("jdtls.dap").test_class, "Run All Test" },
|
|
||||||
-- ["<leader>tr"] = { require("jdtls.dap").test_nearest_method, "Run Nearest Test" },
|
-- Java Test require Java debugger to work
|
||||||
-- ["<leader>tT"] = { require("jdtls.dap").pick_test, "Run Test" },
|
if opts.test and mason_registry.is_installed("java-test") then
|
||||||
-- }, { mode = "n", buffer = args.buf })
|
-- custom keymaps for Java test runner (not yet compatible with neotest)
|
||||||
-- end
|
wk.register({
|
||||||
-- end
|
["<leader>t"] = { name = "+test" },
|
||||||
--
|
["<leader>tt"] = { require("jdtls.dap").test_class, "Run All Test" },
|
||||||
-- -- User can set additional keymaps in opts.on_attach
|
["<leader>tr"] = { require("jdtls.dap").test_nearest_method, "Run Nearest Test" },
|
||||||
-- if opts.on_attach then
|
["<leader>tT"] = { require("jdtls.dap").pick_test, "Run Test" },
|
||||||
-- opts.on_attach(args)
|
}, { mode = "n", buffer = args.buf })
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
-- end,
|
|
||||||
-- })
|
-- User can set additional keymaps in opts.on_attach
|
||||||
--
|
if opts.on_attach then
|
||||||
-- -- Avoid race condition by calling attach the first time, since the autocmd won't fire.
|
opts.on_attach(args)
|
||||||
-- attach_jdtls()
|
end
|
||||||
-- end,
|
end
|
||||||
-- },
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Avoid race condition by calling attach the first time, since the autocmd won't fire.
|
||||||
|
attach_jdtls()
|
||||||
|
end,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"nvim-treesitter/nvim-treesitter",
|
"nvim-treesitter/nvim-treesitter",
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
|
@ -193,8 +199,9 @@ if pcode.active_java_config.active then
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
local package = "google-java-format"
|
local package = "lsp_fmt"
|
||||||
require("user.utils.mason").try_install(package)
|
require("user.utils.mason").try_install("java-debug-adapter")
|
||||||
|
require("user.utils.mason").try_install("java-test")
|
||||||
opts.formatters_by_ft.java = { package }
|
opts.formatters_by_ft.java = { package }
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
@ -243,21 +250,4 @@ if pcode.active_java_config.active then
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if pcode.active_java_config.use_nvim_jdtls then
|
|
||||||
-- table.insert(M, {
|
|
||||||
-- "neovim/nvim-lspconfig",
|
|
||||||
-- enabled = pcode.active_java_config.use_nvim_jdtls or false,
|
|
||||||
-- opts = {
|
|
||||||
-- -- make sure mason installs the server
|
|
||||||
-- servers = {
|
|
||||||
-- jdtls = {},
|
|
||||||
-- },
|
|
||||||
-- setup = {
|
|
||||||
-- jdtls = function()
|
|
||||||
-- return true -- avoid duplicate servers
|
|
||||||
-- end,
|
|
||||||
-- },
|
|
||||||
-- },
|
|
||||||
-- })
|
|
||||||
-- end
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -110,11 +110,11 @@ if pcode.active_cpp_config then
|
||||||
pcode.nvim_dap = true
|
pcode.nvim_dap = true
|
||||||
end
|
end
|
||||||
-- run if java config true
|
-- run if java config true
|
||||||
-- if pcode.active_java_config.active then
|
if pcode.active_java_config.active and pcode.active_java_config.use_nvim_jdtls then
|
||||||
-- table.insert(pcode.treesitter_ensure_installed, "java")
|
-- table.insert(pcode.treesitter_ensure_installed, "java")
|
||||||
-- table.insert(pcode.mason_ensure_installed, "jdtls")
|
-- table.insert(pcode.mason_ensure_installed, "jdtls")
|
||||||
-- table.insert(pcode.null_ls_ensure_installed, "google_java_format")
|
-- table.insert(pcode.null_ls_ensure_installed, "google_java_format")
|
||||||
-- table.insert(pcode.dap_ensure_installed, "javadbg")
|
-- table.insert(pcode.dap_ensure_installed, "javadbg")
|
||||||
-- table.insert(pcode.unregister_lsp, "jdtls")
|
table.insert(pcode.unregister_lsp, "jdtls")
|
||||||
-- end
|
end
|
||||||
return {}
|
return {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue