diff --git a/lua/custom/dap_cpp.lua b/lua/custom/dap_cpp.lua deleted file mode 100644 index 483fc41e..00000000 --- a/lua/custom/dap_cpp.lua +++ /dev/null @@ -1,43 +0,0 @@ -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 ff9c8cb0..ba9491db 100644 --- a/lua/custom/plugins/debug.lua +++ b/lua/custom/plugins/debug.lua @@ -6,6 +6,44 @@ -- be extended to other languages as well. That's why it's called -- kickstart.nvim and not kitchen-sink.nvim ;) +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 + +local function setup_cpp_dap(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 { -- NOTE: Yes, you can install new plugins here! 'mfussenegger/nvim-dap', @@ -146,6 +184,6 @@ return { }, } - require('custom.dap_cpp').setup(dap) + setup_cpp_dap(dap) end, }