From 533d663e87d7fc65d9de43292a4fb822181e433a Mon Sep 17 00:00:00 2001 From: Antoine Vaure Date: Sun, 22 Dec 2024 19:34:20 +0100 Subject: [PATCH] Update the dap mappings, add lsp indicator in bar, use default dapui layout --- lua/configs/dap.lua | 37 +++++++++++++++++++-- lua/configs/lualine.lua | 9 ++++- lua/mappings.lua | 48 +++++++++++++++++---------- lua/plugins.lua | 73 +++++++++++++++++++++++++++++++++-------- 4 files changed, 131 insertions(+), 36 deletions(-) diff --git a/lua/configs/dap.lua b/lua/configs/dap.lua index 1ccb2d6..271eb6e 100644 --- a/lua/configs/dap.lua +++ b/lua/configs/dap.lua @@ -4,14 +4,34 @@ local dap = require("dap") -- name = "Launch", -- type = "gdb", -- request = "launch", --- program = function() --- return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') --- end, +-- -- program = function() +-- -- return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') +-- -- end, -- cwd = "${workspaceFolder}", -- }, -- } +-- +-- dap.configurations.cpp = { +-- { +-- name = "Launch file", +-- type = "cppdbg", +-- request = "launch", +-- program = function() +-- return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') +-- end, +-- cwd = '${workspaceFolder}', +-- stopAtEntry = true, +-- } +-- } dap.adapters.cppdbg = { + id = 'cppdbg', + type = 'executable', + command = '/nix/store/gwags66qlqr6qmblwp0v6crkb6ca2qr1-vscode-extension-ms-vscode-cpptools-1.22.2/share/vscode/extensions/ms-vscode.cpptools/debugAdapters/bin/OpenDebugAD7', + cwd = "${workspaceFolder}", +} + +dap.adapters.gdb = { type = "executable", command = "gdb", args = { "-i", "dap" }, @@ -54,7 +74,18 @@ end require('dap.ext.vscode').load_launchjs("dap_config.json", { cppdbg = { 'c', 'cpp' }, lldb = { 'c', 'cpp' }, + gdb = { 'c', 'cpp' }, debugpy = { 'python' } }) dap.set_log_level("TRACE") + +-- require("telescope").load_extension("dap") +-- Interface Setup +vim.fn.sign_define('DapBreakpoint', { text='', texthl='red'}) +vim.fn.sign_define('DapBreakpointCondition', { text='', texthl='blue'}) +vim.fn.sign_define('DapBreakpointRejected', { text='', texthl='orange'}) +vim.fn.sign_define('DapStopped', { text='󰁕', texthl='green'}) +vim.fn.sign_define('DapLogPoint', { text='.>', texthl='yellow', linehl='DapBreakpoint', numhl='DapBreakpoint' }) + +vim.api.nvim_command 'autocmd FileType dap-float nnoremap q close!' diff --git a/lua/configs/lualine.lua b/lua/configs/lualine.lua index 04b0d72..919f421 100644 --- a/lua/configs/lualine.lua +++ b/lua/configs/lualine.lua @@ -28,7 +28,14 @@ local opts = { -- cond = require("noice").api.status.mode.has, -- }, }, - lualine_x = { 'diagnostics', 'filetype' }, + lualine_x = { + function() + -- invoke `progress` here. + return require('lsp-progress').progress() + end, + 'diagnostics', + 'filetype', + }, lualine_y = { 'progress' }, lualine_z = { 'location' } }, diff --git a/lua/mappings.lua b/lua/mappings.lua index 0674d87..030c444 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -87,6 +87,8 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) vim.keymap.set('n', 'gr', telescope.lsp_references, opts) vim.keymap.set({ 'n', 'v' }, 'fm', ":Format", opts) + vim.keymap.set('n', '', ' :lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', '', ' :lua vim.lsp.buf.hover()', opts) end, }) @@ -124,6 +126,14 @@ local dap_sb_session = dap_widgets.sidebar(dap_widgets.sessions) local dap_sb_threads = dap_widgets.sidebar(dap_widgets.threads) vim.keymap.set('n', 'b', dap.toggle_breakpoint, { desc = "Toggle breakpoint" }) +vim.keymap.set('n', 'B', +function () + local condition = vim.fn.input("Condition: ", "") + dap.set_breakpoint(condition) +end +, { desc = "Add conditional breakpoint" }) + +local dapui = require("dapui") local Hydra = require("hydra") Hydra({ @@ -133,10 +143,12 @@ Hydra({ color = "pink", invoke_on_body = true, on_enter = function() + dapui.open() dap.continue() -- dap.repl.open() end, on_exit = function() + dapui.close() dap.terminate() dap_sb_frames.close() dap_sb_scopes.close() @@ -145,27 +157,27 @@ Hydra({ dap.repl.close() end, hint = { - type = "window", + type = "statusline", }, }, - mode = 'n', - body = 'g', + mode = { 'n', 'v' }, + body = 'gg', heads = { - { 'c', dap.continue, { desc = "Continue" } }, - { 'r', dap.restart, { desc = "Restart" } }, - -- { 'i', dap.pause, { desc = "Pause" } }, - { 'I', nil, {} }, - { 's', dap.step_into, { desc = "Step into" } }, - { 'a', dap.step_over, { desc = "Step over" } }, - { 'A', dap.step_out, { desc = "Step out" } }, - { 'x', dap.repl.toggle, { desc = "repl" } }, - { 't', dap_sb_threads.toggle, { desc = "Threads" } }, - { 'f', dap_sb_frames.toggle, { desc = "Frames" } }, - { 'v', dap_sb_scopes.toggle, { desc = "Scopes" } }, - -- { 'z', dap_sb_session.toggle, { desc = "Session" } }, - { 'K', dap_widgets.hover, { desc = "Hover" } }, - { 'D', dap.up, { desc = "Up" } }, - { 'd', dap.down, { desc = "Down" } }, + { '', dap.continue, { desc = "Continue" } }, + { '', dap.restart, { desc = "Restart" } }, + { '', dap.step_into, { desc = "Step into" } }, + { '', dap.step_over, { desc = "Step over" } }, + { '', dap.step_out, { desc = "Step out" } }, + { '', dap.run_to_cursor, { desc = "Run to cursor" } }, + { '', dap.step_back, { desc = "Step back" } }, + { 'K', require("dapui").eval, { desc = "Hover" } }, + { '', dap.up, { desc = "Up" } }, + { '', dap.down, { desc = "Down" } }, + -- right click to eval + { '', dapui.eval, { desc = "Eval", mode = "v" } }, + { '', ' :lua require("dapui").eval()', { + desc = "Eval", + } }, { 'q', nil, { exit = true, nowait = true, desc = 'Exit' } }, } }) diff --git a/lua/plugins.lua b/lua/plugins.lua index 6bb632f..7454ab3 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -72,11 +72,11 @@ local plugins = { HopNextKey = { bg = C.text, fg = C.base, style = { "bold", "underline" } }, HopNextKey1 = { bg = C.text, fg = C.base, style = { "bold" } }, HopNextKey2 = { bg = C.text, fg = C.base, style = { "bold", "italic" } }, - DiagnosticUnderlineError = { style = { "undercurl" }}, - DiagnosticUnderlineWarn = { style = { "undercurl" }}, - DiagnosticUnderlineInfo = { style = { "undercurl" }}, - DiagnosticUnderlineHint = { style = { "undercurl" }}, - DiagnosticUnderlineOk = { style = { "undercurl" }}, + DiagnosticUnderlineError = { style = { "undercurl" } }, + DiagnosticUnderlineWarn = { style = { "undercurl" } }, + DiagnosticUnderlineInfo = { style = { "undercurl" } }, + DiagnosticUnderlineHint = { style = { "undercurl" } }, + DiagnosticUnderlineOk = { style = { "undercurl" } }, -- Function = { fg = C.blue, style = { "bold" } }, -- Keyword = { fg = C.black, style = { "italic" } }, } @@ -231,12 +231,38 @@ local plugins = { }, { "rmagatti/auto-session", + dependencies = { + "niuiic/dap-utils.nvim", + dependencies = { + "niuiic/core.nvim", + "mfussenegger/nvim-dap", + "rcarriga/nvim-dap-ui", + "nvim-telescope/telescope.nvim", + } + }, config = function() require("auto-session").setup({ log_level = "error", + pre_save_cmds = { + function() + require("dap-utils").store_breakpoints("./.breakpoints") + end + }, + post_restore_cmds = { + function() + require("dap-utils").restore_breakpoints("./.breakpoints") + end + }, + pre_delete_cmds = { + }, }) end, }, + -- { + -- 'niuiic/multiple-session.nvim', + -- dependencies = { 'niuiic/core.nvim' }, + -- config = function () require("multiple-session").setup() end + -- }, -- Lua -- { -- "olimorris/persisted.nvim", @@ -492,20 +518,31 @@ local plugins = { } }, }, - -- { - -- "rcarriga/nvim-dap-ui", - -- dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" }, - -- config = function() - -- require("configs.dap") - -- require("dapui").setup() - -- end - -- }, + { + "rcarriga/nvim-dap-ui", + dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" }, + config = function() + require("dapui").setup() + end + }, + { + "mfussenegger/nvim-dap", + config = function() + require("configs.dap") + end + }, + { "nvim-neotest/nvim-nio" }, + { + 'linrongbin16/lsp-progress.nvim', + config = function() + require('lsp-progress').setup() + end + }, { "theHamsta/nvim-dap-virtual-text", lazy = false, dependencies = { "mfussenegger/nvim-dap", "nvim-treesitter/nvim-treesitter" }, config = function() - require("configs.dap") require("nvim-dap-virtual-text").setup() end }, @@ -594,6 +631,14 @@ local plugins = { config = function() require 'treesitter-context'.setup {} end + }, + { + 'Weissle/persistent-breakpoints.nvim', + config = function() + require('persistent-breakpoints').setup { + load_breakpoints_event = { "BufReadPost" } + } + end } }