From b1c9be6a2455624696c13ebbff2a9d46eebee655 Mon Sep 17 00:00:00 2001 From: Sayed Abdulmohsen Alhashemi Date: Fri, 17 Jan 2025 10:11:10 +0300 Subject: [PATCH] nvim-dap and more keymaps --- init.lua | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/init.lua b/init.lua index bd750267..3e86186a 100644 --- a/init.lua +++ b/init.lua @@ -948,6 +948,104 @@ require('lazy').setup({ -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- { import = 'custom.plugins' }, + { + 'mfussenegger/nvim-dap', + recommended = true, + desc = 'Debugging support. Requires language specific adapters to be configured. (see lang extras)', + + dependencies = { + 'rcarriga/nvim-dap-ui', + 'nvim-neotest/nvim-nio', + -- virtual text for the debugger + { + 'theHamsta/nvim-dap-virtual-text', + opts = {}, + }, + }, + + -- stylua: ignore + keys = { + { "dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" }, + { "", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" }, + { "", function() require("dap").continue() end, desc = "Run/Continue" }, + { "da", function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" }, + { "dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" }, + { "dg", function() require("dap").goto_() end, desc = "Go to Line (No Execute)" }, + { "", function() require("dap").step_into() end, desc = "Step Into" }, + { "dj", function() require("dap").down() end, desc = "Down" }, + { "dk", function() require("dap").up() end, desc = "Up" }, + { "dl", function() require("dap").run_last() end, desc = "Run Last" }, + { "", function() require("dap").step_out() end, desc = "Step Out" }, + { "", function() require("dap").step_over() end, desc = "Step Over" }, + { "dP", function() require("dap").pause() end, desc = "Pause" }, + { "dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" }, + { "ds", function() require("dap").session() end, desc = "Session" }, + { "", function() require("dap").terminate() end, desc = "Terminate" }, + { "dw", function() require("dap.ui.widgets").hover() end, desc = "Widgets" }, + }, + }, + { + 'rcarriga/nvim-dap-ui', + dependencies = { 'nvim-neotest/nvim-nio' }, + -- stylua: ignore + keys = { + { "du", function() require("dapui").toggle({ }) end, desc = "Dap UI" }, + { "de", function() require("dapui").eval() end, desc = "Eval", mode = {"n", "v"} }, + }, + opts = {}, + config = function(_, opts) + local dap = require 'dap' + local mason_registry = require 'mason-registry' + local codelldb = mason_registry.get_package 'codelldb' + local ext_path = codelldb:get_install_path() .. '/extension/' + local codelldb_path = ext_path .. 'adapter/codelldb' + local liblldb_path = ext_path .. 'lldb/lib/liblldb.dylib' + local dapui = require 'dapui' + dapui.setup(opts) + dap.listeners.after.event_initialized['dapui_config'] = function() + dapui.open {} + end + dap.listeners.before.event_terminated['dapui_config'] = function() + dapui.close {} + end + dap.listeners.before.event_exited['dapui_config'] = function() + dapui.close {} + end + dap.adapters.lldb = { + type = 'executable', + command = codelldb_path, -- adjust as needed, must be absolute path + name = 'lldb', + } + + dap.adapters.cpp = { + type = 'executable', + attach = { + pidProperty = 'pid', + pidSelect = 'ask', + }, + command = codelldb_path, + env = { + LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY = 'YES', + }, + name = 'lldb', + } + + dap.configurations.cpp = { + { + name = 'lldb', + type = 'cpp', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/Binaries/App/App.exe', 'file') + end, + cwd = '${workspaceFolder}', + externalTerminal = false, + stopOnEntry = false, + args = {}, + }, + } + end, + }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! @@ -992,5 +1090,7 @@ require('telescope').setup { }, }, } +vim.fn.sign_define('DapBreakpoint', { text = '🛑', texthl = '', linehl = '', numhl = '' }) +vim.keymap.set('n', 'rn', vim.lsp.buf.rename, {}) -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et