refactor(dap): ensure run_last fetches the latest configuration by name#1582
refactor(dap): ensure run_last fetches the latest configuration by name#1582kwdiwt wants to merge 1 commit intomfussenegger:masterfrom
Conversation
mfussenegger
left a comment
There was a problem hiding this comment.
This would break re-running dynamically generated configurations that are directly used via dap.run(config). It isn't ensured that a configuration that was run is also part of the config providers result set.
A common example use-case for that is debugging individual unit tests.
The change here could be tweaked to use the last_run config as fallback same as before, but even then I'm not sure the logic change here is desired.
(And it would also need to run in a coroutine to honor the providers contract)
Leaving it open for a while to gather more feedback.
|
or add M.run_last_by_name ? |
I'm not to keen on adding different versions of the function. If so I'd rather tend to a But before that I'd like to see more interest in this. In the meantime you can as workaround also add a custom version in your dotfiles with something like: local dap = require("dap")
local last_config = nil
---@param session Session
dap.listeners.after.event_initialized["store_config"] = function(session)
last_config = session.config
end
function M.run_last()
if last_config then
-- resolve config like in this PR
else
dap.continue()
end
end |
The current implementation of run_last caches the configuration object from the previous session. This leads to "stale" runs if the user modifies their launch.json or if a dynamic configuration provider updates its values (e.g., changing an environment variable from "RUN_MODE": "a" to "b").
Example Case: When debugging a Python module with a launch.json like this:
{ "version": "0.2.0", "configurations": [ { "name": "main", "type": "debugpy", "request": "launch", "module": "mobile.main", "env": { "RUN_MODE": "a", } } }If the user changes "RUN_MODE" to "b", the updated run_last will correctly pick up the new environment variable without requiring the user to re-select the configuration manually.