fix(java): repair Java debugger configuration and add run keymaps
- Fix debug bundles not being passed to JDTLS init_options - Add on_attach callback to setup DAP after LSP attaches - Remove broken manual Java DAP adapter (now handled by nvim-jdtls) - Add java-debug-adapter and java-test to Mason ensure_installed - Add new Java keymaps: debug, test, run (file/maven/gradle)
This commit is contained in:
28
CHANGELOG.md
28
CHANGELOG.md
@@ -9,6 +9,34 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- **Java Debug & Run Keymaps**: New keybindings for Java development
|
||||
- `<leader>jd` - Debug Class (DAP)
|
||||
- `<leader>jt` - Test Class
|
||||
- `<leader>jn` - Test Nearest Method
|
||||
- `<leader>jr` - Run Java File
|
||||
- `<leader>jm` - Run Maven Project
|
||||
- `<leader>jg` - Run Gradle Project
|
||||
- **Java Debug Dependencies**: Added `java-debug-adapter` and `java-test` to Mason ensure_installed
|
||||
|
||||
### Fixed
|
||||
- **Java DAP Configuration**: Fixed debug adapter not loading
|
||||
- Changed `bundles = {}` to `bundles = bundles` to properly load debug JARs
|
||||
- Added `on_attach` callback to setup DAP after JDTLS attaches
|
||||
- Enables hot code replacement during debugging
|
||||
- **Broken Java DAP Adapter**: Removed manual Java adapter with undefined `port` variable
|
||||
- Now handled automatically by nvim-jdtls via `jdtls.setup_dap()`
|
||||
|
||||
---
|
||||
|
||||
## [2026-01-10]
|
||||
|
||||
### Added
|
||||
- **Custom Colorscheme**: Using `cargdev-cyberpunk` theme
|
||||
- Vibrant, high-contrast cyberpunk aesthetic with neon colors
|
||||
- Hot pink keywords, electric purple types, cyan strings, green functions
|
||||
- Full TypeScript/LSP/Treesitter support
|
||||
- Deep blue backgrounds with neon accents
|
||||
- Loaded with high priority for consistent UI
|
||||
- **Which-Key Group Names**: Added organized group names for better keymap discoverability
|
||||
- Groups: Buffer, Code/Copilot, Debug, Explorer, Find/Files, Git, LSP, Format, Quickfix, Session, Tab/Terminal, Trouble, Copilot Chat
|
||||
- **Auto-Format on Save**: Enabled smart auto-formatting with conform.nvim
|
||||
|
||||
@@ -5,7 +5,6 @@ local workspace_dir = workspace_path .. project_name
|
||||
local keymap = vim.keymap.set
|
||||
|
||||
local status, jdtls = pcall(require, "jdtls")
|
||||
local dap = require("dap")
|
||||
|
||||
if not status then
|
||||
return
|
||||
@@ -72,14 +71,46 @@ local config = {
|
||||
},
|
||||
|
||||
init_options = {
|
||||
bundles = {},
|
||||
bundles = bundles,
|
||||
},
|
||||
}
|
||||
|
||||
-- Callback to setup DAP after JDTLS attaches
|
||||
local function jdtls_on_attach(client, bufnr)
|
||||
-- Setup DAP after language server is ready
|
||||
if #bundles > 0 then
|
||||
require("jdtls").setup_dap({ hotcodereplace = "auto" })
|
||||
require("jdtls.dap").setup_dap_main_class_configs()
|
||||
end
|
||||
end
|
||||
|
||||
config.on_attach = jdtls_on_attach
|
||||
|
||||
require("jdtls").start_or_attach(config)
|
||||
|
||||
-- Java code actions
|
||||
keymap("n", "<leader>co", "<Cmd>lua require'jdtls'.organize_imports()<CR>", { desc = "Organize Imports" })
|
||||
keymap("n", "<leader>crv", "<Cmd>lua require('jdtls').extract_variable()<CR>", { desc = "Extract Variable" })
|
||||
keymap("v", "<leader>crv", "<Esc><Cmd>lua require('jdtls').extract_variable(true)<CR>", { desc = "Extract Variable" })
|
||||
keymap("n", "<leader>crc", "<Cmd>lua require('jdtls').extract_constant()<CR>", { desc = "Extract Constant" })
|
||||
keymap("v", "<leader>crc", "<Esc><Cmd>lua require('jdtls').extract_constant(true)<CR>", { desc = "Extract Constant" })
|
||||
keymap("v", "<leader>crm", "<Esc><Cmd>lua require('jdtls').extract_method(true)<CR>", { desc = "Extract Method" })
|
||||
|
||||
-- Java Debug & Run
|
||||
keymap("n", "<leader>jt", "<Cmd>lua require('jdtls').test_class()<CR>", { desc = "Test Class" })
|
||||
keymap("n", "<leader>jn", "<Cmd>lua require('jdtls').test_nearest_method()<CR>", { desc = "Test Nearest Method" })
|
||||
keymap("n", "<leader>jd", "<Cmd>lua require('jdtls').debug_class()<CR>", { desc = "Debug Class (DAP)" })
|
||||
keymap("n", "<leader>jr", function()
|
||||
-- Run Java main class without debugger
|
||||
local main_class = vim.fn.expand("%:t:r")
|
||||
local cmd = string.format("java %s", main_class)
|
||||
vim.cmd("split | terminal " .. cmd)
|
||||
end, { desc = "Run Java File" })
|
||||
keymap("n", "<leader>jm", function()
|
||||
-- Run with Maven
|
||||
vim.cmd("split | terminal mvn compile exec:java")
|
||||
end, { desc = "Run Maven Project" })
|
||||
keymap("n", "<leader>jg", function()
|
||||
-- Run with Gradle
|
||||
vim.cmd("split | terminal ./gradlew run")
|
||||
end, { desc = "Run Gradle Project" })
|
||||
|
||||
@@ -77,7 +77,7 @@ return {
|
||||
|
||||
-- 🧠 Mason DAP
|
||||
require("mason-nvim-dap").setup({
|
||||
ensure_installed = { "js-debug-adapter", "firefox" },
|
||||
ensure_installed = { "js-debug-adapter", "firefox", "javadbg", "javatest" },
|
||||
automatic_setup = true,
|
||||
})
|
||||
|
||||
@@ -140,18 +140,9 @@ return {
|
||||
})
|
||||
|
||||
-- ☕ Java Debug Adapter
|
||||
dap.adapters.java = function(callback)
|
||||
callback({ type = "server", host = "127.0.0.1", port = { port } })
|
||||
end
|
||||
dap.configurations.java = {
|
||||
{
|
||||
name = "Attach to running Java process",
|
||||
type = "java",
|
||||
request = "attach",
|
||||
hostName = "127.0.0.1",
|
||||
port = { port },
|
||||
},
|
||||
}
|
||||
-- Note: Java DAP is configured by nvim-jdtls in ftplugin/java.lua
|
||||
-- via jdtls.setup_dap() which automatically sets up the adapter
|
||||
-- The configurations are dynamically discovered from the project
|
||||
|
||||
-- 🧠 Node.js (NestJS / TypeScript) - Using js-debug-adapter
|
||||
dap.adapters.node = {
|
||||
|
||||
@@ -50,6 +50,8 @@ return {
|
||||
"pylint",
|
||||
"eslint_d",
|
||||
"tree-sitter-cli", -- required for nvim-treesitter parser compilation
|
||||
"java-debug-adapter", -- Java debugger
|
||||
"java-test", -- Java test runner
|
||||
},
|
||||
})
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user