From 66942a1daa2566b59358beb350892e1f5844eb08 Mon Sep 17 00:00:00 2001 From: Mitchell Hingley Date: Tue, 8 Sep 2026 15:53:56 -0400 Subject: [PATCH] made windows nvim debugging work better with vscode --- lua/config/keymaps.lua | 12 ++++++++++-- lua/plugins/debugger.lua | 26 +++++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index efefa1b..0c1151d 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -44,7 +44,15 @@ if status_ok then --vim.keymap.set("n", "cdc", dap.continue, { desc = "Debug: Start/Continue" }) -- new start debug keymap in debugger.lua vim.keymap.set("n", "cdi", dap.step_into, { desc = "Debug: Step Into" }) - vim.keymap.set("n", "cdo", dap.step_over, { desc = "Debug: Step Over" }) - vim.keymap.set("n", "cdO", dap.step_out, { desc = "Debug: Step Out" }) + vim.keymap.set("n", "cdn", dap.step_over, { desc = "Debug: Step Over" }) + vim.keymap.set("n", "cdO", dap.step_out, { desc = "Debug: Step Out" }) vim.keymap.set("n", "cdt", dap.terminate, { desc = "Debug: Terminate" }) + + vim.keymap.set("n", "cdr", dap.restart, { desc = "Debug: Restart" }) + vim.keymap.set("n", "cdp", dap.pause, { desc = "Debug: Pause" }) + vim.keymap.set("n", "cd[", dap.up, { desc = "Debug: Callstack up" }) + vim.keymap.set("n", "cd]", dap.down, { desc = "Debug: Callstack down" }) + vim.keymap.set("n", "cdh", function() + require("dap.ui.widgets").hover() + end, { desc = "DAP: Hover Variable Value" }) end diff --git a/lua/plugins/debugger.lua b/lua/plugins/debugger.lua index ee2058f..9d5977b 100644 --- a/lua/plugins/debugger.lua +++ b/lua/plugins/debugger.lua @@ -42,6 +42,7 @@ end local function start_debug_session() + local is_windows = vim.fn.has("win32") == 1 local dap = require("dap") -- 3. Platform-agnostic Launcher Configuration if not is_windows then @@ -57,9 +58,11 @@ local function start_debug_session() }, } else + local vscode = require('dap.ext.vscode') local launch_json = vim.fn.getcwd() .. "/.vscode/launch.json" if vim.fn.filereadable(launch_json) == 1 then dap.configurations.cpp = {} + dap.configurations.c = {} -- 1. CRUCIAL FIX: Alias the adapters directly so nvim-dap doesn't complain about a missing engine --if dap.adapters.cppdbg then -- dap.adapters.cppvsdbg = dap.adapters.cppdbg @@ -67,11 +70,11 @@ local function start_debug_session() -- dap.adapters.cppvsdbg = dap.adapters.codelldb --end -- 2. Map types inside launch.json to your C++ filetypes - vscode.load_launchjs(nil, { + vscode.type_to_filetypes = { cppvsdbg = { "cpp", "c" }, cppdbg = { "cpp", "c" }, codelldb = { "cpp", "c" }, - }) + } else -- No launch.json exists. Re-inject your FZF picker template rules dap.configurations.cpp = { @@ -123,7 +126,7 @@ return { -- Automatically manage debugger installations via Mason require("mason-nvim-dap").setup({ - ensure_installed = { "codelldb" }, -- Auto-installs CodeLLDB + ensure_installed = { "codelldb", "cppdbg" }, -- Auto-installs CodeLLDB automatic_installation = true, }) @@ -158,7 +161,7 @@ return { executable = { command = codelldb_path, args = {"--port", "${port}"}, - detached = not is_windows, + detached = false, } } @@ -173,13 +176,13 @@ return { } dap.adapters.cppvsdbg = { - id = "cppdbg", - type = "executable", - command = cpptools_path, - -- For Windows subprocess tracking stability - options = { - detached = not is_windows, - }, + type = 'server', + port = "${port}", + executable = { + command = codelldb_path, + args = {"--port", "${port}"}, + detached = false, + } } -- 3. Platform-agnostic Launcher Configuration @@ -225,3 +228,4 @@ return { end } +