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