You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.9 KiB
Lua
108 lines
2.9 KiB
Lua
local status_ok, dap = pcall(require, "dap")
|
|
if not status_ok then
|
|
return
|
|
end
|
|
|
|
local decode_json_file = function(filename)
|
|
if vim.fn.filereadable(filename) == 0 then
|
|
return nil
|
|
end
|
|
|
|
return vim.fn.json_decode(vim.fn.readfile(filename))
|
|
end
|
|
|
|
-- returns dap_args
|
|
local function pdap_clangd_init(root_dir)
|
|
root_dir = root_dir:gsub('"', '')
|
|
local pclangd_path = root_dir .. "/.pclangd"
|
|
local pclangd = decode_json_file(pclangd_path) -- tbl
|
|
local dap_args = pclangd["dap_args"]
|
|
dap.adapters.cppdbg = {
|
|
id = 'cppdbg',
|
|
type = 'executable',
|
|
command = '/storage/Shared/Documents/vscode-cpptools/extension/debugAdapters/bin/OpenDebugAD7',
|
|
}
|
|
dap.configurations.cpp = {
|
|
name = "Launch file",
|
|
type = "cppdbg",
|
|
request = "launch",
|
|
targetArchitecture = "arm",
|
|
miDebuggerPath = "/usr/bin/arm-none-eabi-gdb",
|
|
program = dap_args.build_dir .. "/" .. dap_args.program_name,
|
|
args = dap_args.args,
|
|
cwd = '${workspaceFolder}',
|
|
stopOnEntry = true,
|
|
}
|
|
|
|
dap.configurations.c = dap.configurations.cpp
|
|
vim.fn.sign_define('DapBreakpoint', {text='🛑', texthl='', linehl='', numhl=''})
|
|
end
|
|
|
|
--
|
|
--
|
|
-- local before_dap_setup = function()
|
|
-- -- need to get project root by finding ancestor containing .pclangd from cwd
|
|
-- local util = require("lspconfig/util")
|
|
-- local path = util.path
|
|
-- local dot_clangd = path.join(vim.fn.getcwd(), ".pclangd")
|
|
-- local tbl = decode_json_file(dot_clangd)
|
|
--
|
|
--
|
|
-- -- Example .pclangd config
|
|
-- -- {
|
|
-- -- "clangd_args":
|
|
-- -- {
|
|
-- -- "toolchain": "gcc",
|
|
-- -- "build_dir": "build"
|
|
-- -- },
|
|
-- -- "dap_args":
|
|
-- -- {
|
|
-- -- "program_name": "udp_server",
|
|
-- -- "args": ["10010"],
|
|
-- -- "build_dir": "build"
|
|
-- -- }
|
|
-- --
|
|
-- -- }
|
|
--
|
|
-- local clients = vim.lsp.get_active_clients()
|
|
-- local thingy = clients[0].root_dir
|
|
-- vim.api.nvim_err_writeln("Here we go " .. thingy)
|
|
-- local dap_args = tbl["dap_args"]
|
|
-- return dap_args
|
|
-- end
|
|
--
|
|
-- -- dap.adapters.cppdbg = {
|
|
-- -- id = 'cppdbg',
|
|
-- -- type = 'executable',
|
|
-- -- command = '/storage/Shared/Documents/vscode-cpptools/extension/debugAdapters/bin/OpenDebugAD7',
|
|
-- -- }
|
|
-- -- dap.configurations.cpp = {
|
|
-- -- name = "Launch file",
|
|
-- -- type = "cppdbg",
|
|
-- -- request = "launch",
|
|
-- -- -- program = function()
|
|
-- -- -- return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
|
|
-- -- -- end,
|
|
-- --
|
|
-- -- -- dap_args.build_dir can be wrong sometimes. I need to be able to get the root directory from lspconfig
|
|
-- -- -- but idk how to do that
|
|
-- -- program = dap_args.build_dir .. "/" .. dap_args.program_name,
|
|
-- -- args = dap_args.args,
|
|
-- -- cwd = '${workspaceFolder}',
|
|
-- -- stopOnEntry = true,
|
|
-- -- }
|
|
-- --
|
|
-- -- dap.configurations.c = dap.configurations.cpp
|
|
-- -- vim.fn.sign_define('DapBreakpoint', {text='🛑', texthl='', linehl='', numhl=''})
|
|
--
|
|
--
|
|
-- --return dap
|
|
--
|
|
--
|
|
|
|
return
|
|
{
|
|
pdap_clangd_init = pdap_clangd_init,
|
|
dap = dap
|
|
}
|