ITADN

Reproducing the last pre-processed config in `run_last`

#1579ClosedZenithFlux 创建于 2026-01-04
Z
ZenithFluxcommented
### Problem Statement I have written a function that asks the user for the arguments to put in the `dap.configuration` before running the debugger. To achieve this, I am using `__call` metamethod: ```lua setmetatable(dap.configurations.python[1], { __call = function(c) local args vim.ui.input({ prompt = "Start debugging on: " }, function(cmd_text) if cmd_text == nil then args = nil else args = require("utils").split_cmd_args(cmd_text) end end) if args ~= nil and #args == 0 then return c end c = vim.deepcopy(c, true) setmetatable(c, nil) if args == nil then c["program"] = require("dap").ABORT elseif args[1] == "-m" then c["module"] = args[2] c["program"] = nil c["args"] = table.move(args, 3, #args, 1, {}) else c["module"] = nil c["program"] = args[1] c["args"] = table.move(args, 2, #args, 1, {}) end return c end, }) ``` This works perfectly when `run`, but the issue is that this function is called again even if a `run_last` is called after. I would like the previously generated config to be reused when `run_last` is called, without prompting the user. I tried all the config preprocessing methods I could find, like `enrich_config`, the `on_config` listener, and the `before` option in `run`, but every one of them is called again in `run_last`. Also, there is no context provided to any of these functions if they are called due to `run_last` or not. This makes it impossible to differentiate in the preprocessing between direct `run` and `run_last`. If there is an existing way to solve this, please guide me. ### Possible Solutions We need a way to replicate the last produced configuration. We can either store the preprocessed config in `last_run`, or pass an argument to the functions to inform them if this is a rerun, so that the functions can themselves return the last config. If this can be done with a simple patch, I can provide the patch myself. ### Considered Alternatives _No response_
关闭于 2026-01-04 2 条评论