144 lines
4.3 KiB
Lua
144 lines
4.3 KiB
Lua
-- local dap = require('dap')
|
|
-- dap.adapters.python = function(cb, config)
|
|
-- if config.request == 'attach' then
|
|
-- ---@diagnostic disable-next-line: undefined-field
|
|
-- local port = (config.connect or config).port
|
|
-- ---@diagnostic disable-next-line: undefined-field
|
|
-- local host = (config.connect or config).host or '127.0.0.1'
|
|
-- cb({
|
|
-- type = 'server',
|
|
-- port = assert(port, '`connect.port` is required for a python `attach` configuration'),
|
|
-- host = host,
|
|
-- options = {
|
|
-- source_filetype = 'python',
|
|
-- },
|
|
-- })
|
|
-- else
|
|
-- cb({
|
|
-- type = 'executable',
|
|
-- command = 'path/to/virtualenvs/debugpy/bin/python',
|
|
-- args = { '-m', 'debugpy.adapter' },
|
|
-- options = {
|
|
-- source_filetype = 'python',
|
|
-- },
|
|
-- })
|
|
-- end
|
|
-- end
|
|
local dap = require("dap")
|
|
dap.adapters.lldb = {
|
|
type = "executable",
|
|
command = "lldb-dap",
|
|
name = 'lldb',
|
|
-- args = { "--interpreter=dap", "--eval-command", "set print pretty on" }
|
|
}
|
|
|
|
auto_python_path = function ()
|
|
local cwd = vim.fn.getcwd()
|
|
if vim.fn.executable(cwd .. '/venv/bin/python') == 1 then
|
|
return cwd .. '/venv/bin/python'
|
|
elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then
|
|
return cwd .. '/.venv/bin/python'
|
|
elseif vim.fn.executable('/usr/bin/python') == 1 then
|
|
return '/usr/bin/python'
|
|
else
|
|
return '/bin/python'
|
|
end
|
|
end
|
|
|
|
local python_path = auto_python_path()
|
|
|
|
get_path = function()
|
|
vim.ui.select({'./venv/bin/python', '/usr/bin/python'}, {
|
|
prompt = "Choose a python variable",
|
|
}, function(selected) python_path = selected end)
|
|
end
|
|
|
|
dap.adapters.python = function(cb, config)
|
|
if config.request == 'attach' then
|
|
---@diagnostic disable-next-line: undefined-field
|
|
local port = (config.connect or config).port
|
|
---@diagnostic disable-next-line: undefined-field
|
|
local host = (config.connect or config).host or '127.0.0.1'
|
|
cb({
|
|
type = 'server',
|
|
port = assert(port, '`connect.port` is required for a python `attach` configuration'),
|
|
host = host,
|
|
options = {
|
|
source_filetype = 'python',
|
|
},
|
|
})
|
|
else
|
|
cb({
|
|
type = 'executable',
|
|
command = python_path,
|
|
args = { '-m', 'debugpy.adapter' },
|
|
options = {
|
|
source_filetype = 'python',
|
|
},
|
|
})
|
|
end
|
|
end
|
|
|
|
|
|
dap.configurations.python = {
|
|
{
|
|
-- The first three options are required by nvim-dap
|
|
type = 'python'; -- the type here established the link to the adapter definition: `dap.adapters.python`
|
|
request = 'launch';
|
|
name = "Launch file";
|
|
|
|
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
|
|
|
|
program = "${file}"; -- This configuration will launch the current file if used.
|
|
pythonPath = python_path },
|
|
}
|
|
|
|
dap.configurations.cpp = {
|
|
{
|
|
name = 'Launch',
|
|
type = 'lldb',
|
|
request = 'launch',
|
|
program = function()
|
|
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
|
|
end,
|
|
cwd = '${workspaceFolder}',
|
|
stopOnEntry = true,
|
|
args = {},
|
|
},
|
|
}
|
|
require("nvim-dap-virtual-text").setup()
|
|
local dap = require("dap")
|
|
|
|
dap.configurations.c = dap.configurations.cpp
|
|
dap.configurations.rust = dap.configurations.cpp
|
|
|
|
require("dapui").setup()
|
|
|
|
local dapui = require("dapui")
|
|
dap.listeners.before.attach.dapui_config = function()
|
|
dapui.open()
|
|
end
|
|
dap.listeners.before.launch.dapui_config = function()
|
|
dapui.open()
|
|
end
|
|
dap.listeners.before.event_terminated.dapui_config = function()
|
|
dapui.close()
|
|
end
|
|
dap.listeners.before.event_exited.dapui_config = function()
|
|
dapui.close()
|
|
end
|
|
|
|
|
|
|
|
vim.keymap.set("n", "<leader>tb", "<cmd>DapToggleBreakpoint<CR>",{ desc = '[t]oggle [b]reakpoint' })
|
|
vim.keymap.set("n", "<leader>dn", "<cmd>DapNew<CR>",{ desc = '[d]ebugger [n]ew' })
|
|
vim.keymap.set("n", "<leader>dps", get_path,{ desc = '[d]ebugger [p]ython [s]elect' })
|
|
vim.keymap.set("n", "<F1>", "<cmd>DapContinue<CR>",{ desc = 'continuej:Da' })
|
|
vim.keymap.set("n", "<F2>", "<cmd>DapStepInto<CR>",{ desc = 'step into' })
|
|
vim.keymap.set("n", "<F3>", "<cmd>DapStepOver<CR>",{ desc = 'step over' })
|
|
vim.keymap.set("n", "<F4>", "<cmd>DapStepOut<CR>",{ desc = 'step out' })
|
|
-- vim.keymap.set("n", "<F5>", "<cmd>DapStepOut<CR>",{ desc = 'step out' })
|
|
vim.keymap.set("n", "<F6>", "<cmd>DapDisconnect<CR>",{ desc = 'disconnect' })
|
|
|
|
|