@@ -11,7 +11,7 @@ local uv = vim.uv or vim.loop
1111--- ```
1212--- require('dap-python').test_runner = "pytest"
1313--- ```
14- --- @type ( string | fun (): string ) name of the test runner
14+ --- @type string | fun (): string name of the test runner
1515M .test_runner = nil
1616
1717
@@ -26,7 +26,7 @@ M.resolve_python = nil
2626--- Built-in are test runners for unittest, pytest and django.
2727--- The key is the test runner name, the value a function to generate the
2828--- module name to run and its arguments. See |dap-python.TestRunner|
29- --- @type table<string , TestRunner>
29+ --- @type table<string , dap-python. TestRunner>
3030M .test_runners = {}
3131
3232
@@ -90,6 +90,7 @@ local function default_runner()
9090end
9191
9292
93+ --- @return string | nil
9394local get_python_path = function ()
9495 local venv_path = os.getenv (' VIRTUAL_ENV' )
9596 if venv_path then
@@ -123,8 +124,11 @@ local get_python_path = function()
123124end
124125
125126
127+ --- @param config dap-python.Config | dap-python.LaunchConfig
128+ --- @param on_config fun ( config : dap-python.Config )
126129local enrich_config = function (config , on_config )
127130 if not config .pythonPath and not config .python then
131+ --- @diagnostic disable-next-line : inject-field
128132 config .pythonPath = get_python_path ()
129133 end
130134 on_config (config )
@@ -164,6 +168,7 @@ local function flatten(...)
164168 if vim .iter then
165169 return vim .iter (values ):flatten (2 ):totable ()
166170 end
171+ --- @diagnostic disable-next-line : deprecated
167172 return vim .tbl_flatten (values )
168173end
169174
@@ -202,11 +207,11 @@ end
202207
203208
204209--- Register the python debug adapter
205- --- @param adapter_python_path string | nil Path to the python interpreter. Path must be absolute or in $PATH and needs to have the debugpy package installed. Default is ` python3`
206- --- @param opts SetupOpts | nil See | dap-python.SetupOpts |
207- function M .setup (adapter_python_path , opts )
210+ --- @param python_path string | nil Path to the python interpreter. Path must be absolute or in $PATH and needs to have the debugpy package installed. Default is ` python3`
211+ --- @param opts ? dap-python.setup.opts See | dap-python.setup.opts |
212+ function M .setup (python_path , opts )
208213 local dap = load_dap ()
209- adapter_python_path = adapter_python_path and vim .fn .expand (vim .fn .trim (adapter_python_path ), true ) or ' python3'
214+ python_path = python_path and vim .fn .expand (vim .fn .trim (python_path ), true ) or ' python3'
210215 opts = vim .tbl_extend (' keep' , opts or {}, default_setup_opts )
211216 dap .adapters .python = function (cb , config )
212217 if config .request == ' attach' then
@@ -226,7 +231,7 @@ function M.setup(adapter_python_path, opts)
226231 else
227232 cb ({
228233 type = ' executable' ;
229- command = adapter_python_path ;
234+ command = python_path ;
230235 args = { ' -m' , ' debugpy.adapter' };
231236 enrich_config = enrich_config ;
232237 options = {
@@ -317,6 +322,7 @@ local function reverse(list)
317322end
318323
319324
325+ --- @private
320326--- @param source string | integer
321327--- @param subject " function" | " class"
322328--- @param end_row integer ? defaults to cursor
392398
393399--- @param classnames string[]
394400--- @param methodname string ?
395- --- @param opts DebugOpts
401+ --- @param opts dap-python.debug_opts
396402local function trigger_test (classnames , methodname , opts )
397403 local test_runner = opts .test_runner or (M .test_runner or default_runner )
398404 if type (test_runner ) == " function" then
420426
421427
422428--- Run test class above cursor
423- --- @param opts ? DebugOpts See | dap-python.DebugOpts |
429+ --- @param opts ? dap-python.debug_opts See | dap-python.debug_opts |
424430function M .test_class (opts )
425431 opts = vim .tbl_extend (' keep' , opts or {}, default_test_opts )
426432 local candidates = M ._get_nodes (0 , " class" )
452458
453459
454460--- Run the test method above cursor
455- --- @param opts ? DebugOpts See | dap-python.DebugOpts |
461+ --- @param opts ? dap-python.debug_opts See | dap-python.debug_opts |
456462function M .test_method (opts )
457463 opts = vim .tbl_extend (' keep' , opts or {}, default_test_opts )
458464 local functions = M ._get_nodes (0 , " function" )
471477--
472478-- >>> remove_indent({' print(10)', ' if True:', ' print(20)'})
473479-- {'print(10)', 'if True:', ' print(20)'}
480+ --- @param lines string[]
481+ --- @return string[]
474482local function remove_indent (lines )
475483 local offset = nil
476484 for _ , line in ipairs (lines ) do
489497
490498
491499--- Debug the selected code
492- --- @param opts ? DebugOpts
500+ --- @param opts ? dap-python.debug_opts
493501function M .debug_selection (opts )
494502 opts = vim .tbl_extend (' keep' , opts or {}, default_test_opts )
495503 local start_row , _ = unpack (api .nvim_buf_get_mark (0 , ' <' ))
@@ -507,47 +515,52 @@ end
507515
508516
509517
510- --- @class PathMapping
518+ --- @class dap-python. PathMapping
511519--- @field localRoot string
512520--- @field remoteRoot string
513521
514522
515- --- @class DebugpyConfig
523+ --- @class dap-python.Config
516524--- @field django boolean | nil Enable django templates. Default is ` false`
517525--- @field gevent boolean | nil Enable debugging of gevent monkey-patched code. Default is ` false`
518526--- @field jinja boolean | nil Enable jinja2 template debugging. Default is ` false`
519527--- @field justMyCode boolean | nil Debug only user-written code. Default is ` true`
520- --- @field pathMappings PathMapping[] | nil Map of local and remote paths.
528+ --- @field pathMappings dap-python. PathMapping[]| nil Map of local and remote paths.
521529--- @field pyramid boolean | nil Enable debugging of pyramid applications
522530--- @field redirectOutput boolean | nil Redirect output to debug console. Default is ` false`
523531--- @field showReturnValue boolean | nil Shows return value of function when stepping
524532--- @field sudo boolean | nil Run program under elevated permissions. Default is ` false`
525533
526- --- @class DebugpyLaunchConfig : DebugpyConfig
534+
535+ --- @class dap-python.LaunchConfig : dap-python.Config
527536--- @field module string | nil Name of the module to debug
528537--- @field program string | nil Absolute path to the program
529538--- @field code string | nil Code to execute in string form
530539--- @field python string[] | nil Path to python executable and interpreter arguments
531540--- @field args string[] | nil Command line arguments passed to the program
532- --- @field console DebugpyConsole See | dap-python.DebugpyConsole |
541+ --- @field console dap-python.console See | dap-python.console |
533542--- @field cwd string | nil Absolute path to the working directory of the program being debugged.
534543--- @field env table | nil Environment variables defined as key value pair
535544--- @field stopOnEntry boolean | nil Stop at first line of user code.
536545
537546
538- --- @class DebugOpts
539- --- @field console DebugpyConsole See | dap-python.DebugpyConsole |
540- --- @field test_runner " unittest" | " pytest" | " django" | string name of the test runner. Default is | dap-python.test_runner |
541- --- @field config DebugpyConfig Overrides for the configuration
547+ --- @class dap-python.debug_opts
548+ --- @field console ? dap-python.console
549+ --- @field test_runner ? " unittest" | " pytest" | " django" | string name of the test runner
550+ --- @field config ? dap-python.Config Overrides for the configuration
542551
543- --- @class SetupOpts
544- --- @field include_configs boolean Add default configurations
545- --- @field console DebugpyConsole See | dap-python.DebugpyConsole |
546- --- @field pythonPath string | nil Path to python interpreter. Uses interpreter from ` VIRTUAL_ENV` environment variable or ` adapter_python_path` by default
552+ --- @class dap-python.setup.opts
553+ --- @field include_configs ? boolean Add default configurations
554+ --- @field console ? dap-python.console
555+ ---
556+ --- Path to python interpreter. Uses interpreter from `VIRTUAL_ENV` environment
557+ --- variable or `python_path` by default
558+ --- @field pythonPath ? string
547559
548560
549- --- @alias TestRunner fun ( classname : string | string[] , methodname : string ?): string , string[]
561+ --- A function receiving classname and methodname; must return module to run and its arguments
562+ --- @alias dap-python.TestRunner fun ( classname : string | string[] , methodname : string ?): string , string[]
550563
551- --- @alias DebugpyConsole " internalConsole" | " integratedTerminal" | " externalTerminal" | nil
564+ --- @alias dap-python.console ' internalConsole' | ' integratedTerminal' | ' externalTerminal' | nil
552565
553566return M
0 commit comments