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