]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/dap.lua
e12e8fba568b591f6f60dbe2addab82b0ab4b911
[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 },
43 },
44 },
45
46 -- mason.nvim integration
47 {
48 "jay-babu/mason-nvim-dap.nvim",
49 dependencies = "mason.nvim",
50 cmd = { "DapInstall", "DapUninstall" },
51 opts = {
52 -- Makes a best effort to setup the various debuggers with
53 -- reasonable debug configurations
54 automatic_installation = true,
55
56 -- You can provide additional configuration to the handlers,
57 -- see mason-nvim-dap README for more information
58 handlers = {},
59 },
60 },
61 {
62 "jbyuki/one-small-step-for-vimkind",
63 -- stylua: ignore
64 keys = {
65 { "<leader>daL", function() require("osv").launch({ port = 8086 }) end, desc = "Adapter Lua Server" },
66 { "<leader>dal", function() require("osv").run_this() end, desc = "Adapter Lua" },
67 },
68 config = function()
69 local dap = require("dap")
70 dap.adapters.nlua = function(callback, config)
71 local adapter = {
72 type = "server",
73 host = config.host or "127.0.0.1",
74 port = config.port or 8086,
75 }
76 if config.start_neovim then
77 local dap_run = dap.run
78 dap.run = function(c)
79 adapter.port = c.port
80 adapter.host = c.host
81 end
82 require("osv").run_this()
83 dap.run = dap_run
84 end
85 callback(adapter)
86 end
87 dap.configurations.lua = {
88 {
89 type = "nlua",
90 request = "attach",
91 name = "Run this file",
92 start_neovim = {},
93 },
94 {
95 type = "nlua",
96 request = "attach",
97 name = "Attach to running Neovim instance (port 8086)",
98 port = 8086,
99 },
100 }
101 end,
102 },
103 },
104
105 -- stylua: ignore
106 keys = {
107 { "<leader>dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" },
108 { "<leader>db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" },
109 { "<leader>dc", function() require("dap").continue() end, desc = "Continue" },
110 { "<leader>dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" },
111 { "<C-T>", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" },
112 { "<leader>dg", function() require("dap").goto_() end, desc = "Go to line (no execute)" },
113 { "<leader>di", function() require("dap").step_into() end, desc = "Step Into" },
114 { "<C-S>", function() require("dap").step_into() end, desc = "Step Into" },
115 { "<leader>dj", function() require("dap").down() end, desc = "Down" },
116 { "<leader>dk", function() require("dap").up() end, desc = "Up" },
117 { "<leader>dl", function() require("dap").run_last() end, desc = "Run Last" },
118 { "<leader>do", function() require("dap").step_out() end, desc = "Step Out" },
119 { "<C-F>", function() require("dap").step_out() end, desc = "Step Over" },
120 { "<leader>dO", function() require("dap").step_over() end, desc = "Step Over" },
121 { "<C-N>", function() require("dap").step_over() end, desc = "Step Over" },
122 { "<leader>dp", function() require("dap").pause() end, desc = "Pause" },
123 { "<leader>dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" },
124 { "<leader>ds", function() require("dap").session() end, desc = "Session" },
125 { "<leader>dt", function() require("dap").terminate() end, desc = "Terminate" },
126 { "<leader>dw", function() require("dap.ui.widgets").hover() end, desc = "Widgets" },
127 },
128
129 config = function()
130 local Config = require("lazyvim.config")
131 vim.api.nvim_set_hl(0, "DapStoppedLine", { default = true, link = "Visual" })
132
133 for name, sign in pairs(Config.icons.dap) do
134 sign = type(sign) == "table" and sign or { sign }
135 vim.fn.sign_define(
136 "Dap" .. name,
137 { text = sign[1], texthl = sign[2] or "DiagnosticInfo", linehl = sign[3], numhl = sign[3] }
138 )
139 end
140 end,
141 }