From aeb346b991c47eca87d66bb0085b479403dd0d84 Mon Sep 17 00:00:00 2001 From: Alex Liang Date: Thu, 4 Jun 2026 23:59:57 -0400 Subject: [PATCH] fix(dap): skip enrich_config for attach mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setup:enrich_config asserts that mainClass is present, but attach configs don't have one and don't need one — the JVM is already running and chose its own main class, classpath, and java executable. The assert fires before any check on request type, making every attach config in nvim-dap fail unless callers pre-populate dummy values for the five fields the early-return checks. Adding an early return for `request == 'attach'` skips the launch-specific enrichment (build_workspace, classpath resolution, java executable resolution) which are all meaningless for an already- running JVM. Reproduction: register a Java attach config in dap.configurations.java with type='java', request='attach', hostName='127.0.0.1', port=5005, then :DapContinue. Today it errors with: To enrich the config, mainClass should already be present .../java-dap/setup.lua:54 After this fix, the attach proceeds and dap-ui opens against the running JVM as expected. Co-Authored-By: Claude Opus 4.7 (1M context) --- lua/java-dap/setup.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/java-dap/setup.lua b/lua/java-dap/setup.lua index cf73550..4ad542e 100644 --- a/lua/java-dap/setup.lua +++ b/lua/java-dap/setup.lua @@ -41,6 +41,14 @@ end function Setup:enrich_config(config) config = vim.deepcopy(config) + -- Attach configs don't need enriching — the JVM is already running and + -- chose its own main class, classpath, and java executable. Without this + -- short-circuit, the `assert(main, ...)` below fires because attach + -- configs (correctly) have no mainClass. + if config.request == 'attach' then + return config + end + -- skip enriching if already enriched if config.mainClass and config.projectName and config.modulePaths and config.classPaths and config.javaExec then return config