nvim: Migrated all dap-related things to their own file

This commit is contained in:
PowerUser64 2021-09-28 01:52:37 -07:00
parent 4f55c742ad
commit 7c747cbbc1
4 changed files with 162 additions and 82 deletions

View file

@ -0,0 +1,117 @@
local M = {}
-- DAP: Debug Adapter Protocol >>>
M.nvim_dap = function()
-- keybinds
vim.cmd [[
" Debugger movement
nnoremap <silent> <leader>d<space> <cmd>lua require'dap'.continue()<CR>
nnoremap <silent> <leader>dj <cmd>lua require'dap'.step_over()<CR>
nnoremap <silent> <leader>dl <cmd>lua require'dap'.step_into()<CR>
nnoremap <silent> <leader>dh <cmd>lua require'dap'.step_out()<CR>
" Breakpoints
nnoremap <silent> <leader>dbb <cmd>lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <leader>dbc <cmd>lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition<cmd> '))<CR>
nnoremap <silent> <leader>dbl <cmd>lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message<cmd> '))<CR>
" Extra
nnoremap <silent> <leader>dp <cmd>lua require'dap'.run_last()<CR>
nnoremap <silent> <leader>dr <cmd>lua require'dap'.repl.open()<CR>
]]
require('dap')
vim.fn.sign_define('DapBreakpoint', {text = '', texthl = 'ErrorMsg', linehl = '', numhl = ''}) -- custom attributes of breakpointed lines (use an emoji?)
vim.fn.sign_define('DapBreakpointRejected', {text = '', texthl = 'ErrorMsg', linehl = '', numhl = ''})
vim.fn.sign_define('DapLogPoint', {text = '', texthl = 'ErrorMsg', linehl = '', numhl = ''})
vim.fn.sign_define('DapStopped', {text = '', texthl = 'ErrorMsg', linehl = '', numhl = ''})
vim.cmd "au FileType dap-repl lua require('dap.ext.autocompl').attach()"
-- per-language config:
local dap = require('dap')
-- c++ dap congiguration >>>
dap.configurations.cpp = {
{
name = "Launch file",
type = "cppdbg",
request = "launch",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = true,
},
}
dap.adapters.cppdbg = {
type = 'executable',
command = '/home/blake/.local/share/nvim/dapinstall/ccppr_vsc/extension/debugAdapters/bin/OpenDebugAD7',
}
-- <<<
end -- <<<
-- DAP installer >>>
M.dap_install = function()
require("dap-install").setup({
installation_path = vim.fn.stdpath("data") .. "/dapinstall/",
})
end -- <<<
-- UI for nvim-dap >>>
M.dap_ui = function()
-- external keybinds
-- require("dapui").open()
-- require("dapui").close()
-- require("dapui").toggle()
require("dapui").setup({
icons = { expanded = "", collapsed = "" },
mappings = {
expand = { "l", "<CR>", "<2-LeftMouse>", }, -- expand (or close)
open = "o", -- action depends on the dap server
remove = "d", -- delete the variable
edit = "s", -- (as in substitute)
repl = "r", -- open a repl
},
sidebar = {
-- You can change the order of elements in the sidebar
elements = {
-- size can be float or integer > 1
{ id = "scopes", size = 0.55, },
{ id = "breakpoints", size = 0.15 },
{ id = "stacks", size = 0.15 },
{ id = "watches", size = 0.15 },
},
size = 40,
position = "left", -- Can be "left", "right", "top", "bottom"
},
tray = {
elements = { "repl" },
size = 10,
position = "bottom", -- Can be "left", "right", "top", "bottom"
},
floating = {
max_height = nil, -- These can be integers or a float between 0 and 1.
max_width = nil, -- Floats will be treated as percentage of your screen.
mappings = {
close = { "q", "<Esc>" },
},
},
windows = { indent = 1 },
})
end -- <<<
-- dap-virtual-text: show values of variables inline while debugging >>>
M.dap_vtext = function()
require'nvim-dap-virtual-text'
-- virtual text deactivated (default)
vim.g.dap_virtual_text = true
-- show virtual text for current frame (recommended)
vim.g.dap_virtual_text = true
-- request variable values for all frames (experimental)
vim.g.dap_virtual_text = 'all frames'
end -- <<<
return M
-- vim:fdm=marker:fmr=>>>,<<<:expandtab:tabstop=3:sw=3

View file

