JESUS EFFING CHRIST (read desc or look at diffs)
after like a billion hours of troubleshooting BS vs launch stuff from launch.json and redirecting it to other debugger adapters because microsoft sucks and windows blows, I FINALY managed to get debugging in neovim from vscode launcher stuff
This commit is contained in:
1 parent
c57f525bd9
commit
d2485ea96b
2 files changed
+185
-19
No files matched your search
@@ -41,7 +41,8 @@ vim.keymap.set("n", "<Leader>f", "<cmd>:lua require('conform').format()<CR>")
|
|||||||
local status_ok, dap = pcall(require, "dap")
|
local status_ok, dap = pcall(require, "dap")
|
||||||
if status_ok then
|
if status_ok then
|
||||||
vim.keymap.set("n", "<leader>cdb", dap.toggle_breakpoint, { desc = "Debug: Toggle Breakpoint" })
|
vim.keymap.set("n", "<leader>cdb", dap.toggle_breakpoint, { desc = "Debug: Toggle Breakpoint" })
|
||||||
vim.keymap.set("n", "<leader>cdc", dap.continue, { desc = "Debug: Start/Continue" })
|
--vim.keymap.set("n", "<leader>cdc", dap.continue, { desc = "Debug: Start/Continue" })
|
||||||
|
-- new start debug keymap in debugger.lua
|
||||||
vim.keymap.set("n", "<leader>cdi", dap.step_into, { desc = "Debug: Step Into" })
|
vim.keymap.set("n", "<leader>cdi", dap.step_into, { desc = "Debug: Step Into" })
|
||||||
vim.keymap.set("n", "<leader>cdo", dap.step_over, { desc = "Debug: Step Over" })
|
vim.keymap.set("n", "<leader>cdo", dap.step_over, { desc = "Debug: Step Over" })
|
||||||
vim.keymap.set("n", "<leader>cdO", dap.step_out, { desc = "Debug: Step Out" })
|
vim.keymap.set("n", "<leader>cdO", dap.step_out, { desc = "Debug: Step Out" })
|
||||||
|
|||||||
+183
-18
@@ -1,3 +1,109 @@
|
|||||||
|
|
||||||
|
local function fzf_pick_executable()
|
||||||
|
return coroutine.create(function(coro)
|
||||||
|
local current_cwd = vim.fn.getcwd():gsub("\\", "/")
|
||||||
|
|
||||||
|
require("fzf-lua").files({
|
||||||
|
cwd = current_cwd,
|
||||||
|
cmd = "fd --type x --hidden --no-ignore",
|
||||||
|
|
||||||
|
previewer = false,
|
||||||
|
header = false,
|
||||||
|
prompt = "Select Executable ❯ ",
|
||||||
|
|
||||||
|
winopts = {
|
||||||
|
title = " Select Executable ",
|
||||||
|
title_pos = "center",
|
||||||
|
height = 0.40,
|
||||||
|
width = 0.60,
|
||||||
|
},
|
||||||
|
|
||||||
|
actions = {
|
||||||
|
["default"] = function(selected)
|
||||||
|
if selected and selected[1] then
|
||||||
|
-- 1. Strip icons and formatting spaces to isolate the file string
|
||||||
|
local entry = require("fzf-lua.path").entry_to_file(selected[1], { cwd = current_cwd })
|
||||||
|
|
||||||
|
-- 2. Automatically resolve it to an absolute path (handles relative or absolute safely)
|
||||||
|
local full_path = vim.fn.fnamemodify(entry.path, ":p")
|
||||||
|
|
||||||
|
-- 3. Clean up slashes and hand it to DAP
|
||||||
|
coroutine.resume(coro, full_path:gsub("\\", "/"))
|
||||||
|
else
|
||||||
|
coroutine.resume(coro, vim.fn.empty())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function start_debug_session()
|
||||||
|
|
||||||
|
|
||||||
|
local dap = require("dap")
|
||||||
|
-- 3. Platform-agnostic Launcher Configuration
|
||||||
|
if not is_windows then
|
||||||
|
dap.configurations.cpp = {
|
||||||
|
{
|
||||||
|
name = "Launch file",
|
||||||
|
type = "codelldb",
|
||||||
|
request = "launch",
|
||||||
|
program = fzf_pick_executable,
|
||||||
|
cwd = '${workspaceFolder}',
|
||||||
|
stopOnEntry = false,
|
||||||
|
args = {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
else
|
||||||
|
local launch_json = vim.fn.getcwd() .. "/.vscode/launch.json"
|
||||||
|
if vim.fn.filereadable(launch_json) == 1 then
|
||||||
|
dap.configurations.cpp = {}
|
||||||
|
-- 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
|
||||||
|
--elseif dap.adapters.codelldb then
|
||||||
|
-- dap.adapters.cppvsdbg = dap.adapters.codelldb
|
||||||
|
--end
|
||||||
|
-- 2. Map types inside launch.json to your C++ filetypes
|
||||||
|
vscode.load_launchjs(nil, {
|
||||||
|
cppvsdbg = { "cpp", "c" },
|
||||||
|
cppdbg = { "cpp", "c" },
|
||||||
|
codelldb = { "cpp", "c" },
|
||||||
|
})
|
||||||
|
else
|
||||||
|
-- No launch.json exists. Re-inject your FZF picker template rules
|
||||||
|
dap.configurations.cpp = {
|
||||||
|
{
|
||||||
|
name = "Launch file",
|
||||||
|
type = "cppdbg",
|
||||||
|
request = "launch",
|
||||||
|
program = fzf_pick_executable,
|
||||||
|
cwd = "${workspaceFolder}",
|
||||||
|
stopOnEntry = false,
|
||||||
|
|
||||||
|
-- Crucial configurations for Microsoft cpptools:
|
||||||
|
-- On Windows, this automatically uses MinGW/MSVC underlying debugger engines
|
||||||
|
MIMode = is_windows and "gdb" or "lldb",
|
||||||
|
miDebuggerPath = is_windows and "gdb.exe" or nil, -- Uses system path for gdb on Windows
|
||||||
|
|
||||||
|
setupCommands = {
|
||||||
|
{
|
||||||
|
text = "-enable-pretty-printing",
|
||||||
|
description = "enable pretty printing",
|
||||||
|
ignoreFailures = false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
dap.continue()
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader>cdc", start_debug_session, { desc = "Debug: Start/Continue with Smart Config" })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"mfussenegger/nvim-dap",
|
"mfussenegger/nvim-dap",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
@@ -27,36 +133,95 @@ return {
|
|||||||
dap.listeners.before.event_exited["dapui_config"] = function() dapui.close() end
|
dap.listeners.before.event_exited["dapui_config"] = function() dapui.close() end
|
||||||
|
|
||||||
-- Step 2 & 3 configurations will go here...
|
-- Step 2 & 3 configurations will go here...
|
||||||
-- Define the adapter connection
|
-- 1. Detect operating system
|
||||||
|
local is_windows = vim.fn.has("win32") == 1
|
||||||
|
local ext = is_windows and ".exe" or ""
|
||||||
|
|
||||||
|
-- 2. Platform-agnostic CodeLLDB Adapter setup
|
||||||
|
local mason_registry = require("mason-registry")
|
||||||
|
local codelldb = mason_registry.get_package("codelldb")
|
||||||
|
local extension_path = codelldb:get_install_path() .. "/extension/"
|
||||||
|
|
||||||
|
-- CodeLLDB executable is in different subfolders depending on Mason's package version
|
||||||
|
local codelldb_path = extension_path .. "adapter/codelldb" .. ext
|
||||||
|
|
||||||
|
|
||||||
|
local cpptools_pkg = mason_registry.get_package("cpptools")
|
||||||
|
local cpptools_path = cpptools_pkg:get_install_path()
|
||||||
|
.. "/extension/debugAdapters/bin/OpenDebugAD7"
|
||||||
|
.. ext
|
||||||
|
|
||||||
|
|
||||||
dap.adapters.codelldb = {
|
dap.adapters.codelldb = {
|
||||||
type = 'server',
|
type = 'server',
|
||||||
port = "${port}",
|
port = "${port}",
|
||||||
executable = {
|
executable = {
|
||||||
-- Adjust this path if Mason uses a different default location on your OS
|
command = codelldb_path,
|
||||||
command = vim.fn.stdpath("data") .. "/mason/bin/codelldb",
|
|
||||||
args = {"--port", "${port}"},
|
args = {"--port", "${port}"},
|
||||||
|
detached = not is_windows,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Configure C++ configurations
|
dap.adapters.cppdbg = {
|
||||||
dap.configurations.cpp = {
|
id = "cppdbg",
|
||||||
{
|
type = "executable",
|
||||||
name = "Launch file",
|
command = cpptools_path,
|
||||||
type = "codelldb",
|
-- For Windows subprocess tracking stability
|
||||||
request = "launch",
|
options = {
|
||||||
program = function()
|
detached = not is_windows,
|
||||||
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
|
|
||||||
end,
|
|
||||||
cwd = '${workspaceFolder}',
|
|
||||||
stopOnEntry = false,
|
|
||||||
args = {},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Re-use C++ configuration for C language
|
dap.adapters.cppvsdbg = {
|
||||||
|
id = "cppdbg",
|
||||||
|
type = "executable",
|
||||||
|
command = cpptools_path,
|
||||||
|
-- For Windows subprocess tracking stability
|
||||||
|
options = {
|
||||||
|
detached = not is_windows,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 3. Platform-agnostic Launcher Configuration
|
||||||
|
if not is_windows then
|
||||||
|
dap.configurations.cpp = {
|
||||||
|
{
|
||||||
|
name = "Launch file",
|
||||||
|
type = "codelldb",
|
||||||
|
request = "launch",
|
||||||
|
program = fzf_pick_executable,
|
||||||
|
cwd = '${workspaceFolder}',
|
||||||
|
stopOnEntry = false,
|
||||||
|
args = {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dap.configurations.cpp = {
|
||||||
|
{
|
||||||
|
name = "Launch file",
|
||||||
|
type = "cppdbg",
|
||||||
|
request = "launch",
|
||||||
|
program = fzf_pick_executable,
|
||||||
|
cwd = "${workspaceFolder}",
|
||||||
|
stopOnEntry = false,
|
||||||
|
|
||||||
|
-- Crucial configurations for Microsoft cpptools:
|
||||||
|
-- On Windows, this automatically uses MinGW/MSVC underlying debugger engines
|
||||||
|
MIMode = is_windows and "gdb" or "lldb",
|
||||||
|
miDebuggerPath = is_windows and "gdb.exe" or nil, -- Uses system path for gdb on Windows
|
||||||
|
|
||||||
|
setupCommands = {
|
||||||
|
{
|
||||||
|
text = "-enable-pretty-printing",
|
||||||
|
description = "enable pretty printing",
|
||||||
|
ignoreFailures = false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
dap.configurations.c = dap.configurations.cpp
|
dap.configurations.c = dap.configurations.cpp
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user