mirror of
https://github.com/macocianradu/setup.git
synced 2026-03-18 21:00:04 +00:00
115 lines
3.2 KiB
Lua
115 lines
3.2 KiB
Lua
local dap = require("dap")
|
|
|
|
local M = {}
|
|
|
|
require("dap-python").setup("~/projects/odoo/venv/bin/python3")
|
|
dap.adapters['pwa-chrome'] = {
|
|
type = 'server',
|
|
host = 'localhost',
|
|
port = '${port}',
|
|
executable = {
|
|
command = 'node',
|
|
args = {
|
|
vim.fn.stdpath('data') .. '/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js',
|
|
'${port}',
|
|
},
|
|
}
|
|
}
|
|
|
|
local function is_odoo_project()
|
|
local cwd = vim.fn.getcwd()
|
|
return vim.fn.filereadable(cwd .. "/odoo-bin") == 1 or
|
|
vim.fn.filereadable(cwd .. "/odoo/odoo-bin") == 1
|
|
end
|
|
|
|
local function debug_odoo()
|
|
local db_name = vim.fn.input('Odoo DB: ', 'master')
|
|
if db_name == "" then return end
|
|
|
|
dap.run({
|
|
type = "python",
|
|
request = "launch",
|
|
name = "Odoo Server",
|
|
program = "/home/admac/projects/odoo/odoo/odoo-bin",
|
|
pythonPath = "/home/admac/projects/odoo/venv/bin/python3",
|
|
args = {
|
|
"--addons-path", "/home/admac/projects/odoo/enterprise/,/home/admac/projects/odoo/odoo/addons/",
|
|
"--dev", "all",
|
|
"-d", db_name
|
|
},
|
|
console = "externalTerminal",
|
|
})
|
|
end
|
|
|
|
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
|
|
|
|
M.is_odoo_project = is_odoo_project
|
|
M.debug_odoo = debug_odoo
|
|
M.run_odoo_test_at_cursor = run_odoo_test_at_cursor
|
|
|
|
return M
|