From 4b6091d8e9ebd9cc3976e2152eb7df9bda35898d Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Mon, 28 Feb 2022 17:11:38 +1100 Subject: [PATCH] Add debug configuration to NVIM --- dot_config/nvim/init.lua | 12 +++++++-- dot_config/nvim/lua/lang/debug.lua | 29 ++++++++++++++++++++++ dot_config/nvim/lua/options.lua | 6 +++++ dot_config/nvim/lua/plugins/appearance.lua | 1 + dot_config/nvim/lua/plugins/keymap.lua | 12 ++++++++- 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 dot_config/nvim/lua/lang/debug.lua diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua index 9d51cec..8d89482 100644 --- a/dot_config/nvim/init.lua +++ b/dot_config/nvim/init.lua @@ -27,7 +27,10 @@ return require('packer').startup(function(use) use { 'SmiteshP/nvim-gps', -- Status line requires = 'nvim-treesitter/nvim-treesitter', - config = function() require("nvim-gps").setup({ disable_icons = true }) end, + config = function() require("nvim-gps").setup({ + disable_icons = true, + depth = 3, + }) end, } use { 'nvim-lualine/lualine.nvim', -- Status line @@ -72,6 +75,10 @@ return require('packer').startup(function(use) require('lang.zinc') end, } + use { + 'mfussenegger/nvim-dap', + config = require('lang.debug').conf_debug, + } use { 'pianocomposer321/yabs.nvim', -- Build System config = require('lang.build').conf_yabs, @@ -85,8 +92,9 @@ return require('packer').startup(function(use) 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-nvim-lua', - 'hrsh7th/vim-vsnip', + 'hrsh7th/cmp-vsnip', -- Further Requirements + 'hrsh7th/vim-vsnip', 'nvim-lua/plenary.nvim' }, config = require('plugins.completion').conf_cmp, diff --git a/dot_config/nvim/lua/lang/debug.lua b/dot_config/nvim/lua/lang/debug.lua new file mode 100644 index 0000000..036f01d --- /dev/null +++ b/dot_config/nvim/lua/lang/debug.lua @@ -0,0 +1,29 @@ +-- DAP +function conf_debug() + local dap = require('dap') + dap.adapters.lldb = { + type = 'executable', + command = '/opt/homebrew/opt/llvm/bin/lldb-vscode', -- adjust as needed + name = "lldb" + } + 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 = false, + args = {}, + runInTerminal = false, + }, + } + -- Use the same configuration for C and Rust + dap.configurations.c = dap.configurations.cpp + dap.configurations.rust = dap.configurations.cpp + +end + +return { conf_debug = conf_debug } diff --git a/dot_config/nvim/lua/options.lua b/dot_config/nvim/lua/options.lua index 8efdfe9..fcb0a04 100644 --- a/dot_config/nvim/lua/options.lua +++ b/dot_config/nvim/lua/options.lua @@ -82,6 +82,12 @@ vim.opt.tabstop = 2 vim.opt.smartindent = true vim.opt.expandtab = false +-- Code Folding +vim.opt.foldmethod = 'expr' +vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' +vim.opt.foldminlines = 5 +vim.opt.foldnestmax = 2 + -- Save when lost focus vim.cmd('au FocusLost * silent! wa') diff --git a/dot_config/nvim/lua/plugins/appearance.lua b/dot_config/nvim/lua/plugins/appearance.lua index 460213d..a6bf799 100644 --- a/dot_config/nvim/lua/plugins/appearance.lua +++ b/dot_config/nvim/lua/plugins/appearance.lua @@ -22,6 +22,7 @@ local conf_theme = function() }, sections = { lualine_c = { + 'filename', { gps.get_location, cond = gps.is_available }, }, } diff --git a/dot_config/nvim/lua/plugins/keymap.lua b/dot_config/nvim/lua/plugins/keymap.lua index 4a75fca..8e8b54b 100644 --- a/dot_config/nvim/lua/plugins/keymap.lua +++ b/dot_config/nvim/lua/plugins/keymap.lua @@ -21,12 +21,22 @@ local mappings = { [""] = { "", "Reopen Last Buffer" }, -- Buffer b = { - name = "buffer", + name = "Buffer", b = { "lua require('telescope.builtin').buffers()", "Find Buffer" }, d = { "bd", "Delete Buffer" }, m = { "%bd|e#", "Delete Other Buffers" }, y = { "ggyG", "Copy Buffer" }, }, + -- Debug + d = { + name = "Debug", + b = {"lua require('dap').toggle_breakpoint()", "Breakpoint"}, + B = {"lua require('dap').set_breakpoint(vim.fn.input('Breakpoint condition: '))", "Conditional Breakpoint"}, + l = {"require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point message: '))", "Logpoint"}, + r = {"lua require('dap').repl.open()", "Open REPL"}, + c = {"lua require('dap').continue()", "Continue"}, + q = {"lua require('dap').close()", "Close"}, + }, -- File f = { name = "File",