From 1da7fbeaf3d3422a14059a13ef99928d595d0e6d Mon Sep 17 00:00:00 2001 From: "Paul B. Kim" Date: Tue, 17 Feb 2026 16:01:32 +0900 Subject: [PATCH] feat(debug): add C/C++ codelldb profile and textobject selects Add additive C/C++ DAP launch defaults and treesitter select textobjects to speed structural editing while preserving existing keymaps and DAP controls. --- README.md | 6 ++- lua/custom/dap_cpp.lua | 43 +++++++++++++++++++ lua/custom/plugins/debug.lua | 2 + lua/custom/plugins/treesitter_textobjects.lua | 9 ++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 lua/custom/dap_cpp.lua diff --git a/README.md b/README.md index 1bd1f779..cb53f9c9 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ nvim --headless "+MasonToolsInstallSync" "+qa" - `jm` / `jk`: next/previous function start - `jM` / `jK`: next/previous function end - `jc` / `jC`: next/previous class start +- Textobject select (operator-pending/visual): `af`/`if` for function, `ac`/`ic` for class ### Tests and debug @@ -119,7 +120,8 @@ Existing DAP keys are unchanged: - Core: `nvim-dap`, `nvim-dap-ui`, `mason-nvim-dap`, `nvim-dap-go`. - JS/TS: `nvim-dap-vscode-js` configured with `js-debug-adapter` and `pwa-node` launch/attach defaults. -- C/C++: `codelldb` installation added through Mason DAP setup. +- C/C++: `codelldb` installation via Mason and baseline launch profile + (`Launch current file (codelldb)`). ### Testing @@ -179,7 +181,7 @@ Check with `:Mason` and install manually if needed. 1. Navigate symbols with `jm/jk/jc/jC`. 2. Build/test with CMake mappings if project uses CMake. -3. Debug using existing DAP keys with `codelldb` installed. +3. Debug using existing DAP keys and select `Launch current file (codelldb)`. 4. Run gtest via neotest after `:ConfigureGtest` setup. ### Kubernetes/Helm workflow diff --git a/lua/custom/dap_cpp.lua b/lua/custom/dap_cpp.lua new file mode 100644 index 00000000..483fc41e --- /dev/null +++ b/lua/custom/dap_cpp.lua @@ -0,0 +1,43 @@ +local M = {} + +local function has_configuration(configurations, name, adapter) + for _, configuration in ipairs(configurations or {}) do + if configuration.name == name and configuration.type == adapter then + return true + end + end + + return false +end + +function M.setup(dap) + dap = dap or require 'dap' + + dap.adapters.codelldb = dap.adapters.codelldb or { + type = 'executable', + command = 'codelldb', + } + + local launch_name = 'Launch current file (codelldb)' + local launch_configuration = { + name = launch_name, + type = 'codelldb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + } + + for _, language in ipairs { 'c', 'cpp' } do + dap.configurations[language] = dap.configurations[language] or {} + + if not has_configuration(dap.configurations[language], launch_name, 'codelldb') then + table.insert(dap.configurations[language], vim.deepcopy(launch_configuration)) + end + end +end + +return M diff --git a/lua/custom/plugins/debug.lua b/lua/custom/plugins/debug.lua index ab989236..ff9c8cb0 100644 --- a/lua/custom/plugins/debug.lua +++ b/lua/custom/plugins/debug.lua @@ -145,5 +145,7 @@ return { detached = vim.fn.has 'win32' == 0, }, } + + require('custom.dap_cpp').setup(dap) end, } diff --git a/lua/custom/plugins/treesitter_textobjects.lua b/lua/custom/plugins/treesitter_textobjects.lua index 417daad4..f904c5b7 100644 --- a/lua/custom/plugins/treesitter_textobjects.lua +++ b/lua/custom/plugins/treesitter_textobjects.lua @@ -4,6 +4,15 @@ return { dependencies = { 'nvim-treesitter/nvim-treesitter' }, config = function() require('nvim-treesitter-textobjects').setup { + select = { + lookahead = true, + keymaps = { + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + }, + }, move = { set_jumps = true, },