@ -17,9 +17,7 @@ M.lspinstall = function() --
require'lspconfig'[server].setup{}
end
end
setup_servers()
-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
require'lspinstall'.post_install_hook = function ()
setup_servers() -- reload installed servers
@ -83,6 +81,18 @@ M.treesitter = function()
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
-- How to read these next keybinds
-- first character:
-- [ means previous
-- ] means next
-- second character:
-- m means function beginning
-- M means function end
-- OR
-- both the same means start in that direction
-- ex: [[ means previous start
-- both in opposite directions means end in that way
-- ex: [] means previous end
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
@ -109,7 +119,6 @@ M.cmp = function()
-- nvim-cmp supports additional completion capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
@ -153,7 +162,6 @@ M.cmp = function()
format = function(entry, vim_item)
-- fancy icons and a name of kind
vim_item.kind = require("lspkind").presets.default[vim_item.kind] .. " " .. vim_item.kind
-- set a name for each source
vim_item.menu = ({
path = "(Path)",
@ -226,58 +234,6 @@ M.lspconfig = function()
end
end -- <<<
-- DAP: Debug Adapter Protocol >>>
M.dap = function()
-- keybinds
vim.cmd [[
" Debugger movement
nnoremap <silent> <leader>d<space> <cmd>lua require'dap'.continue()<CR>
nnoremap <silent> <leader>dj <cmd>lua require'dap'.step_over()<CR>
nnoremap <silent> <leader>dl <cmd>lua require'dap'.step_into()<CR>
nnoremap <silent> <leader>dh <cmd>lua require'dap'.step_out()<CR>
" Breakpoints
nnoremap <silent> <leader>dbb <cmd>lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <leader>dbc <cmd>lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition<cmd> '))<CR>
nnoremap <silent> <leader>dbl <cmd>lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message<cmd> '))<CR>
" Extra
nnoremap <silent> <leader>dp <cmd>lua require'dap'.run_last()<CR>
nnoremap <silent> <leader>dr <cmd>lua require'dap'.repl.open()<CR>
]]
-- vim.fn.sign_define('DapBreakpoint', {text='B', texthl='', linehl='', numhl=''}) -- custom attributes of breakpointed lines (use an emoji?)
vim.cmd "au FileType dap-repl lua require('dap.ext.autocompl').attach()"
-- per-language config:
local dap = require('dap')
-- c++ dap congiguration >>>
dap.configurations.cpp = {
{
name = "Launch file",
type = "cppdbg",
request = "launch",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = true,
},
}
dap.adapters.cppdbg = {
type = 'executable',
command = '/home/blake/.local/share/nvim/dapinstall/ccppr_vsc/extension/debugAdapters/bin/OpenDebugAD7',
}
-- <<<
end -- <<<
-- DAP installer >>>
M.dapinstall = function()
local dap_install = require("dap-install")
dap_install.setup({
installation_path = vim.fn.stdpath("data") .. "/dapinstall/",
})
end -- <<<
return M
-- vim:fdm=marker:fmr=>>>,<<<:expandtab:tabstop=3:sw=3

View file

@ -88,6 +88,32 @@ return require('packer').startup(function()
end
}
---- DAP (Debug Adapter Protocol)
use { -- nvim-dap: DAP support
'mfussenegger/nvim-dap',
config = function()
require('blake.dap').nvim_dap()
end
}
use { -- DAP adapter installer
'Pocco81/DAPInstall.nvim',
config = function()
require('blake.dap').dap_install()
end
}
use { -- virtual-text: Print Variable names while debugging
'theHamsta/nvim-dap-virtual-text',
config = function()
require('blake.dap').dap_vtext()
end
}
use { -- a UI for nvim-dap (easy access to info)
'rcarriga/nvim-dap-ui',
config = function()
require('blake.dap').dap_ui()
end,
}
---- Other IDE features
use { -- git integration
'lewis6991/gitsigns.nvim',
@ -128,32 +154,6 @@ return require('packer').startup(function()
ft = { 'md', 'markdown', }
}
---- DAP (Debug Adapter Protocol)
use { -- nvim-dap: DAP support
'mfussenegger/nvim-dap',
config = function()
require('blake.lsp').nvim_dap()
end
}
use { -- DAP adapter installer
'Pocco81/DAPInstall.nvim',
config = function()
require('blake.dap').dapinstall()
end
}
use { -- Print Variable names while debugging
'theHamsta/nvim-dap-virtual-text',
config = function()
require'nvim-dap-virtual-text'
-- virtual text deactivated (default)
vim.g.dap_virtual_text = true
-- show virtual text for current frame (recommended)
vim.g.dap_virtual_text = true
-- request variable values for all frames (experimental)
vim.g.dap_virtual_text = 'all frames'
end
}
-- Conveniences
use { -- Undo tree
'mbbill/undotree',

View file

@ -66,6 +66,13 @@ vim.cmd [[
command! W w
command! Wq wq
command! WQ wq
command! Wa wa
command! WA wa
command! Qa qa
command! QA qa
command! Wqa wqa
command! WQa wqa
command! WQA wqa
" Press Alt h to toggle highlighting on/off, and show current value.
noremap <M-h> <cmd>set hlsearch! hlsearch?<CR>