From 02301591585fc7cb96911e24dad2ac31c892c023 Mon Sep 17 00:00:00 2001 From: devxpain <170700110+devxpain@users.noreply.github.com> Date: Sat, 30 Nov 2024 17:11:14 +0800 Subject: [PATCH] feat(dap-python): add cwd option to setup opts This commit introduces a `cwd` option to `dap-python.setup.opts`, enabling users to specify the working directory for debug sessions. - Useful for projects with complex directory structures. - Default value is `nil` to preserve existing behavior. --- doc/dap-python.txt | 1 + lua/dap-python.lua | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/doc/dap-python.txt b/doc/dap-python.txt index 9ea6c12..4c759b6 100644 --- a/doc/dap-python.txt +++ b/doc/dap-python.txt @@ -110,6 +110,7 @@ dap-python.setup.opts *dap-python.setup.opts* Fields: ~ {include_configs?} (boolean) Add default configurations {console?} (dap-python.console) + {cwd?} (string|function|nil) Working directory for the debug session. {pythonPath?} (string) Path to python interpreter. Uses interpreter from `VIRTUAL_ENV` environment variable or `python_path` by default diff --git a/lua/dap-python.lua b/lua/dap-python.lua index 06a2be7..32cfaf1 100644 --- a/lua/dap-python.lua +++ b/lua/dap-python.lua @@ -138,6 +138,7 @@ end local default_setup_opts = { include_configs = true, console = 'integratedTerminal', + cwd = nil, pythonPath = nil, } @@ -276,6 +277,7 @@ function M.setup(python_path, opts) name = 'file'; program = '${file}'; console = opts.console; + cwd = opts.cwd, pythonPath = opts.pythonPath, }) table.insert(configs, { @@ -292,6 +294,7 @@ function M.setup(python_path, opts) return vim.split(args_string, " +") end; console = opts.console; + cwd = opts.cwd, pythonPath = opts.pythonPath, }) table.insert(configs, { @@ -313,6 +316,7 @@ function M.setup(python_path, opts) args = { "${file}" }, noDebug = true, console = opts.console, + cwd = opts.cwd, pythonPath = opts.pythonPath, }) end @@ -576,6 +580,7 @@ end ---@class dap-python.setup.opts ---@field include_configs? boolean Add default configurations ---@field console? dap-python.console +---@field cwd? string|function|nil Working directory for the debug session. Default is `nil` --- --- Path to python interpreter. Uses interpreter from `VIRTUAL_ENV` environment --- variable or `python_path` by default