Skip to content

refactor(dap): ensure run_last fetches the latest configuration by name#1582

Open
kwdiwt wants to merge 1 commit intomfussenegger:masterfrom
kwdiwt:master
Open

refactor(dap): ensure run_last fetches the latest configuration by name#1582
kwdiwt wants to merge 1 commit intomfussenegger:masterfrom
kwdiwt:master

Conversation

@kwdiwt
Copy link
Copy Markdown

@kwdiwt kwdiwt commented Jan 10, 2026

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.

Copy link
Copy Markdown
Owner

@mfussenegger mfussenegger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kwdiwt
Copy link
Copy Markdown
Author

kwdiwt commented Jan 11, 2026

or add M.run_last_by_name ?

@mfussenegger
Copy link
Copy Markdown
Owner

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 opts parameter that adds options to control the behavior. There have also been requests for showing a list of recent configurations, or to avoid re-evaluation of function properties.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants