2024-09-26 04:58:13 +02:00
|
|
|
if vim.g.did_load_c_plugin then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
vim.g.did_load_c_plugin = true
|
|
|
|
|
2024-03-06 18:55:22 +01:00
|
|
|
-- Exit if the language server isn't available
|
|
|
|
if vim.fn.executable('clangd') ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-09-23 23:22:44 +02:00
|
|
|
-- require'lspconfig'.clangd.setup{}
|
2024-09-19 01:24:20 +02:00
|
|
|
|
2024-09-23 23:22:44 +02:00
|
|
|
local root_files = {
|
2024-03-06 18:55:22 +01:00
|
|
|
'compile_commands.json',
|
|
|
|
'.vscode',
|
|
|
|
'.git',
|
|
|
|
}
|
|
|
|
|
|
|
|
vim.lsp.start {
|
|
|
|
name = 'clangd',
|
|
|
|
cmd = { 'clangd' },
|
|
|
|
root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]),
|
|
|
|
capabilities = require('user.lsp').make_client_capabilities(),
|
2024-09-26 04:58:13 +02:00
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
require("nvim-navic").attach(client, bufnr)
|
|
|
|
end
|
|
|
|
}
|
2024-03-06 23:07:22 +01:00
|
|
|
|
|
|
|
local dap = require("dap")
|
2024-09-23 23:22:44 +02:00
|
|
|
local pickers = require("telescope.pickers")
|
|
|
|
local finders = require("telescope.finders")
|
|
|
|
local conf = require("telescope.config").values
|
|
|
|
local actions = require("telescope.actions")
|
|
|
|
local action_state = require("telescope.actions.state")
|
2024-03-06 23:07:22 +01:00
|
|
|
|
|
|
|
if require('user.file_exists').file_exists(vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]) .. "/.vscode/launch.json") then
|
|
|
|
require("dap.ext.vscode").load_launchjs(nil, { cppdbg = { "c", "cpp", "asm" } })
|
|
|
|
end
|
|
|
|
|
|
|
|
dap.adapters.gdb = {
|
|
|
|
type = "executable",
|
|
|
|
command = "gdb",
|
|
|
|
args = { "-i", "dap" }
|
|
|
|
}
|
|
|
|
|
2024-09-25 23:57:17 +02:00
|
|
|
dap.adapters.cppdbg = {
|
|
|
|
id = 'cppdbg',
|
|
|
|
type = 'executable',
|
|
|
|
command = 'OpenDebugAD7',
|
|
|
|
}
|
|
|
|
|
2024-03-06 23:07:22 +01:00
|
|
|
dap.configurations.c = {
|
|
|
|
{
|
2024-09-23 23:22:44 +02:00
|
|
|
name = "Launch an executable",
|
2024-09-25 23:57:17 +02:00
|
|
|
type = "cppdbg",
|
2024-03-06 23:07:22 +01:00
|
|
|
request = "launch",
|
2024-09-23 23:22:44 +02:00
|
|
|
cwd = "${workspaceFolder}",
|
2024-03-06 23:07:22 +01:00
|
|
|
program = function()
|
2024-09-23 23:22:44 +02:00
|
|
|
return coroutine.create(function(coro)
|
|
|
|
local opts = {}
|
|
|
|
pickers
|
|
|
|
.new(opts, {
|
|
|
|
prompt_title = "Path to executable",
|
|
|
|
finder = finders.new_oneshot_job({ "fd", "--hidden", "--no-ignore", "--type", "x" }, {}),
|
|
|
|
sorter = conf.generic_sorter(opts),
|
|
|
|
attach_mappings = function(buffer_number)
|
|
|
|
actions.select_default:replace(function()
|
|
|
|
actions.close(buffer_number)
|
|
|
|
coroutine.resume(coro, action_state.get_selected_entry()[1])
|
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
:find()
|
|
|
|
end)
|
2024-03-06 23:07:22 +01:00
|
|
|
end,
|
2024-09-25 23:57:17 +02:00
|
|
|
stopAtBeginningOfMainSubprogram = true,
|
2024-03-06 23:07:22 +01:00
|
|
|
},
|
2024-03-06 18:55:22 +01:00
|
|
|
}
|