mirror of
https://github.com/macocianradu/setup.git
synced 2026-03-18 21:00:04 +00:00
added test debugging
This commit is contained in:
@@ -15,7 +15,7 @@ dap.listeners.after.event_exited["dapui_config"] = function()
|
||||
dapui.close()
|
||||
end
|
||||
|
||||
require("dap-python").setup("~/Projects/odoo/venv/bin/python3")
|
||||
require("dap-python").setup("~/projects/odoo/venv/bin/python3")
|
||||
dap.adapters['pwa-chrome'] = {
|
||||
type = 'server',
|
||||
host = 'localhost',
|
||||
@@ -29,6 +29,72 @@ dap.adapters['pwa-chrome'] = {
|
||||
}
|
||||
}
|
||||
|
||||
local function run_odoo_test_at_cursor()
|
||||
-- Safely get the node at cursor
|
||||
local status, node = pcall(vim.treesitter.get_node)
|
||||
if not status or not node then
|
||||
print("Error: Tree-sitter parser not found. Ensure you are in a Python buffer.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Safety Limit: Prevent infinite loop if tree is malformed
|
||||
local attempts = 0
|
||||
while node do
|
||||
if node:type() == 'function_definition' then
|
||||
break
|
||||
end
|
||||
node = node:parent()
|
||||
attempts = attempts + 1
|
||||
if attempts > 50 then
|
||||
print("Error: Could not find function definition (traversal limit reached).")
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if not node then
|
||||
print("Cursor is not inside a function definition.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Extract function name safely
|
||||
local func_name = nil
|
||||
for child in node:iter_children() do
|
||||
if child:type() == 'identifier' then
|
||||
func_name = vim.treesitter.get_node_text(child, 0)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not func_name then
|
||||
print("Error: Could not extract function name.")
|
||||
return
|
||||
end
|
||||
|
||||
local db = vim.fn.input("Database: ")
|
||||
if db == nil or db == "" then
|
||||
print("Canceled (no database provided).")
|
||||
return
|
||||
end
|
||||
|
||||
print("Launching Debugger for: " .. func_name)
|
||||
|
||||
dap.run({
|
||||
type = "python",
|
||||
request = "launch",
|
||||
name = "Debug Test: " .. func_name,
|
||||
pythonPath = "/home/admac/projects/odoo/venv/bin/python3",
|
||||
program = "/home/admac/projects/odoo/odoo/odoo-bin",
|
||||
args = {
|
||||
"--addons-path", "/home/admac/projects/odoo/enterprise/,/home/admac/projects/odoo/odoo/addons/",
|
||||
"-d", db,
|
||||
"--log-level=warn",
|
||||
"--test-tags", "." .. func_name,
|
||||
"--stop-after-init",
|
||||
},
|
||||
console = "externalTerminal",
|
||||
})
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<leader>5", function() dap.continue() end)
|
||||
vim.keymap.set("n", "<leader>6", function() dap.step_over() end)
|
||||
vim.keymap.set("n", "<leader>+", function() dap.step_into() end)
|
||||
@@ -37,18 +103,19 @@ vim.keymap.set("n", "<leader>b", function() dap.toggle_breakpoint() end)
|
||||
vim.keymap.set("n", "<leader>B", function() dap.set_breakpoint(vim.fn.input("Breakpoint condition: ")) end)
|
||||
vim.keymap.set("n", "<leader>qd", function() dap.terminate() end)
|
||||
vim.keymap.set("n", "<leader>rd", function() dap.restart() end)
|
||||
vim.keymap.set("n", "<leader>dt", run_odoo_test_at_cursor, { desc = "Debug Odoo Test unde Cursor" })
|
||||
|
||||
dap.configurations.python = {
|
||||
{
|
||||
type = "python",
|
||||
request = "launch",
|
||||
name = "Launch Odoo",
|
||||
program = "/home/odoo/Projects/odoo/odoo/odoo-bin",
|
||||
program = "/home/admac/projects/odoo/odoo/odoo-bin",
|
||||
pythonPath = function()
|
||||
return "/home/odoo/Projects/odoo/venv/bin/python3"
|
||||
return "/home/admac/projects/odoo/venv/bin/python3"
|
||||
end,
|
||||
args = {
|
||||
"--addons-path", "/home/odoo/Projects/odoo/enterprise/,/home/odoo/Projects/odoo/odoo/addons/",
|
||||
"--addons-path", "/home/admac/projects/odoo/enterprise/,/home/admac/projects/odoo/odoo/addons/",
|
||||
"--dev", "all",
|
||||
"-d", "rd-pos"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user