]> git.rmz.io Git - dotfiles.git/commitdiff
nvim: run with args keymap
authorSamir Benmendil <me@rmz.io>
Sat, 20 Jan 2024 17:08:46 +0000 (17:08 +0000)
committerSamir Benmendil <me@rmz.io>
Wed, 21 Feb 2024 01:26:30 +0000 (01:26 +0000)
nvim/lua/plugins/dap.lua

index e12e8fba568b591f6f60dbe2addab82b0ab4b911..da88369a1df9a0a65ba55b4f658dabfca65b8c41 100644 (file)
@@ -1,3 +1,15 @@
+---@param config {args?:string[]|fun():string[]?}
+local function get_args(config)
+  local args = type(config.args) == "function" and (config.args() or {}) or config.args or {}
+  config = vim.deepcopy(config)
+  ---@cast args string[]
+  config.args = function()
+    local new_args = vim.fn.input("Run with args: ", table.concat(args, " ")) --[[@as string]]
+    return vim.split(vim.fn.expand(new_args) --[[@as string]], " ")
+  end
+  return config
+end
+
 return {
   "mfussenegger/nvim-dap",
 
@@ -107,6 +119,7 @@ return {
     { "<leader>dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" },
     { "<leader>db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" },
     { "<leader>dc", function() require("dap").continue() end, desc = "Continue" },
+    { "<leader>da", function() require("dap").continue({ before = get_args }) end, desc = "Run with Args" },
     { "<leader>dC", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" },
     { "<C-T>", function() require("dap").run_to_cursor() end, desc = "Run to Cursor" },
     { "<leader>dg", function() require("dap").goto_() end, desc = "Go to line (no execute)" },