all repos

init.lua @ 105849d11d270332a3b35b231c599e1457ac18f5

my nvim config
3 files changed, 75 insertions(+), 3 deletions(-)
feat: add util for sending breakpoints into dlv
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2025-10-12 23:26:55 +0300
Parent: 4e96b91
M after/ftplugin/go.lua

@@ -15,3 +15,5 @@ map("n", "<localleader>a", "<cmd>GoTestsAll<cr>", true)

map("n", "<localleader>e", "<cmd>GoTestsExp<cr>", true) map("n", "<localleader>s", require("scratch.gotest").switch, true) +map("n", "<localleader>b", require("scratch.dlv").bset, true) +map("n", "<localleader>B", require("scratch.dlv").clear, true)
M lazy-lock.json

@@ -1,5 +1,5 @@

{ - "blink.cmp": { "branch": "main", "commit": "bae4bae0eedd1fa55f34b685862e94a222d5c6f8" }, + "blink.cmp": { "branch": "main", "commit": "327fff91fe6af358e990be7be1ec8b78037d2138" }, "curl.nvim": { "branch": "main", "commit": "3ee14fbafc8169fc803e80562ce7ac5b4474bdff" }, "fidget.nvim": { "branch": "main", "commit": "b61e8af9b8b68ee0ec7da5fb7a8c203aae854f2e" }, "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" },

@@ -17,11 +17,11 @@ "nvim-treesitter-context": { "branch": "master", "commit": "ed1cf48d5af252248c55f50b9427e8ce883a2c6b" },

"nvim-treesitter-endwise": { "branch": "master", "commit": "a61a9de7965324d4019fb1637b66bfacdcb01f51" }, "oil.nvim": { "branch": "master", "commit": "975a77cce3c8cb742bc1b3629f4328f5ca977dad" }, "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, - "render-markdown.nvim": { "branch": "main", "commit": "3da7bb459f6cff03980dd1e106c46f3e62ff4d9f" }, + "render-markdown.nvim": { "branch": "main", "commit": "6594102acb2fc50dd47d19e49e463031ae48c3ef" }, "schemastore.nvim": { "branch": "main", "commit": "dc34600801650c2c8bf62125b1f70f6cfffcc057" }, "snacks.nvim": { "branch": "main", "commit": "da230e3ca8146da4b73752daaf0a1d07d343c12d" }, "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, - "tokyonight.nvim": { "branch": "main", "commit": "b262293ef481b0d1f7a14c708ea7ca649672e200" }, + "tokyonight.nvim": { "branch": "main", "commit": "4d159616aee17796c2c94d2f5f87d2ee1a3f67c7" }, "undotree": { "branch": "master", "commit": "fe9a9d0645f0f5532360b5e5f5c550d7bb4f1869" }, "vim-repeat": { "branch": "master", "commit": "8106e142dfdc278ff3eaaadd7b362ad7949d4357" }, "vim-speeddating": { "branch": "master", "commit": "426c792e479f6e1650a6996c683943a09344c21e" },
A lua/scratch/dlv.lua

@@ -0,0 +1,70 @@

+local dlv = {} +local cache = { + tab_id = nil, + signs = {}, +} + +vim.fn.sign_define("Breakpoint", { text = "b", texthl = "Error" }) + +local function kitty(args) + local res = vim.system({ "kitty", "@", unpack(args) }, { text = true }):wait() + if res.code ~= 0 then + vim.notify("failed to kitty @ " .. vim.inspect(args), vim.log.levels.ERROR) + end + return res +end + +local function get_dlv_tab_id() + if cache.tab_id then + return cache.tab_id + end + + local res = kitty { "ls" } + local out = vim.json.decode(res.stdout) + + for _, tab in ipairs(out) do + for _, win in ipairs(tab.tabs or {}) do + for _, w in ipairs(win.windows or {}) do + if + w.title:match "^dlv connect" + or w.title:match "^dlv debug" + or w.title:match "^dlv test" + then + cache.tab_id = w.id + return w.id + end + end + end + end + + vim.notify("it seems like there's no dlv running", vim.log.levels.ERROR) +end + +function dlv.bset() + local line = vim.fn.line "." + + -- send breakpoint + local tid = get_dlv_tab_id() + local cmd = string.format("break %s:%d\n", vim.fn.expand "%:t", line) + kitty { "send-text", "-m", "id:" .. tid, cmd } + + -- set sign + local fullpath = vim.fn.expand "%:p" + + local sid = tonumber(string.format("%d%04d", vim.fn.bufnr(), line)) --[[ @as number]] + vim.fn.sign_place(sid, "Breakpoints", "Breakpoint", fullpath, { lnum = line }) + table.insert(cache.signs, sid) +end + +function dlv.clear() + for _, sid in ipairs(cache.signs) do + vim.fn.sign_unplace("Breakpoints", { id = sid }) + end + + cache.signs = {} + cache.tab_id = nil + + vim.notify("Cleared all breakpoints.", vim.log.levels.INFO) +end + +return dlv