@@ -11,7 +11,7 @@ local uv = vim.uv or vim.loop
11
11
--- ```
12
12
--- require('dap-python').test_runner = "pytest"
13
13
--- ```
14
- --- @type ( string | fun (): string ) name of the test runner
14
+ --- @type string | fun (): string name of the test runner
15
15
M .test_runner = nil
16
16
17
17
@@ -26,7 +26,7 @@ M.resolve_python = nil
26
26
--- Built-in are test runners for unittest, pytest and django.
27
27
--- The key is the test runner name, the value a function to generate the
28
28
--- module name to run and its arguments. See |dap-python.TestRunner|
29
- --- @type table<string , TestRunner>
29
+ --- @type table<string , dap-python. TestRunner>
30
30
M .test_runners = {}
31
31
32
32
@@ -90,6 +90,7 @@ local function default_runner()
90
90
end
91
91
92
92
93
+ --- @return string | nil
93
94
local get_python_path = function ()
94
95
local venv_path = os.getenv (' VIRTUAL_ENV' )
95
96
if venv_path then
@@ -123,8 +124,11 @@ local get_python_path = function()
123
124
end
124
125
125
126
127
+ --- @param config dap-python.Config | dap-python.LaunchConfig
128
+ --- @param on_config fun ( config : dap-python.Config )
126
129
local enrich_config = function (config , on_config )
127
130
if not config .pythonPath and not config .python then
131
+ --- @diagnostic disable-next-line : inject-field
128
132
config .pythonPath = get_python_path ()
129
133
end
130
134
on_config (config )
@@ -164,6 +168,7 @@ local function flatten(...)
164
168
if vim .iter then
165
169
return vim .iter (values ):flatten (2 ):totable ()
166
170
end
171
+ --- @diagnostic disable-next-line : deprecated
167
172
return vim .tbl_flatten (values )
168
173
end
169
174
@@ -202,11 +207,11 @@ end
202
207
203
208
204
209
--- 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 )
208
213
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'
210
215
opts = vim .tbl_extend (' keep' , opts or {}, default_setup_opts )
211
216
dap .adapters .python = function (cb , config )
212
217
if config .request == ' attach' then
@@ -226,7 +231,7 @@ function M.setup(adapter_python_path, opts)
226
231
else
227
232
cb ({
228
233
type = ' executable' ;
229
- command = adapter_python_path ;
234
+ command = python_path ;
230
235
args = { ' -m' , ' debugpy.adapter' };
231
236
enrich_config = enrich_config ;
232
237
options = {
@@ -317,6 +322,7 @@ local function reverse(list)
317
322
end
318
323
319
324
325
+ --- @private
320
326
--- @param source string | integer
321
327
--- @param subject " function" | " class"
322
328
--- @param end_row integer ? defaults to cursor
392
398
393
399
--- @param classnames string[]
394
400
--- @param methodname string ?
395
- --- @param opts DebugOpts
401
+ --- @param opts dap-python.debug_opts
396
402
local function trigger_test (classnames , methodname , opts )
397
403
local test_runner = opts .test_runner or (M .test_runner or default_runner )
398
404
if type (test_runner ) == " function" then
420
426
421
427
422
428
--- 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 |
424
430
function M .test_class (opts )
425
431
opts = vim .tbl_extend (' keep' , opts or {}, default_test_opts )
426
432
local candidates = M ._get_nodes (0 , " class" )
452
458
453
459
454
460
--- 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 |
456
462
function M .test_method (opts )
457
463
opts = vim .tbl_extend (' keep' , opts or {}, default_test_opts )
458
464
local functions = M ._get_nodes (0 , " function" )
471
477
--
472
478
-- >>> remove_indent({' print(10)', ' if True:', ' print(20)'})
473
479
-- {'print(10)', 'if True:', ' print(20)'}
480
+ --- @param lines string[]
481
+ --- @return string[]
474
482
local function remove_indent (lines )
475
483
local offset = nil
476
484
for _ , line in ipairs (lines ) do
489
497
490
498
491
499
--- Debug the selected code
492
- --- @param opts ? DebugOpts
500
+ --- @param opts ? dap-python.debug_opts
493
501
function M .debug_selection (opts )
494
502
opts = vim .tbl_extend (' keep' , opts or {}, default_test_opts )
495
503
local start_row , _ = unpack (api .nvim_buf_get_mark (0 , ' <' ))
@@ -507,47 +515,52 @@ end
507
515
508
516
509
517
510
- --- @class PathMapping
518
+ --- @class dap-python. PathMapping
511
519
--- @field localRoot string
512
520
--- @field remoteRoot string
513
521
514
522
515
- --- @class DebugpyConfig
523
+ --- @class dap-python.Config
516
524
--- @field django boolean | nil Enable django templates. Default is ` false`
517
525
--- @field gevent boolean | nil Enable debugging of gevent monkey-patched code. Default is ` false`
518
526
--- @field jinja boolean | nil Enable jinja2 template debugging. Default is ` false`
519
527
--- @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.
521
529
--- @field pyramid boolean | nil Enable debugging of pyramid applications
522
530
--- @field redirectOutput boolean | nil Redirect output to debug console. Default is ` false`
523
531
--- @field showReturnValue boolean | nil Shows return value of function when stepping
524
532
--- @field sudo boolean | nil Run program under elevated permissions. Default is ` false`
525
533
526
- --- @class DebugpyLaunchConfig : DebugpyConfig
534
+
535
+ --- @class dap-python.LaunchConfig : dap-python.Config
527
536
--- @field module string | nil Name of the module to debug
528
537
--- @field program string | nil Absolute path to the program
529
538
--- @field code string | nil Code to execute in string form
530
539
--- @field python string[] | nil Path to python executable and interpreter arguments
531
540
--- @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 |
533
542
--- @field cwd string | nil Absolute path to the working directory of the program being debugged.
534
543
--- @field env table | nil Environment variables defined as key value pair
535
544
--- @field stopOnEntry boolean | nil Stop at first line of user code.
536
545
537
546
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
542
551
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
547
559
548
560
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[]
550
563
551
- --- @alias DebugpyConsole " internalConsole" | " integratedTerminal" | " externalTerminal" | nil
564
+ --- @alias dap-python.console ' internalConsole' | ' integratedTerminal' | ' externalTerminal' | nil
552
565
553
566
return M
0 commit comments