]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/dap.lua
vim: do not set pastetoggle in nvim
[dotfiles.git] / nvim / lua / plugins / dap.lua
1 ---@param config {type?:string, 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 {} --[[@as string[] | string ]]
4 local args_str = type(args) == "table" and table.concat(args, " ") or args --[[@as string]]
5
6 config = vim.deepcopy(config)
7 ---@cast args string[]
8 config.args = function()
9 local new_args = vim.fn.expand(vim.fn.input("Run with args: ", args_str)) --[[@as string]]
10 return require("dap.utils").splitstr(new_args)
11 end
12 return config
13 end
14
15 return {
16 { "mfussenegger/nvim-dap",
17 dependencies = {
18 "rcarriga/nvim-dap-ui",
19 { "theHamsta/nvim-dap-virtual-text", -- virtual text for the debugger
20 opts = {},
21 },
22 },
23
24 -- stylua: ignore
25 keys = {
26 { "<leader>dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" },
27 { "<leader>db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" },
28 { "<leader>dc", function() require("dap").continue() end, desc = "Run/Continue" },
29 { "<leader>da", function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" },
30 { "<leader>dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" },
31 { "<C-T>", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" },
32 { "<leader>dg", function() require("dap").goto_() end, desc = "Go to Line (No Execute)" },
33 { "<leader>di", function() require("dap").step_into() end, desc = "Step Into" },
34 { "<C-S>", function() require("dap").step_into() end, desc = "Step Into" },
35 { "<leader>dj", function() require("dap").down() end, desc = "Down" },
36 { "<leader>dk", function() require("dap").up() end, desc = "Up" },
37 { "<leader>dl", function() require("dap").run_last() end, desc = "Run Last" },
38 { "<leader>do", function() require("dap").step_out() end, desc = "Step Out" },
39 { "<C-F>", function() require("dap").step_out() end, desc = "Step Over" },
40 { "<leader>dO", function() require("dap").step_over() end, desc = "Step Over" },
41 { "<C-N>", function() require("dap").step_over() end, desc = "Step Over" },
42 { "<leader>dP", function() require("dap").pause() end, desc = "Pause" },
43 { "<leader>dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" },
44 { "<leader>ds", function() require("dap").session() end, desc = "Session" },
45 { "<leader>dt", function() require("dap").terminate() end, desc = "Terminate" },
46 { "<leader>dw", function() require("dap.ui.widgets").hover() end, desc = "Widgets" },
47 },
48
49 config = function()
50 -- load mason-nvim-dap here, after all adapters have been setup
51 require("mason-nvim-dap").setup(rmz.lazy.opts("mason-nvim-dap.nvim"))
52
53 vim.api.nvim_set_hl(0, "DapStoppedLine", { default = true, link = "Visual" })
54
55 for name, sign in pairs(rmz.ui.icons.dap) do
56 sign = type(sign) == "table" and sign or { sign } ---@cast sign table
57 vim.fn.sign_define(
58 "Dap" .. name,
59 { text = sign[1], texthl = sign[2] or "DiagnosticInfo", linehl = sign[3], numhl = sign[3] }
60 )
61 end
62
63 -- setup dap config by VsCode launch.json file
64 local vscode = require("dap.ext.vscode")
65 local json = require("plenary.json")
66 vscode.json_decode = function(str)
67 return vim.json.decode(json.json_strip_comments(str))
68 end
69 end,
70 },
71 { "mason.nvim",
72 opts = {
73 log_level = vim.log.levels.TRACE,
74 }
75 },
76 { "rcarriga/nvim-dap-ui", -- fancy UI for the debugger
77 dependencies = { "nvim-neotest/nvim-nio" },
78 -- stylua: ignore
79 keys = {
80 { "<leader>du", function() require("dapui").toggle({ }) end, desc = "Dap UI" },
81 { "<leader>de", function() require("dapui").eval() end, desc = "Eval", mode = {"n", "v"} },
82 },
83 opts = {},
84 config = function(_, opts)
85 local dap = require("dap")
86 local dapui = require("dapui")
87 dapui.setup(opts)
88 dap.listeners.after.event_initialized["dapui_config"] = function()
89 dapui.open({})
90 end
91 end,
92 },
93 -- mason.nvim integration
94 { "jay-babu/mason-nvim-dap.nvim",
95 dependencies = "mason.nvim",
96 cmd = { "DapInstall", "DapUninstall" },
97 opts_extend = { "ensure_installed" },
98 opts = {
99 automatic_installation = true,
100 handlers = {},
101 ensure_installed = { },
102 },
103 -- mason-nvim-dap is loaded when nvim-dap loads
104 config = function() end,
105 },
106 }