feat: add dap args

This commit is contained in:
Rónán Carrigan
2022-02-06 21:37:21 +00:00
parent a02e6d5acb
commit 49ed805750
2 changed files with 39 additions and 25 deletions

View File

@@ -17,7 +17,7 @@ M.module_exists = function(module, python_command)
return lib.process.run(vim.tbl_flatten({
python_command,
"-c",
"import imp; imp.find_module('"..module.."')",
"import imp; imp.find_module('" .. module .. "')",
})) == 0
end
@@ -56,25 +56,4 @@ function M.parse_positions(file_path)
return lib.treesitter.parse_positions(file_path, query)
end
function M.get_strategy_config(strategy, python, python_script, args)
local config = {
dap = function()
return {
type = "python",
name = "Neotest Debugger",
request = "launch",
python = python,
program = python_script,
cwd = async.fn.getcwd(),
args = args,
justMyCode= false,
}
end,
}
if config[strategy] then
return config[strategy]()
end
end
return M

View File

@@ -10,6 +10,27 @@ end
local python_script = (Path.new(script_path()):parent():parent() / "neotest.py").filename
local dap_args
local function get_strategy_config(strategy, python, python_script, args)
local config = {
dap = function()
return vim.tbl_extend("keep", {
type = "python",
name = "Neotest Debugger",
request = "launch",
python = python,
program = python_script,
cwd = async.fn.getcwd(),
args = args,
}, dap_args or {})
end,
}
if config[strategy] then
return config[strategy]()
end
end
local get_args = function(runner, position)
if runner == "unittest" then
runner = "pyunit"
@@ -97,12 +118,18 @@ function PythonNeotestAdapter.build_spec(args)
python_script,
script_args,
})
local strategy_config = get_strategy_config(
args.strategy,
python,
python_script,
script_args
)
return {
command = command,
context = {
results_path = results_path,
},
strategy = base.get_strategy_config(args.strategy, python, python_script, script_args),
strategy = strategy_config,
}
end
@@ -111,11 +138,11 @@ end
---@param result NeotestStrategyResult
---@return NeotestResult[]
function PythonNeotestAdapter.results(spec, result)
-- TODO: Find out if this JSON option is supported in future
local success, data = pcall(lib.files.read, spec.context.results_path)
if not success then
data = "{}"
end
-- TODO: Find out if this JSON option is supported in future
local results = vim.json.decode(data, { luanil = { object = true } })
for _, pos_result in pairs(results) do
result.output_path = pos_result.output_path
@@ -123,6 +150,10 @@ function PythonNeotestAdapter.results(spec, result)
return results
end
local is_callable = function(obj)
return type(obj) == "function" or (type(obj) == "table" and obj.__call)
end
setmetatable(PythonNeotestAdapter, {
__call = function(_, opts)
if type(opts.args) == "function" or (type(opts.args) == "table" and opts.args.__call) then
@@ -132,13 +163,17 @@ setmetatable(PythonNeotestAdapter, {
return opts.args
end
end
if type(opts.runner) == "function" or (type(opts.runner) == "table" and opts.runner.__call) then
if is_callable(opts.runner) then
get_runner = opts.runner
elseif opts.runner then
get_runner = function()
return opts.runner
end
end
if type(opts.dap) == "table" then
dap_args = opts.dap
end
return PythonNeotestAdapter
end,
})