Skip to content

Commit 679762e

Browse files
committed
Support opts.config as function
Instead of adding overrides this allows extending the generated config dynamically. For example to profile a test case using `cProfile` one could use a `config` like this for `test_method`: config = function(config) local newconfig = vim.deepcopy(config) newconfig.module = "cProfile" newconfig.args = { "-m", config.module } vim.list_extend(newconfig.args, config.args) return newconfig end
1 parent 84e89ad commit 679762e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lua/dap-python.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,16 @@ local function trigger_test(classnames, methodname, opts)
456456
args = args,
457457
console = opts.console
458458
}
459-
load_dap().run(vim.tbl_extend('force', config, opts.config or {}))
459+
local opts_config = opts.config or {}
460+
if type(opts_config) == "function" then
461+
config = opts_config(config)
462+
elseif type(opts_config) == "table" then
463+
config = vim.tbl_extend("force", config, opts_config)
464+
else
465+
error("opts.config must be a table, got: " .. type(opts_config))
466+
end
467+
---@cast config dap.Configuration
468+
load_dap().run(config)
460469
end
461470

462471

@@ -582,7 +591,7 @@ end
582591
---@class dap-python.debug_opts
583592
---@field console? dap-python.console
584593
---@field test_runner? "unittest"|"pytest"|"django"|string name of the test runner
585-
---@field config? dap-python.Config Overrides for the configuration
594+
---@field config? dap-python.Config|fun(config:dap-python.Config):dap-python.Config Overrides for the configuration
586595

587596
---@class dap-python.setup.opts
588597
---@field include_configs? boolean Add default configurations

0 commit comments

Comments
 (0)