repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: fixes dap debugging

d7ca6f5a0b0e220b8687d7cd7cc46faac3853a91

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (7)

+308 / −51 text lines

Diff layout

neovim/after/ftplugin/c.lua

Added
new file mode 100644

+1 / −0 text lines

1vim.opt.makeprg = 'use build.nu; build debug'

neovim/init.lua

Modified

+1 / −1 text lines

8282require 'bugabinga.virtual_column'
8383require 'bugabinga.winbar'
8484-- lldb-dap with nvim-dap is too hard to use, i cannot seem to make it work
85-- require 'bugabinga.debugging'
85require 'bugabinga.debugging'
8787require 'bugabinga.incubator'

neovim/lsp/clangd.lua

Added
new file mode 100644

+93 / −0 text lines

1-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
2local function switch_source_header(bufnr, client)
3 local method_name = 'textDocument/switchSourceHeader'
4 ---@diagnostic disable-next-line:param-type-mismatch
5 if not client or not client:supports_method(method_name) then
6 return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name))
7 end
8 local params = vim.lsp.util.make_text_document_params(bufnr)
9 ---@diagnostic disable-next-line:param-type-mismatch
10 client:request(method_name, params, function(err, result)
11 if err then
12 error(tostring(err))
13 end
14 if not result then
15 vim.notify('corresponding file cannot be determined')
16 return
17 end
18 vim.cmd.edit(vim.uri_to_fname(result))
19 end, bufnr)
20end
22local function symbol_info(bufnr, client)
23 local method_name = 'textDocument/symbolInfo'
24 ---@diagnostic disable-next-line:param-type-mismatch
25 if not client or not client:supports_method(method_name) then
26 return vim.notify('Clangd client not found', vim.log.levels.ERROR)
27 end
28 local win = vim.api.nvim_get_current_win()
29 local params = vim.lsp.util.make_position_params(win, client.offset_encoding)
30 ---@diagnostic disable-next-line:param-type-mismatch
31 client:request(method_name, params, function(err, res)
32 if err or #res == 0 then
33 -- Clangd always returns an error, there is no reason to parse it
34 return
35 end
36 local container = string.format('container: %s', res[1].containerName) ---@type string
37 local name = string.format('name: %s', res[1].name) ---@type string
38 vim.lsp.util.open_floating_preview({ name, container }, '', {
39 height = 2,
40 width = math.max(string.len(name), string.len(container)),
41 focusable = false,
42 focus = false,
43 title = 'Symbol Info',
44 })
45 end, bufnr)
46end
48---@class ClangdInitializeResult: lsp.InitializeResult
49---@field offsetEncoding? string
51---@type vim.lsp.Config
52return {
53 cmd = { 'clangd', '--background-index', '--clang-tidy' },
54 filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
55 root_markers = {
56 '.clangd',
57 '.clang-tidy',
58 '.clang-format',
59 'compile_commands.json',
60 'compile_flags.txt',
61 'configure.ac', -- AutoTools
62 '.git',
63 },
64 init_options = {
65 clangdFileStatus = true,
66 usePlaceHolders = true,
67 completeUnimported = true,
68 semanticHighlighting = true,
69 },
70 capabilities = {
71 textDocument = {
72 completion = {
73 editsNearCursor = true,
74 },
75 },
76 offsetEncoding = { 'utf-8', 'utf-16' },
77 },
78 ---@param init_result ClangdInitializeResult
79 on_init = function(client, init_result)
80 if init_result.offsetEncoding then
81 client.offset_encoding = init_result.offsetEncoding
82 end
83 end,
84 on_attach = function(client, bufnr)
85 vim.api.nvim_buf_create_user_command(bufnr, 'LspClangdSwitchSourceHeader', function()
86 switch_source_header(bufnr, client)
87 end, { desc = 'Switch between source/header' })
89 vim.api.nvim_buf_create_user_command(bufnr, 'LspClangdShowSymbolInfo', function()
90 symbol_info(bufnr, client)
91 end, { desc = 'Show symbol info' })
92 end,
93}

neovim/lua/bugabinga/debugging.lua

Added
new file mode 100644

