neovim: fixes dap debugging
d7ca6f5a0b0e220b8687d7cd7cc46faac3853a91
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: f9a83423896e
bugabingas dorkfiles
d7ca6f5a0b0e220b8687d7cd7cc46faac3853a91
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+308 / −51 text lines
new file mode 100644+1 / −0 text lines
vim.opt.makeprg = 'use build.nu; build debug'+1 / −1 text lines
new file mode 100644+93 / −0 text lines
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheaderlocal function switch_source_header(bufnr, client) local method_name = 'textDocument/switchSourceHeader' ---@diagnostic disable-next-line:param-type-mismatch if not client or not client:supports_method(method_name) then return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name)) end local params = vim.lsp.util.make_text_document_params(bufnr) ---@diagnostic disable-next-line:param-type-mismatch client:request(method_name, params, function(err, result) if err then error(tostring(err)) end if not result then vim.notify('corresponding file cannot be determined') return end vim.cmd.edit(vim.uri_to_fname(result)) end, bufnr)endlocal function symbol_info(bufnr, client) local method_name = 'textDocument/symbolInfo' ---@diagnostic disable-next-line:param-type-mismatch if not client or not client:supports_method(method_name) then return vim.notify('Clangd client not found', vim.log.levels.ERROR) end local win = vim.api.nvim_get_current_win() local params = vim.lsp.util.make_position_params(win, client.offset_encoding) ---@diagnostic disable-next-line:param-type-mismatch client:request(method_name, params, function(err, res) if err or #res == 0 then -- Clangd always returns an error, there is no reason to parse it return end local container = string.format('container: %s', res[1].containerName) ---@type string local name = string.format('name: %s', res[1].name) ---@type string vim.lsp.util.open_floating_preview({ name, container }, '', { height = 2, width = math.max(string.len(name), string.len(container)), focusable = false, focus = false, title = 'Symbol Info', }) end, bufnr)end---@class ClangdInitializeResult: lsp.InitializeResult---@field offsetEncoding? string---@type vim.lsp.Configreturn { cmd = { 'clangd', '--background-index', '--clang-tidy' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' }, root_markers = { '.clangd', '.clang-tidy', '.clang-format', 'compile_commands.json', 'compile_flags.txt', 'configure.ac', -- AutoTools '.git', }, init_options = { clangdFileStatus = true, usePlaceHolders = true, completeUnimported = true, semanticHighlighting = true, }, capabilities = { textDocument = { completion = { editsNearCursor = true, }, }, offsetEncoding = { 'utf-8', 'utf-16' }, }, ---@param init_result ClangdInitializeResult on_init = function(client, init_result) if init_result.offsetEncoding then client.offset_encoding = init_result.offsetEncoding end end, on_attach = function(client, bufnr) vim.api.nvim_buf_create_user_command(bufnr, 'LspClangdSwitchSourceHeader', function() switch_source_header(bufnr, client) end, { desc = 'Switch between source/header' }) vim.api.nvim_buf_create_user_command(bufnr, 'LspClangdShowSymbolInfo', function() symbol_info(bufnr, client) end, { desc = 'Show symbol info' }) end,}new file mode 100644+143 / −0 text lines
local puk = require 'std.puk'local dbg = require 'std.dbg'local map = require 'std.map'local function configure_lldb(dap) --FIXME: i cannot get this shit to work!!! too stoopid! local lldb_dap_exe = vim.fn.exepath 'lldb-dap' if lldb_dap_exe ~= '' then dap.adapters.lldb = { type = 'executable', command = lldb_dap_exe, name = 'lldb', } dap.configurations.c = { { name = 'Launch', type = 'lldb', request = 'launch', program = function() return coroutine.create(function(dap_run_co) -- local path = vim.fn.input({ -- prompt = 'Path to executable: ', -- default = vim.fn.getcwd() .. '/', -- completion = 'file' -- }) local path = require("dap.utils").pick_file({ filter = "output/*" }) local choice = (path and path ~= "") and path or dap.ABORT coroutine.resume(dap_run_co, choice) end) end, cwd = '${workspaceFolder}', stopOnEntry = false, initCommands = { 'settings set target.x86-disassembly-flavor intel', 'settings set symbols.auto-download background', 'settings set symbols.enable-background-lookup true', 'settings set symbols.enable-lldb-index-cache true' }, env = function() local variables = {} for k, v in pairs(vim.fn.environ()) do table.insert(variables, string.format("%s=%s", k, v)) end return variables end, --TODO: if exe takes arguments, use vim.input here to provide them args = {}, -- 💀 -- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting: -- -- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope -- -- Otherwise you might get the following error: -- -- Error on launch: Failed to attach to the target process -- -- But you should be aware of the implications: -- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html runInTerminal = true, }, } dap.configurations.cpp = dap.configurations.c dap.configurations.rust = dap.configurations.c endendpuk.defer 'dap' (function(dap) dap.set_log_level(dbg.get() and 'TRACE' or 'ERROR') puk 'nio' local dapui = puk 'dapui' local dap_disasm = puk 'dap-disasm' local dap_virtual_text = puk 'nvim-dap-virtual-text' configure_lldb(dap) dapui.setup() dap_disasm.setup() dap_virtual_text.setup() dap.listeners.before.attach.dapui_config = function() dapui.open() end dap.listeners.before.launch.dapui_config = function() dapui.open() end dap.listeners.before.event_terminated.dapui_config = function() dapui.close() end dap.listeners.before.event_exited.dapui_config = function() dapui.close() end map.normal { description = 'toggle breakpoint', category = 'debug', keys = '<leader>db', command = dap.toggle_breakpoint, } map.normal { description = 'run to cursor', category = 'debug', keys = '<leader>dr', command = dap.run_to_cursor, } map.normal { description = 'run last', category = 'debug', keys = '<leader>dl', command = dap.run_last, } map.normal { description = 'continue/start debugger', category = 'debug', keys = '<leader>dd', command = dap.continue, } map.normal { description = 'step into', category = 'debug', keys = '<Right>', command = dap.step_into, } map.normal { description = 'step over', category = 'debug', keys = '<Down>', command = dap.step_over, } map.normal { description = 'step out', category = 'debug', keys = '<Left>', command = dap.step_out, } map.normal { description = 'restart frame', category = 'debug', keys = '<Up>', command = dap.restart_frame, } map.normal.visual { description = 'eval under cursor', category = 'debug', keys = '<leader>de', command = dapui.eval, } map.normal { description = 'show element', category = 'debug', keys = '<leader>de', command = function() dapui.float_element(nil, { position = 'center' }) end, }end)+7 / −0 text lines
+52 / −47 text lines
'Glance', 'Outline', 'WhichKey', '^git.*', 'bigfile', 'blink-cmp-menu', 'dap-repl', 'dap-view', 'dap-view-term', 'dap-float', 'disassembly', 'mininotify', 'mininotify-history', 'checkhealth', 'fidget', 'grug-far', 'help', 'minipick', 'ivy', 'incline', 'lazy', 'man', 'neo-tree', 'neo-tree-popup', 'notify', 'nvim-docs-view', 'oil', 'oil_progress', 'oil_preview', 'outputpanel', 'qf', 'netrw', 'svn', 'Glance', 'Outline', 'WhichKey', '^git.*', 'bigfile', 'blink-cmp-menu', 'dap-repl', 'dap-view', 'dap-view-term', 'dap-float', 'dapui_console', 'dapui_scopes', 'dapui_breakpoints', 'dapui_stacks', 'dapui_watches', 'dapui_hover', 'mininotify', 'mininotify-history', 'checkhealth', 'fidget', 'grug-far', 'help', 'minipick', 'ivy', 'incline', 'lazy', 'man', 'neo-tree', 'neo-tree-popup', 'notify', 'nvim-docs-view', 'oil', 'oil_progress', 'oil_preview', 'outputpanel', 'qf', 'netrw', 'svn',+11 / −3 text lines