From 8f0b088886ba3064bdecb33a35d978748b740af0 Mon Sep 17 00:00:00 2001 From: jiriks74 Date: Wed, 6 Mar 2024 23:07:22 +0100 Subject: [PATCH] feat: basic nvim-dap setup --- nvim/ftplugin/c.lua | 26 +++++++++++++++++++++++++- nvim/lua/user/file_exists.lua | 8 ++++++++ nvim/plugin/dap.lua | 5 +++++ nvim/plugin/plugins.lua | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 nvim/lua/user/file_exists.lua create mode 100644 nvim/plugin/dap.lua diff --git a/nvim/ftplugin/c.lua b/nvim/ftplugin/c.lua index bee7ef7..b3cf061 100644 --- a/nvim/ftplugin/c.lua +++ b/nvim/ftplugin/c.lua @@ -14,5 +14,29 @@ vim.lsp.start { cmd = { 'clangd' }, root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), capabilities = require('user.lsp').make_client_capabilities(), - -- capabilities = { offsetEncoding = "utf-8" }, +} + +local dap = require("dap") + +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" } +} + +dap.configurations.c = { + { + name = "Launch", + type = "gdb", + request = "launch", + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = "${workspaceFolder}", + stopAtBeginningOfMainSubprogram = false, + }, } diff --git a/nvim/lua/user/file_exists.lua b/nvim/lua/user/file_exists.lua new file mode 100644 index 0000000..961116d --- /dev/null +++ b/nvim/lua/user/file_exists.lua @@ -0,0 +1,8 @@ +local F = {} + +function F.file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end +end + +return F diff --git a/nvim/plugin/dap.lua b/nvim/plugin/dap.lua new file mode 100644 index 0000000..f536beb --- /dev/null +++ b/nvim/plugin/dap.lua @@ -0,0 +1,5 @@ +if vim.g.did_load_dap_plugin then + return +end +vim.g.did_load_dap_plugin = true + diff --git a/nvim/plugin/plugins.lua b/nvim/plugin/plugins.lua index 3429409..401b4a9 100644 --- a/nvim/plugin/plugins.lua +++ b/nvim/plugin/plugins.lua @@ -6,6 +6,7 @@ vim.g.did_load_plugins_plugin = true -- many plugins annoyingly require a call to a 'setup' function to be loaded, -- even with default configs +require("dapui").setup() require("copilot_cmp").setup() require('nvim-surround').setup() require('which-key').setup()