]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/dap.lua
nvim: telescope sort buffers by last first
[dotfiles.git] / nvim / lua / plugins / dap.lua
1 return {
2 "mfussenegger/nvim-dap",
3
4 dependencies = {
5 -- fancy UI for the debugger
6 {
7 "rcarriga/nvim-dap-ui",
8 -- stylua: ignore
9 keys = {
10 { "<leader>du", function() require("dapui").toggle({ }) end, desc = "Dap UI" },
11 { "<leader>de", function() require("dapui").eval() end, desc = "Eval", mode = {"n", "v"} },
12 },
13 opts = {},
14 config = function(_, opts)
15 local dap = require("dap")
16 local dapui = require("dapui")
17 dapui.setup(opts)
18 dap.listeners.after.event_initialized["dapui_config"] = function()
19 dapui.open({})
20 end
21 dap.listeners.before.event_terminated["dapui_config"] = function()
22 dapui.close({})
23 end
24 dap.listeners.before.event_exited["dapui_config"] = function()
25 dapui.close({})
26 end
27 end,
28 },
29
30 -- virtual text for the debugger
31 {
32 "theHamsta/nvim-dap-virtual-text",
33 opts = {},
34 },
35
36 -- which key integration
37 {
38 "folke/which-key.nvim",
39 opts = {
40 defaults = {
41 ["<leader>d"] = { name = "+debug" },
42 ["<leader>da"] = { name = "+adapters" },
43 },
44 },
45 },
46
47 -- mason.nvim integration
48 {
49 "jay-babu/mason-nvim-dap.nvim",
50 dependencies = "mason.nvim",
51 cmd = { "DapInstall", "DapUninstall" },
52 opts = {
53 -- Makes a best effort to setup the various debuggers with
54 -- reasonable debug configurations
55 automatic_setup = true,
56
57 -- You can provide additional configuration to the handlers,
58 -- see mason-nvim-dap README for more information
59 handlers = {},
60
61 -- You'll need to check that you have the required things installed
62 -- online, please don't ask me how to install them :)
63 ensure_installed = {
64 "cpptools",
65 },
66 },
67 config = function(_, opts)
68 require("mason-nvim-dap").setup(opts)
69 local dap = require("dap")
70 dap.configurations.cpp = {
71 {
72 name = "Launch file",
73 type = "cppdbg",
74 request = "launch",
75 program = function()
76 return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
77 end,
78 cwd = "${workspaceFolder}",
79 stopAtEntry = true,
80 },
81 }
82 end,
83 },
84
85 {
86 "jbyuki/one-small-step-for-vimkind",
87 -- stylua: ignore
88 keys = {
89 { "<leader>daL", function() require("osv").launch({ port = 8086 }) end, desc = "Adapter Lua Server" },
90 { "<leader>dal", function() require("osv").run_this() end, desc = "Adapter Lua" },
91 },
92 config = function()
93 local dap = require("dap")
94 dap.adapters.nlua = function(callback, config)
95 callback({ type = "server", host = config.host or "127.0.0.1", port = config.port or 8086 })
96 end
97 dap.configurations.lua = {
98 {
99 type = "nlua",
100 request = "attach",
101 name = "Attach to running Neovim instance",
102 },
103 }
104 end,
105 },
106 },
107
108 -- stylua: ignore
109 keys = {
110 { "<leader>dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" },
111 { "<leader>db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" },
112 { "<leader>dc", function() require("dap").continue() end, desc = "Continue" },
113 { "<leader>dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" },
114 { "<leader>dg", function() require("dap").goto_() end, desc = "Go to line (no execute)" },
115 { "<leader>di", function() require("dap").step_into() end, desc = "Step Into" },
116 { "<leader>dj", function() require("dap").down() end, desc = "Down" },
117 { "<leader>dk", function() require("dap").up() end, desc = "Up" },
118 { "<leader>dl", function() require("dap").run_last() end, desc = "Run Last" },
119 { "<leader>do", function() require("dap").step_out() end, desc = "Step Out" },
120 { "<leader>dO", function() require("dap").step_over() end, desc = "Step Over" },
121 { "<leader>dp", function() require("dap").pause() end, desc = "Pause" },
122 { "<leader>dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" },
123 { "<leader>ds", function() require("dap").session() end, desc = "Session" },
124 { "<leader>dt", function() require("dap").terminate() end, desc = "Terminate" },
125 { "<leader>dw", function() require("dap.ui.widgets").hover() end, desc = "Widgets" },
126 },
127
128 config = function()
129 local Config = require("lazyvim.config")
130 vim.api.nvim_set_hl(0, "DapStoppedLine", { default = true, link = "Visual" })
131
132 for name, sign in pairs(Config.icons.dap) do
133 sign = type(sign) == "table" and sign or { sign }
134 vim.fn.sign_define(
135 "Dap" .. name,
136 { text = sign[1], texthl = sign[2] or "DiagnosticInfo", linehl = sign[3], numhl = sign[3] }
137 )
138 end
139 end,
140 }