+143 / −0 text lines

1local puk = require 'std.puk'
2local dbg = require 'std.dbg'
3local map = require 'std.map'
4
5local function configure_lldb(dap)
6 --FIXME: i cannot get this shit to work!!! too stoopid!
7 local lldb_dap_exe = vim.fn.exepath 'lldb-dap'
8 if lldb_dap_exe ~= '' then
9 dap.adapters.lldb = {
10 type = 'executable',
11 command = lldb_dap_exe,
12 name = 'lldb',
13 }
14 dap.configurations.c = {
15 {
16 name = 'Launch',
17 type = 'lldb',
18 request = 'launch',
19 program = function()
20 return coroutine.create(function(dap_run_co)
21 -- local path = vim.fn.input({
22 -- prompt = 'Path to executable: ',
23 -- default = vim.fn.getcwd() .. '/',
24 -- completion = 'file'
25 -- })
27 local path = require("dap.utils").pick_file({ filter = "output/*" })
28 local choice = (path and path ~= "") and path or dap.ABORT
29 coroutine.resume(dap_run_co, choice)
30 end)
31 end,
32 cwd = '${workspaceFolder}',
33 stopOnEntry = false,
34 initCommands = {
35 'settings set target.x86-disassembly-flavor intel',
36 'settings set symbols.auto-download background',
37 'settings set symbols.enable-background-lookup true',
38 'settings set symbols.enable-lldb-index-cache true'
39 },
40 env = function()
41 local variables = {}
42 for k, v in pairs(vim.fn.environ()) do
43 table.insert(variables, string.format("%s=%s", k, v))
44 end
45 return variables
46 end,
47 --TODO: if exe takes arguments, use vim.input here to provide them
48 args = {},
50 -- 💀
51 -- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
52 --
53 -- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
54 --
55 -- Otherwise you might get the following error:
56 --
57 -- Error on launch: Failed to attach to the target process
58 --
59 -- But you should be aware of the implications:
60 -- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
61 runInTerminal = true,
62 },
63 }
64 dap.configurations.cpp = dap.configurations.c
65 dap.configurations.rust = dap.configurations.c
66 end
67end
69puk.defer 'dap' (function(dap)
70 dap.set_log_level(dbg.get() and 'TRACE' or 'ERROR')
71 puk 'nio'
72 local dapui = puk 'dapui'
73 local dap_disasm = puk 'dap-disasm'
74 local dap_virtual_text = puk 'nvim-dap-virtual-text'
75 configure_lldb(dap)
76 dapui.setup()
77 dap_disasm.setup()
78 dap_virtual_text.setup()
79 dap.listeners.before.attach.dapui_config = function() dapui.open() end
80 dap.listeners.before.launch.dapui_config = function() dapui.open() end
81 dap.listeners.before.event_terminated.dapui_config = function() dapui.close() end
82 dap.listeners.before.event_exited.dapui_config = function() dapui.close() end
83 map.normal {
84 description = 'toggle breakpoint',
85 category = 'debug',
86 keys = '<leader>db',
87 command = dap.toggle_breakpoint,
88 }
89 map.normal {
90 description = 'run to cursor',
91 category = 'debug',
92 keys = '<leader>dr',
93 command = dap.run_to_cursor,
94 }
95 map.normal {
96 description = 'run last',
97 category = 'debug',
98 keys = '<leader>dl',
99 command = dap.run_last,
100 }
101 map.normal {
102 description = 'continue/start debugger',
103 category = 'debug',
104 keys = '<leader>dd',
105 command = dap.continue,
106 }
107 map.normal {
108 description = 'step into',
109 category = 'debug',
110 keys = '<Right>',
111 command = dap.step_into,
112 }
113 map.normal {
114 description = 'step over',
115 category = 'debug',
116 keys = '<Down>',
117 command = dap.step_over,
118 }
119 map.normal {
120 description = 'step out',
121 category = 'debug',
122 keys = '<Left>',
123 command = dap.step_out,
124 }
125 map.normal {
126 description = 'restart frame',
127 category = 'debug',
128 keys = '<Up>',
129 command = dap.restart_frame,
130 }
131 map.normal.visual {
132 description = 'eval under cursor',
133 category = 'debug',
134 keys = '<leader>de',
135 command = dapui.eval,
136 }
137 map.normal {
138 description = 'show element',
139 category = 'debug',
140 keys = '<leader>de',
141 command = function() dapui.float_element(nil, { position = 'center' }) end,
142 }
143end)

