From 3940c92b48583cb2fe797fae317bc70cb7cdfc0f Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez Date: Sat, 10 Jan 2026 22:27:02 -0500 Subject: [PATCH] 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) --- CHANGELOG.md | 28 +++++++++++++++++++++++++ ftplugin/java.lua | 35 +++++++++++++++++++++++++++++-- lua/cargdev/plugins/dap.lua | 17 ++++----------- lua/cargdev/plugins/lsp/mason.lua | 2 ++ 4 files changed, 67 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1559871..4d53f2c 100644 --- a/CHANGELOG.md +++ b/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 + - `jd` - Debug Class (DAP) + - `jt` - Test Class + - `jn` - Test Nearest Method + - `jr` - Run Java File + - `jm` - Run Maven Project + - `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 diff --git a/ftplugin/java.lua b/ftplugin/java.lua index b81ed8b..346e395 100644 --- a/ftplugin/java.lua +++ b/ftplugin/java.lua @@ -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", "co", "lua require'jdtls'.organize_imports()", { desc = "Organize Imports" }) keymap("n", "crv", "lua require('jdtls').extract_variable()", { desc = "Extract Variable" }) keymap("v", "crv", "lua require('jdtls').extract_variable(true)", { desc = "Extract Variable" }) keymap("n", "crc", "lua require('jdtls').extract_constant()", { desc = "Extract Constant" }) keymap("v", "crc", "lua require('jdtls').extract_constant(true)", { desc = "Extract Constant" }) keymap("v", "crm", "lua require('jdtls').extract_method(true)", { desc = "Extract Method" }) + +-- Java Debug & Run +keymap("n", "jt", "lua require('jdtls').test_class()", { desc = "Test Class" }) +keymap("n", "jn", "lua require('jdtls').test_nearest_method()", { desc = "Test Nearest Method" }) +keymap("n", "jd", "lua require('jdtls').debug_class()", { desc = "Debug Class (DAP)" }) +keymap("n", "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", "jm", function() + -- Run with Maven + vim.cmd("split | terminal mvn compile exec:java") +end, { desc = "Run Maven Project" }) +keymap("n", "jg", function() + -- Run with Gradle + vim.cmd("split | terminal ./gradlew run") +end, { desc = "Run Gradle Project" }) diff --git a/lua/cargdev/plugins/dap.lua b/lua/cargdev/plugins/dap.lua index b899228..91da8b0 100644 --- a/lua/cargdev/plugins/dap.lua +++ b/lua/cargdev/plugins/dap.lua @@ -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 = { diff --git a/lua/cargdev/plugins/lsp/mason.lua b/lua/cargdev/plugins/lsp/mason.lua index adfd2de..d277385 100644 --- a/lua/cargdev/plugins/lsp/mason.lua +++ b/lua/cargdev/plugins/lsp/mason.lua @@ -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,