my neovim config, who would've thought
at main 1.7 kB view raw
1local dlv = {} 2local cache = { 3 tab_id = nil, 4 signs = {}, 5} 6 7vim.fn.sign_define("Breakpoint", { text = "b", texthl = "Error" }) 8 9local function kitty(args) 10 local res = vim.system({ "kitty", "@", unpack(args) }, { text = true }):wait() 11 if res.code ~= 0 then 12 vim.notify("failed to kitty @ " .. vim.inspect(args), vim.log.levels.ERROR) 13 end 14 return res 15end 16 17local function get_dlv_tab_id() 18 if cache.tab_id then 19 return cache.tab_id 20 end 21 22 local res = kitty { "ls" } 23 local out = vim.json.decode(res.stdout) 24 25 for _, tab in ipairs(out) do 26 for _, win in ipairs(tab.tabs or {}) do 27 for _, w in ipairs(win.windows or {}) do 28 if 29 w.title:match "^dlv connect" 30 or w.title:match "^dlv debug" 31 or w.title:match "^dlv test" 32 then 33 cache.tab_id = w.id 34 return w.id 35 end 36 end 37 end 38 end 39 40 vim.notify("it seems like there's no dlv running", vim.log.levels.ERROR) 41end 42 43function dlv.bset() 44 local line = vim.fn.line "." 45 46 -- send breakpoint 47 local tid = get_dlv_tab_id() 48 local cmd = string.format("break %s:%d\n", vim.fn.expand "%:t", line) 49 kitty { "send-text", "-m", "id:" .. tid, cmd } 50 51 -- set sign 52 local fullpath = vim.fn.expand "%:p" 53 54 local sid = tonumber(string.format("%d%04d", vim.fn.bufnr(), line)) --[[ @as number]] 55 vim.fn.sign_place(sid, "Breakpoints", "Breakpoint", fullpath, { lnum = line }) 56 table.insert(cache.signs, sid) 57end 58 59function dlv.clear() 60 for _, sid in ipairs(cache.signs) do 61 vim.fn.sign_unplace("Breakpoints", { id = sid }) 62 end 63 64 cache.signs = {} 65 cache.tab_id = nil 66 67 vim.notify("Cleared all breakpoints.", vim.log.levels.INFO) 68end 69 70return dlv