neovim/lua/bugabinga/options/keymaps.lua

Modified

+7 / −0 text lines

118118 keys = '<leader>a',
119119 command = 'ggVG'
122map.normal {
123 description = 'current project',
124 category = 'build',
125 keys = '<F9>',
126 command = '<CMD>make<CR>'
127}

neovim/lua/std/ignored.lua

Modified

+52 / −47 text lines

11local filetypes = {
2 'Glance',
3 'Outline',
4 'WhichKey',
5 '^git.*',
6 'bigfile',
7 'blink-cmp-menu',
8 'dap-repl',
9 'dap-view',
10 'dap-view-term',
11 'dap-float',
12 'disassembly',
13 'mininotify',
14 'mininotify-history',
15 'checkhealth',
16 'fidget',
17 'grug-far',
18 'help',
19 'minipick',
20 'ivy',
21 'incline',
22 'lazy',
23 'man',
24 'neo-tree',
25 'neo-tree-popup',
26 'notify',
27 'nvim-docs-view',
28 'oil',
29 'oil_progress',
30 'oil_preview',
31 'outputpanel',
32 'qf',
33 'netrw',
34 'svn',
2 'Glance',
3 'Outline',
4 'WhichKey',
5 '^git.*',
6 'bigfile',
7 'blink-cmp-menu',
8 'dap-repl',
9 'dap-view',
10 'dap-view-term',
11 'dap-float',
12 'dapui_console',
13 'dapui_scopes',
14 'dapui_breakpoints',
15 'dapui_stacks',
16 'dapui_watches',
17 'dapui_hover',
18 'mininotify',
19 'mininotify-history',
20 'checkhealth',
21 'fidget',
22 'grug-far',
23 'help',
24 'minipick',
25 'ivy',
26 'incline',
27 'lazy',
28 'man',
29 'neo-tree',
30 'neo-tree-popup',
31 'notify',
32 'nvim-docs-view',
33 'oil',
34 'oil_progress',
35 'oil_preview',
36 'outputpanel',
37 'qf',
38 'netrw',
39 'svn',
3742local buftypes = {
38 'acwrite',
39 'help',
40 'prompt',
41 'nofile',
43 'acwrite',
44 'help',
45 'prompt',
46 'nofile',
4449local as_kv = function(list)
45 local tbl = {}
46 for _, value in ipairs(list) do
47 vim.validate('value', value, 'string')
48 tbl[value] = true
49 end
50 return tbl
50 local tbl = {}
51 for _, value in ipairs(list) do
52 vim.validate('value', value, 'string')
53 tbl[value] = true
54 end
55 return tbl
5156end
5358local filetypes_kv = as_kv(filetypes)
5459local buftypes_kv = as_kv(buftypes)
5661return {
57 filetypes = filetypes,
58 filetypes_kv = filetypes_kv,
59 buftypes = buftypes,
60 buftypes_kv = buftypes_kv,
62 filetypes = filetypes,
63 filetypes_kv = filetypes_kv,
64 buftypes = buftypes,
65 buftypes_kv = buftypes_kv,

neovim/puk.plugins.nuon

Modified

+11 / −3 text lines

273273 null
274274 ],
275275 [
276 dap-view,
276 dapui,
277277 github,
278 "igorlfs/nvim-dap-view",
278 "rcarriga/nvim-dap-ui",
279279 main,
280 788190807ae98a5b0ff3eb9d836fe4e35ba75c23,
280 cf91d5e2d07c72903d052f5207511bf7ecdb7122
281281 null
282282 ],
283 [
284 nio,
285 github,
286 "nvim-neotest/nvim-nio",
287 master,
288 21f5324bfac14e22ba26553caf69ec76ae8a7662,
289 null
290 ]
283291 [
284292 dap-disasm,
285293 github,