repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

feat(cmdline): Custom cmdline popup with smart popupmenu positioning

1bcc9bc6f35b948fc7b48f1feeb4cc74ad7e287b

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

- Custom cmdline popup replacing native Neovim UI
- Full-screen width popup appearing at cursor position
- Icon prefix with type detection (search, command, lua, input)
- Trailing space for proper cursor positioning after last character
- Stable position: only calculated on initial show, reused on subsequent updates
- Smart popupmenu positioning:
  - Renders below cmdline when cursor in top half of screen
  - Renders above cmdline when cursor in bottom half of screen
  - Reverses item order and adjusts cursor when above
- 38 passing tests for cmdline modules

Changed files (44)

neovim/init.lua

Modified
9 9 -- ▀ ▀
11 11 local version = vim.version()
12 -local expected = { major = 0, minor = 12 }
12 +local expected = { major = 0, minor = 11 }
13 13 if version.major ~= expected.major or version.minor ~= expected.minor then
14 14 vim.notify(
15 15 'This configuration assumes NeoVim version ' ..
53 53 require 'bugabinga.diagnostic'
54 54 require 'bugabinga.editorconfig'
55 55 require 'bugabinga.lsp'
56 +require 'bugabinga.snippet'
57 +require 'bugabinga.code_action'
56 58 require 'bugabinga.statusline'.setup()
57 59 require 'bugabinga.mkdir'
58 60 require 'bugabinga.options'
61 +require 'bugabinga.cycle'
59 62 require 'bugabinga.sessions'
60 63 require 'bugabinga.treesitter'
61 64 require 'bugabinga.terminal'
65 +require 'bugabinga.cmdline'
62 66 require 'bugabinga.inlay'
64 68 --[[ PLUGINS ]]
69 +require 'bugabinga.opencode'
65 70 require 'bugabinga.autotag'
66 71 require 'bugabinga.colorizer'
67 72 require 'bugabinga.devicons'
68 73 require 'bugabinga.diff'
69 74 require 'bugabinga.file_explorer'
70 75 require 'bugabinga.format'
76 +require 'bugabinga.d2'
71 77 require 'bugabinga.fuzzy_find'
78 +require 'bugabinga.grapple'
72 79 require 'bugabinga.jump2d'
73 80 require 'bugabinga.key_preview'
74 81 require 'bugabinga.move'
80 87 require 'bugabinga.surround'
81 88 require 'bugabinga.textobjects'
82 89 require 'bugabinga.winbar'
83 -require 'bugabinga.supress_warnings'
90 +require 'bugabinga.suppress_warnings'
84 91 require 'bugabinga.autopairs'
92 +require 'bugabinga.notify'
86 94 require 'bugabinga.incubator'

neovim/lua/bugabinga/cmdline/cursor.lua

Added
new file mode 100644
1 +return {
2 + fix = function(win, byte_pos)
3 + if not vim.api.nvim_win_is_valid(win) then
4 + return
5 + end
6 + vim.defer_fn(function()
7 + if not vim.api.nvim_win_is_valid(win) then
8 + return
9 + end
10 + vim.api.nvim_win_set_cursor(win, { 1, byte_pos })
11 + vim.api.nvim__redraw({ cursor = true, win = win, flush = true })
12 + end, 0)
13 + end,

neovim/lua/bugabinga/cmdline/format.lua

Added
new file mode 100644
1 +local icon = require 'std.icon'
3 +return {
4 + detect = function(firstc, content, prompt)
5 + if prompt and prompt ~= '' then
6 + return { type = 'input', icon = icon.prompt_prefix }
7 + end
8 + if firstc == '/' then
9 + return { type = 'search_down', icon = icon.search }
10 + end
11 + if firstc == '?' then
12 + return { type = 'search_up', icon = icon.search }
13 + end
14 + if firstc == ':' then
15 + if content:match '^lua%s+' or content:match '^=%s*' or content:match '^:%s*lua%s*=%s*' then
16 + return { type = 'lua', icon = icon.vim }
17 + end
18 + return { type = 'cmdline', icon = icon.command }
19 + end
20 + return { type = 'cmdline', icon = icon.command }
21 + end,

neovim/lua/bugabinga/cmdline/init.lua

Added
new file mode 100644
1 +local state = require 'bugabinga.cmdline.state'
2 +local render = require 'bugabinga.cmdline.render'
3 +local popupmenu = require 'bugabinga.cmdline.popupmenu'
5 +local ns = vim.api.nvim_create_namespace 'bugabinga.cmdline'
6 +local attached = false
8 +local handlers = {
9 + cmdline_show = function(content, pos, firstc, prompt, indent, level)
10 + local cmdline_state = state.new(content, pos, firstc, prompt, indent, level)
11 + render.show(cmdline_state)
12 + end,
13 + cmdline_pos = function(pos, level)
14 + local cmdline_state = state.new({}, pos, '', '', 0, level)
15 + render.update_cursor(cmdline_state)
16 + end,
17 + cmdline_hide = function(abort)
18 + render.hide()
19 + end,
20 + popupmenu_show = function(items, selected, row, col, grid)
21 + popupmenu.on_show(items, selected, row, col, grid)
22 + end,
23 + popupmenu_select = function(selected)
24 + popupmenu.on_select(selected)
25 + end,
26 + popupmenu_hide = function()
27 + popupmenu.on_hide()
28 + end,
31 +local function dispatch(event, ...)
32 + local handler = handlers[event]
33 + if handler then
34 + handler(...)
35 + return true
36 + end
37 + return false
38 +end
40 +local M = {}
42 +function M.setup()
43 + if attached then
44 + return
45 + end
46 + vim.ui_attach(ns, { ext_cmdline = true, ext_popupmenu = true }, function(event, ...)
47 + return dispatch(event, ...)
48 + end)
49 + attached = true
50 +end
52 +function M.disable()
53 + if not attached then
54 + return
55 + end
56 + vim.ui_detach(ns)
57 + attached = false
58 + render.hide()
59 + popupmenu.on_hide()
60 +end
62 +M.setup()
64 +return M

neovim/lua/bugabinga/cmdline/popupmenu.lua

Added
new file mode 100644
1 +local icon = require 'std.icon'
2 +local position = require 'bugabinga.cmdline.position'
4 +local ns = vim.api.nvim_create_namespace 'bugabinga.cmdline.popupmenu'
6 +local state = {
7 + buffer = -1,
8 + window = -1,
9 + items = {},
10 + selected = -1,
11 + grid = -1,
12 + above = false,
15 +local function kind_icon(kind)
16 + if not kind or kind == '' then
17 + return ''
18 + end
19 + return icon[kind] or icon.variable or ''
20 +end
22 +local function format_item(item)
23 + local abbr = item[1] or ''
24 + local kind = item[2] or ''
25 + local menu = item[3] or ''
26 + local info = item[4] or ''
27 + local kind_str = kind_icon(kind)
28 + local parts = {}
29 + if kind_str ~= '' then
30 + table.insert(parts, kind_str .. ' ')
31 + end
32 + table.insert(parts, abbr)
33 + if menu ~= '' then
34 + table.insert(parts, ' ')
35 + table.insert(parts, menu)
36 + end
37 + return table.concat(parts)
38 +end
40 +local function max_width(items)
41 + local max = 0
42 + for _, item in ipairs(items) do
43 + local text = format_item(item)
44 + max = math.max(max, #text)
45 + end
46 + return max
47 +end
49 +local function get_buf()
50 + if vim.api.nvim_buf_is_valid(state.buffer) then
51 + return state.buffer
52 + end
53 + state.buffer = vim.api.nvim_create_buf(false, true)
54 + vim.bo[state.buffer].buflisted = false
55 + vim.bo[state.buffer].filetype = 'bugabinga_popupmenu'
56 + return state.buffer
57 +end
59 +local function get_anchor(row, col, grid, popup_height)
60 + if grid == -1 then
61 + local cmdline_anchor = position.get_cmdline_anchor()
62 + if cmdline_anchor then
63 + local cmdline_row = cmdline_anchor.screenpos.row
64 + local screen_mid = vim.o.lines / 2
65 + local above = cmdline_row > screen_mid
66 + state.above = above
67 + if above then
68 + return {
69 + row = cmdline_row - popup_height - 2,
70 + col = cmdline_anchor.screenpos.col + col,
71 + }
72 + else
73 + return {
74 + row = cmdline_row + 3,
75 + col = cmdline_anchor.screenpos.col + col,
76 + }
77 + end
78 + end
79 + end
80 + state.above = false
81 + return {
82 + row = row + 1,
83 + col = col,
84 + }
85 +end
87 +local function get_win(buf, anchor, width, height)
88 + if vim.api.nvim_win_is_valid(state.window) then
89 + return state.window
90 + end
91 + state.window = vim.api.nvim_open_win(buf, false, {
92 + relative = 'editor',
93 + width = width,
94 + height = height,
95 + row = anchor.row,
96 + col = anchor.col,
97 + style = 'minimal',
98 + border = vim.g.border_style,
99 + focusable = false,
100 + zindex = 201,
101 + })
102 + vim.wo[state.window].cursorline = true
103 + vim.wo[state.window].winbar = ''
104 + vim.wo[state.window].foldenable = false
105 + vim.wo[state.window].winhighlight =
106 + 'Normal:Pmenu,CursorLine:PmenuSel,FloatBorder:FloatBorder'
107 + return state.window
108 +end
110 +local M = {}
112 +function M.on_show(items, selected, row, col, grid)
113 + if not items or #items == 0 then
114 + M.on_hide()
115 + return
116 + end
117 + state.items = items
118 + state.selected = selected
119 + state.grid = grid
120 + local width = math.min(max_width(items) + 2, vim.o.columns - 4)
121 + local height = math.min(#items, vim.o.pumheight)
122 + local anchor = get_anchor(row, col, grid, height)
123 + local buf = get_buf()
124 + local win = get_win(buf, anchor, width, height)
125 + vim.api.nvim_win_set_config(win, {
126 + relative = 'editor',
127 + width = width,
128 + height = height,
129 + row = anchor.row,
130 + col = anchor.col,
131 + })
132 + local lines = vim.iter(items):map(function(item)
133 + return format_item(item)
134 + end):totable()
135 + if state.above then
136 + lines = vim.iter(lines):rev():totable()
137 + end
138 + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
139 + if selected >= 0 and selected < #items then
140 + if state.above then
141 + local visible_start = #items - height
142 + if selected >= visible_start then
143 + local reversed_idx = #items - 1 - selected
144 + vim.api.nvim_win_set_cursor(win, { reversed_idx + 1, 0 })
145 + end
146 + else
147 + vim.api.nvim_win_set_cursor(win, { selected + 1, 0 })
148 + end
149 + end
150 +end
152 +function M.on_select(selected)
153 + if not vim.api.nvim_win_is_valid(state.window) then
154 + return
155 + end
156 + state.selected = selected
157 + if selected >= 0 and selected < #state.items then
158 + if state.above then
159 + local reversed_idx = #state.items - 1 - selected
160 + vim.api.nvim_win_set_cursor(state.window, { reversed_idx + 1, 0 })
161 + else
162 + vim.api.nvim_win_set_cursor(state.window, { selected + 1, 0 })
163 + end
164 + end
165 +end
167 +function M.on_hide()
168 + if vim.api.nvim_win_is_valid(state.window) then
169 + vim.api.nvim_win_hide(state.window)
170 + end
171 + state.items = {}
172 + state.selected = -1
173 + state.grid = -1
174 + state.above = false
175 +end
177 +return M

neovim/lua/bugabinga/cmdline/position.lua

Added
new file mode 100644
1 +local M = {
2 + _anchor = nil,
3 +}
5 +function M.at_cursor(cmdline_width)
6 + local row = vim.fn.screenrow() - 2
7 + local col = 0
8 + local screen_width = vim.o.columns
9 + local width = cmdline_width or 40
10 + if col + width > screen_width then
11 + col = math.max(0, screen_width - width - 1)
12 + end
13 + return { row = row, col = col }
14 +end
16 +function M.get_cmdline_anchor()
17 + return M._anchor
18 +end
20 +function M.set_cmdline_anchor(anchor)
21 + M._anchor = anchor
22 +end
24 +return M

neovim/lua/bugabinga/cmdline/render.lua

Added
new file mode 100644
1 +local format = require 'bugabinga.cmdline.format'
2 +local position = require 'bugabinga.cmdline.position'
3 +local cursor = require 'bugabinga.cmdline.cursor'
5 +local ns = vim.api.nvim_create_namespace 'bugabinga.cmdline'
7 +local state = {
8 + buffer = -1,
9 + window = -1,
10 + icon_width = 0,
13 +local function get_buf()
14 + if vim.api.nvim_buf_is_valid(state.buffer) then
15 + return state.buffer
16 + end
17 + state.buffer = vim.api.nvim_create_buf(false, true)
18 + vim.bo[state.buffer].buflisted = false
19 + vim.bo[state.buffer].filetype = 'bugabinga_cmdline'
20 + return state.buffer
21 +end
23 +local function get_win(buf, width)
24 + if vim.api.nvim_win_is_valid(state.window) then
25 + return state.window
26 + end
27 + local screen_pos = position.at_cursor(width or vim.o.columns)
28 + state.window = vim.api.nvim_open_win(buf, false, {
29 + relative = 'editor',
30 + width = width or vim.o.columns,
31 + height = 1,
32 + row = screen_pos.row,
33 + col = 0,
34 + style = 'minimal',
35 + border = vim.g.border_style,
36 + focusable = false,
37 + zindex = 200,
38 + })
39 + vim.wo[state.window].cursorline = false
40 + vim.wo[state.window].winbar = ''
41 + vim.wo[state.window].foldenable = false
42 + vim.wo[state.window].winhighlight = 'Normal:NormalFloat,FloatBorder:FloatBorder'
43 + return state.window
44 +end
46 +local M = {}
48 +function M.show(cmdline_state)
49 + local text = cmdline_state:text()
50 + local fmt = format.detect(cmdline_state.firstc, text, cmdline_state.prompt)
51 + local icon = fmt.icon
52 + local icon_bytes = #icon
53 + state.icon_width = icon_bytes
54 + local display_text = icon .. ' ' .. text .. ' '
55 + local width = vim.o.columns
56 + local buf = get_buf()
57 + local win = get_win(buf, width)
58 + local is_new = not position.get_cmdline_anchor()
59 + if is_new then
60 + local screen_pos = position.at_cursor(width)
61 + vim.api.nvim_win_set_config(win, {
62 + relative = 'editor',
63 + width = width,
64 + height = 1,
65 + row = screen_pos.row,
66 + col = 0,
67 + })
68 + local anchor = {
69 + screenpos = { row = screen_pos.row, col = 0 },
70 + cursor = 0,
71 + buf = buf,
72 + win = win,
73 + bufpos = { row = 0, col = 0 },
74 + }
75 + position.set_cmdline_anchor(anchor)
76 + vim.g.ui_cmdline_pos = { anchor.screenpos.row, anchor.screenpos.col }
77 + end
78 + vim.api.nvim_buf_set_lines(buf, 0, -1, false, { display_text })
79 + vim.api.nvim_buf_clear_namespace(buf, ns, 0, -1)
80 + local cursor_byte = cmdline_state:cursor_byte()
81 + local cursor_col = icon_bytes + 1 + cursor_byte
82 + local anchor = position.get_cmdline_anchor()
83 + if anchor then
84 + anchor.cursor = cursor_col
85 + anchor.bufpos.col = cursor_col
86 + position.set_cmdline_anchor(anchor)
87 + end
88 + cursor.fix(win, cursor_col)
89 +end
91 +function M.hide()
92 + if vim.api.nvim_win_is_valid(state.window) then
93 + vim.api.nvim_win_hide(state.window)
94 + end
95 + state.icon_width = 0
96 + position.set_cmdline_anchor(nil)
97 + vim.g.ui_cmdline_pos = nil
98 +end
100 +function M.update_cursor(cmdline_state)
101 + if not vim.api.nvim_win_is_valid(state.window) then
102 + return
103 + end
104 + local icon_bytes = state.icon_width
105 + local cursor_byte = cmdline_state:cursor_byte()
106 + vim.api.nvim_buf_clear_namespace(state.buffer, ns, 0, -1)
107 + local cursor_col = icon_bytes + 1 + cursor_byte
108 + local anchor = position.get_cmdline_anchor()
109 + if anchor then
110 + anchor.cursor = cursor_col
111 + position.set_cmdline_anchor(anchor)
112 + end
113 + cursor.fix(state.window, cursor_col)
114 +end
116 +return M

neovim/lua/bugabinga/cmdline/state.lua

Added
new file mode 100644
1 +local M = {}
3 +function M.new(content, pos, firstc, prompt, indent, level)
4 + vim.validate({
5 + content = { content, 'table' },
6 + pos = { pos, 'number' },
7 + firstc = { firstc, 'string' },
8 + prompt = { prompt, 'string' },
9 + indent = { indent, 'number' },
10 + level = { level, 'number' },
11 + })
12 + return setmetatable({
13 + content = content,
14 + pos = pos,
15 + firstc = firstc,
16 + prompt = prompt,
17 + indent = indent,
18 + level = level,
19 + }, { __index = M })
20 +end
22 +function M:text()
23 + local parts = {}
24 + for _, chunk in ipairs(self.content) do
25 + table.insert(parts, chunk[2])
26 + end
27 + return table.concat(parts)
28 +end
30 +function M:cursor_byte()
31 + return self.pos
32 +end
34 +function M:is_search()
35 + return self.firstc == '/' or self.firstc == '?'
36 +end
38 +function M:is_input()
39 + return self.prompt ~= nil and self.prompt ~= ''
40 +end
42 +return M

neovim/lua/bugabinga/code_action.lua

Added
new file mode 100644
1 +local auto = require 'std.auto'
3 +local NS = vim.api.nvim_create_namespace 'bugabinga.code_action'
5 +local kind_icons = {
6 + ['source.fixAll'] = '●',
7 + ['quickfix'] = '◉',
8 + ['refactor.extract'] = '◎',
9 + ['source.organizeImports'] = '◎',
10 + ['source'] = '◎',
11 + ['refactor.move'] = '○',
12 + ['refactor'] = '○',
13 + [''] = '○',
16 +local kind_priority = {
17 + ['source.fixAll'] = 1,
18 + ['quickfix'] = 2,
19 + ['refactor.extract'] = 3,
20 + ['source.organizeImports'] = 3,
21 + ['source'] = 3,
22 + ['refactor.move'] = 4,
23 + ['refactor'] = 4,
24 + [''] = 5,
27 +local function resolve_kind(kind)
28 + local k = kind or ''
29 + while k ~= '' do
30 + if kind_icons[k] then return k end
31 + k = k:match '^(.+)%.[^%.]+$' or ''
32 + end
33 + return ''
34 +end
36 +local function get_kind_hl(kind)
37 + local k = resolve_kind(kind)
38 + return 'BugabingaCodeAction' .. (k == '' and 'Default' or k:gsub('%.', '_'):gsub('^%l', string.upper))
39 +end
41 +local function get_line_diagnostics(bufnr)
42 + local row = vim.api.nvim_win_get_cursor(0)[1] - 1
43 + local diagnostics = vim.diagnostic.get(bufnr, { lnum = row })
44 + local lsp_diagnostics = {}
45 + for _, d in ipairs(diagnostics) do
46 + if d.user_data and d.user_data.lsp then
47 + table.insert(lsp_diagnostics, d.user_data.lsp)
48 + end
49 + end
50 + return lsp_diagnostics
51 +end
53 +local function update(bufnr)
54 + bufnr = bufnr or vim.api.nvim_get_current_buf()
56 + local clients = vim.lsp.get_clients({ bufnr = bufnr, method = 'textDocument/codeAction' })
57 + if #clients == 0 then
58 + vim.api.nvim_buf_clear_namespace(bufnr, NS, 0, -1)
59 + return
60 + end
62 + local encoding = clients[1].offset_encoding or 'utf-16'
63 + local params = vim.lsp.util.make_range_params(0, encoding)
64 + params.context = { diagnostics = get_line_diagnostics(bufnr) }
66 + if vim.b[bufnr].bugabinga_code_action_cancel then
67 + vim.b[bufnr].bugabinga_code_action_cancel()
68 + end
70 + local cancel = vim.lsp.buf_request_all(bufnr, 'textDocument/codeAction', params, function(results)
71 + if not vim.api.nvim_buf_is_valid(bufnr) then return end
73 + local best_kind, best_prio = '', math.huge
74 + for _, resp in pairs(results) do
75 + if resp.result then
76 + for _, action in ipairs(resp.result) do
77 + local kind = action.kind or ''
78 + local prio = kind_priority[kind] or 99
79 + if prio < best_prio then
80 + best_prio = prio
81 + best_kind = kind
82 + end
83 + end
84 + end
85 + end
87 + vim.api.nvim_buf_clear_namespace(bufnr, NS, 0, -1)
89 + if best_kind ~= '' or best_prio ~= math.huge then
90 + local icon = kind_icons[resolve_kind(best_kind)] or '○'
91 + local hl = get_kind_hl(best_kind)
92 + local line = params.range.start.line
93 + vim.api.nvim_buf_set_extmark(bufnr, NS, line, 0, {
94 + sign_text = icon,
95 + sign_hl_group = hl,
96 + priority = 10,
97 + })
98 + end
99 + end)
101 + vim.b[bufnr].bugabinga_code_action_cancel = cancel
102 +end
104 +local function setup(bufnr)
105 + local group = vim.api.nvim_create_augroup(
106 + ('bugabinga.code_action.%d'):format(bufnr),
107 + { clear = true }
110 + vim.api.nvim_create_autocmd({ 'CursorHold', 'TextChanged', 'DiagnosticChanged' }, {
111 + group = group,
112 + buffer = bufnr,
113 + callback = function() update(bufnr) end,
114 + })
116 + vim.api.nvim_create_autocmd('InsertEnter', {
117 + group = group,
118 + buffer = bufnr,
119 + callback = function()
120 + vim.api.nvim_buf_clear_namespace(bufnr, NS, 0, -1)
121 + end,
122 + })
124 + vim.api.nvim_create_autocmd('InsertLeave', {
125 + group = group,
126 + buffer = bufnr,
127 + callback = function() update(bufnr) end,
128 + })
130 + vim.api.nvim_create_autocmd('LspDetach', {
131 + group = group,
132 + buffer = bufnr,
133 + callback = function()
134 + vim.api.nvim_buf_clear_namespace(bufnr, NS, 0, -1)
135 + end,
136 + })
137 +end
139 +auto 'code_action' {
140 + description = 'code action: show kind-specific circle sign when actions available',
141 + events = 'LspAttach',
142 + command = function(args)
143 + setup(args.buf)
144 + end,

neovim/lua/bugabinga/cycle.lua

Added
new file mode 100644
1 +local auto = require 'std.auto'
3 +local history = {}
5 +local state = {
6 + timer = nil,
7 + source_buf = nil,
8 + source_win = nil,
9 + popup_win = nil,
10 + popup_buf = nil,
11 + selecting_idx = 1,
12 + buffers = {},
13 + hl_ns = nil,
16 +local SETTLE_MS = 1000
17 +local MAX_HEIGHT = 100
18 +local ICON_WIDTH = 2
19 +local PATH_START_OFFSET = 3
21 +local function get_icon(buf_path)
22 + local ok, icon_data = pcall(require, 'mini.icons')
23 + if not ok then return ' ', '' end
24 + local icon, hl = icon_data.get('file', buf_path)
25 + return icon or ' ', hl or ''
26 +end
28 +local function truncate(str, max)
29 + if #str > max then
30 + return str:sub(1, max - 1) .. '…'
31 + end
32 + return str
33 +end
35 +local function shorten_path(full_path, max_len)
36 + local basename = vim.fs.basename(full_path)
37 + local abs_cwd = vim.fs.normalize(vim.fn.getcwd())
38 + local abs_path = vim.fs.normalize(full_path)
40 + if abs_path:find(abs_cwd, 1, true) ~= 1 then
41 + return #basename <= max_len and basename or truncate(basename, max_len)
42 + end
44 + local rel_path = abs_path:sub(#abs_cwd + 1)
45 + if rel_path:sub(1, 1) == '/' then
46 + rel_path = rel_path:sub(2)
47 + end
48 + rel_path = './' .. rel_path
50 + if #rel_path <= max_len then
51 + return rel_path
52 + end
54 + if #basename >= max_len then
55 + return truncate(basename, max_len)
56 + end
58 + local available = max_len - #basename - 1
59 + if available <= 0 then
60 + return basename
61 + end
63 + if #rel_path - #basename > available then
64 + local dirname_len = available - 1
65 + if dirname_len > 0 then
66 + local dirname_start = #rel_path - #basename - dirname_len
67 + rel_path = './…/' .. rel_path:sub(dirname_start)
68 + else
69 + rel_path = './…'
70 + end
71 + end
72 + return rel_path
73 +end
75 +local function render_item(b, idx, selecting_idx, width)
76 + local prefix = idx == selecting_idx and '› ' or ' '
77 + local full_path = b.name
78 + local icon, icon_hl = get_icon(full_path)
79 + local icon_len = #icon
80 + local rel_path = shorten_path(full_path, width - #prefix - icon_len - 1)
81 + local line = prefix .. icon .. ' ' .. rel_path
83 + local basename = vim.fs.basename(full_path)
84 + local basename_in_line = icon .. ' ' .. rel_path
85 + local name_start_byte = basename_in_line:find(basename, 1, true)
86 + local name_start = #prefix + (name_start_byte or 1)
87 + local name_end_exclusive = name_start + #basename
88 + local info = {
89 + line_idx = idx - 1,
90 + icon_hl = icon_hl ~= '' and icon_hl or nil,
91 + name_start = name_start,
92 + name_end_exclusive = name_end_exclusive,
93 + }
94 + return line, info
95 +end
97 +local function render_list(buffers, selecting_idx, width)
98 + local lines = {}
99 + local highlights = {}
100 + for i, b in ipairs(buffers) do
101 + local line, info = render_item(b, i, selecting_idx, width)
102 + lines[i] = line
103 + highlights[i] = info
104 + end
105 + return lines, highlights
106 +end
108 +local function get_listed_buffers()
109 + local cur = vim.api.nvim_get_current_buf()
110 + local result = {}
111 + for _, bufnr in ipairs(history) do
112 + if vim.api.nvim_buf_is_valid(bufnr) and vim.bo[bufnr].buflisted then
113 + local name = vim.api.nvim_buf_get_name(bufnr)
114 + if name ~= '' then
115 + table.insert(result, { bufnr = bufnr, name = name })
116 + end
117 + end
118 + end
119 + for _, info in ipairs(vim.fn.getbufinfo { buflisted = 1 }) do
120 + local bufnr = info.bufnr
121 + if vim.api.nvim_buf_is_valid(bufnr) and vim.bo[bufnr].buflisted and info.name ~= '' then
122 + local found = false
123 + for _, b in ipairs(result) do
124 + if b.bufnr == bufnr then found = true break end
125 + end
126 + if not found then
127 + table.insert(result, { bufnr = bufnr, name = info.name })
128 + end
129 + end
130 + end
131 + return result
132 +end
134 +local function close_popup()
135 + if state.popup_win and type(state.popup_win) == 'number' then
136 + local ok, valid = pcall(vim.api.nvim_win_is_valid, state.popup_win)
137 + if ok and valid then
138 + pcall(vim.api.nvim_win_close, state.popup_win, true)
139 + end
140 + end
141 + state.popup_win = nil
142 + state.popup_buf = nil
143 + state.selecting_idx = 1
144 + state.buffers = {}
145 + state.hl_ns = nil
146 +end
148 +local function cancel()
149 + if state.timer then
150 + state.timer:stop()
151 + state.timer:close()
152 + state.timer = nil
153 + end
154 + close_popup()
155 + if state.source_buf then
156 + local ok, valid = pcall(vim.api.nvim_buf_is_valid, state.source_buf)
157 + if ok and valid then
158 + pcall(vim.api.nvim_set_current_buf, state.source_buf)
159 + end
160 + end
161 +end
163 +local function commit_switch()
164 + local target = state.buffers[state.selecting_idx]
165 + if target then
166 + close_popup()
167 + vim.api.nvim_set_current_buf(target.bufnr)
168 + for i = #history, 1, -1 do
169 + if history[i] == target.bufnr then table.remove(history, i) end
170 + end
171 + table.insert(history, target.bufnr)
172 + if #history > 50 then table.remove(history, 1) end
173 + else
174 + close_popup()
175 + end
176 +end
178 +local function apply_highlights(bufnr, hl_ns, highlights)
179 + for _, h in ipairs(highlights) do
180 + if h.icon_hl then
181 + local icon_end = 3
182 + vim.api.nvim_buf_add_highlight(bufnr, hl_ns, h.icon_hl, h.line_idx, 0, 2)
183 + end
184 + vim.api.nvim_buf_add_highlight(bufnr, hl_ns, 'CycleBufferFileName', h.line_idx, h.name_start - 1, h.name_end_exclusive - 1)
185 + end
186 +end
188 +local function clear_highlights()
189 + if state.hl_ns and state.popup_buf and vim.api.nvim_buf_is_valid(state.popup_buf) then
190 + vim.api.nvim_buf_clear_highlight(state.popup_buf, state.hl_ns, 0, -1)
191 + end
192 +end
194 +local function open_popup()
195 + close_popup()
197 + state.buffers = get_listed_buffers()
198 + if #state.buffers == 0 then return end
200 + if state.selecting_idx > #state.buffers then
201 + state.selecting_idx = 1
202 + end
204 + local width = math.min(55, vim.o.columns - 4)
205 + local height = math.min(#state.buffers, MAX_HEIGHT)
206 + local row = math.floor((vim.o.lines - height) / 2) - 1
207 + local col = math.floor((vim.o.columns - width) / 2)
209 + state.popup_buf = vim.api.nvim_create_buf(false, true)
210 + state.hl_ns = vim.api.nvim_create_namespace('cycle_buffer')
212 + local lines, highlights = render_list(state.buffers, state.selecting_idx, width)
213 + vim.api.nvim_buf_set_lines(state.popup_buf, 0, -1, false, lines)
214 + vim.bo[state.popup_buf].modifiable = false
215 + vim.bo[state.popup_buf].filetype = 'CycleBuffer'
217 + local opts = {
218 + relative = 'editor',
219 + width = width,
220 + height = height,
221 + row = row,
222 + col = col,
223 + style = 'minimal',
224 + border = vim.g.border_style,
225 + focusable = false,
227 + state.popup_win = vim.api.nvim_open_win(state.popup_buf, true, opts)
228 + vim.wo[state.popup_win].cursorline = true
230 + apply_highlights(state.popup_buf, state.hl_ns, highlights)
232 + local mod = require 'bugabinga.cycle'
233 + vim.keymap.set('n', '<C-Tab>', function() mod.cycle(1) end, { buffer = state.popup_buf, silent = true })
234 + vim.keymap.set('n', '<C-S-Tab>', function() mod.cycle(-1) end, { buffer = state.popup_buf, silent = true })
235 + vim.keymap.set('n', '<Tab>', function() mod.cycle(1) end, { buffer = state.popup_buf, silent = true })
236 + vim.keymap.set('n', '<S-Tab>', function() mod.cycle(-1) end, { buffer = state.popup_buf, silent = true })
237 + vim.keymap.set('n', '<Esc>', cancel, { buffer = state.popup_buf, silent = true })
238 + vim.keymap.set('n', 'q', cancel, { buffer = state.popup_buf, silent = true })
239 +end
241 +local function cycle(direction)
242 + if state.timer then
243 + state.timer:stop()
244 + state.timer:close()
245 + state.timer = nil
246 + end
248 + if not state.popup_win then
249 + state.source_win = vim.api.nvim_get_current_win()
250 + state.source_buf = vim.api.nvim_get_current_buf()
251 + state.selecting_idx = 1
252 + open_popup()
253 + if not state.popup_win then
254 + vim.notify('buffer cycle: No other buffers', vim.log.levels.INFO)
255 + return
256 + end
257 + else
258 + state.selecting_idx = state.selecting_idx + direction
259 + if state.selecting_idx < 1 then state.selecting_idx = #state.buffers
260 + elseif state.selecting_idx > #state.buffers then state.selecting_idx = 1 end
261 + if state.popup_buf and vim.api.nvim_buf_is_valid(state.popup_buf) then
262 + local width = math.min(55, vim.o.columns - 4)
263 + local lines, highlights = render_list(state.buffers, state.selecting_idx, width)
264 + clear_highlights()
265 + local was_modifiable = vim.bo[state.popup_buf].modifiable
266 + vim.bo[state.popup_buf].modifiable = true
267 + vim.api.nvim_buf_set_lines(state.popup_buf, 0, -1, false, lines)
268 + vim.bo[state.popup_buf].modifiable = was_modifiable
269 + apply_highlights(state.popup_buf, state.hl_ns, highlights)
270 + vim.api.nvim_win_set_cursor(state.popup_win, { state.selecting_idx, 0 })
271 + end
272 + end
274 + local timer = vim.uv.new_timer()
275 + timer:start(SETTLE_MS, 0, vim.schedule_wrap(function()
276 + timer:stop()
277 + timer:close()
278 + state.timer = nil
279 + commit_switch()
280 + end))
281 + state.timer = timer
282 +end
284 +auto 'cycle_mru' {
285 + events = 'BufEnter',
286 + command = function()
287 + if state.popup_win then return end
288 + local bufnr = vim.api.nvim_get_current_buf()
289 + if not vim.bo[bufnr].buflisted then return end
290 + local name = vim.api.nvim_buf_get_name(bufnr)
291 + if name == '' then return end
292 + for i = #history, 1, -1 do
293 + if history[i] == bufnr then table.remove(history, i) end
294 + end
295 + table.insert(history, bufnr)
296 + if #history > 50 then table.remove(history, 1) end
297 + end,
300 +local map = require 'std.map'
302 +map.normal {
303 + description = 'Cycle to next MRU buffer.',
304 + category = 'cycle',
305 + keys = '<C-Tab>',
306 + command = function() cycle(1) end,
309 +map.normal {
310 + description = 'Cycle to previous MRU buffer.',
311 + category = 'cycle',
312 + keys = '<C-S-Tab>',
313 + command = function() cycle(-1) end,
316 +vim.api.nvim_create_autocmd('BufWipeout', {
317 + callback = function(args)
318 + for i = #history, 1, -1 do
319 + if history[i] == args.buf then table.remove(history, i) end
320 + end
321 + end,
324 +vim.api.nvim_create_autocmd('VimLeave', {
325 + once = true,
326 + callback = function()
327 + cancel()
328 + end,
331 +return {
332 + cycle = cycle,
333 + cancel = cancel,
334 + history = history,
335 + get_icon = get_icon,
336 + shorten_path = shorten_path,

neovim/lua/bugabinga/d2.lua

Added
new file mode 100644
1 +local auto = require 'std.auto'
2 +local map = require 'std.map'
3 +local user_command = require 'std.user_command'
5 +local NS = 'd2'
7 +local PREVIEW_BUF_NAME = 'D2_ASCII_PREVIEW'
8 +local PREVIEW_AUGRP = 'd2_preview_autosave'
9 +local preview_winnr = nil
11 +local d2_binary = vim.system({ 'd2', '--version' }, { text = true }):wait().code == 0
12 + and 'd2'
13 + or 'd2.exe'
15 +local preview_bufnr = function()
16 + return vim.fn.bufnr(PREVIEW_BUF_NAME)
17 +end
19 +local preview_window_exists = function()
20 + return preview_winnr ~= nil and vim.api.nvim_win_is_valid(preview_winnr)
21 +end
23 +local close_preview_window = function()
24 + if preview_winnr and vim.api.nvim_win_is_valid(preview_winnr) then
25 + vim.api.nvim_win_close(preview_winnr, true)
26 + preview_winnr = nil
27 + end
28 +end
30 +local render = function(bufnr)
31 + local input_file = vim.fn.tempname() .. '.d2'
32 + local output_file = vim.fn.tempname() .. '.txt'
33 + local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
34 + vim.fn.writefile(lines, input_file)
35 + local result = vim.system({ d2_binary, input_file, output_file }, { text = true }):wait()
36 + if result.code ~= 0 then
37 + vim.notify('d2 render failed: ' .. (result.stderr or ''), vim.log.levels.ERROR)
38 + return nil
39 + end
40 + local output_lines = vim.fn.readfile(output_file)
41 + if #output_lines > 0 and output_lines[1] == '' then
42 + table.remove(output_lines, 1)
43 + end
44 + vim.fn.delete(input_file)
45 + vim.fn.delete(output_file)
46 + return output_lines
47 +end
49 +local show_preview = function(output_lines)
50 + close_preview_window()
51 + local is_wide = vim.o.columns > vim.o.lines
52 + local pbufnr = vim.api.nvim_create_buf(false, true)
53 + vim.api.nvim_buf_set_name(pbufnr, PREVIEW_BUF_NAME)
54 + vim.api.nvim_buf_set_lines(pbufnr, 0, -1, false, output_lines)
55 + vim.api.nvim_set_option_value('buftype', 'nofile', { buf = pbufnr })
56 + vim.api.nvim_set_option_value('bufhidden', 'wipe', { buf = pbufnr })
57 + vim.api.nvim_set_option_value('swapfile', false, { buf = pbufnr })
58 + vim.api.nvim_set_option_value('modifiable', false, { buf = pbufnr })
59 + vim.api.nvim_set_option_value('readonly', true, { buf = pbufnr })
60 + local is_wide = vim.o.columns > 120
61 + if is_wide then
62 + vim.cmd(('vertical botright %dsplit %s'):format(math.floor(vim.o.columns * 0.4), PREVIEW_BUF_NAME))
63 + else
64 + vim.cmd(('belowright split %s'):format(PREVIEW_BUF_NAME))
65 + end
66 + local winnr = vim.fn.bufwinid(pbufnr)
67 + preview_winnr = winnr
68 + vim.api.nvim_set_option_value('number', false, { win = winnr })
69 + vim.api.nvim_set_option_value('wrap', false, { win = winnr })
70 + vim.api.nvim_set_option_value('spell', false, { win = winnr })
71 +end
73 +local preview_toggle = function()
74 + if preview_window_exists() then
75 + close_preview_window()
76 + return
77 + end
78 + local bufnr = vim.api.nvim_get_current_buf()
79 + local output = render(bufnr)
80 + if output then
81 + show_preview(output)
82 + end
83 +end
85 +local preview_update = function()
86 + if not preview_window_exists() then return end
87 + local cur_buf = vim.api.nvim_get_current_buf()
88 + local output = render(cur_buf)
89 + if output then
90 + local preview_buf = vim.fn.bufnr(PREVIEW_BUF_NAME)
91 + if preview_buf ~= -1 then
92 + vim.api.nvim_set_option_value('modifiable', true, { buf = preview_buf })
93 + vim.api.nvim_buf_set_lines(preview_buf, 0, -1, false, output)
94 + vim.api.nvim_set_option_value('modifiable', false, { buf = preview_buf })
95 + end
96 + end
97 +end
99 +local preview_copy = function()
100 + local pbnr = preview_bufnr()
101 + if pbnr == -1 then
102 + vim.notify('No D2 preview open', vim.log.levels.WARN)
103 + return
104 + end
105 + local lines = vim.api.nvim_buf_get_lines(pbnr, 0, -1, false)
106 + local text = table.concat(lines, '\n')
107 + vim.fn.setreg('+', text)
108 + vim.fn.setreg('*', text)
109 + vim.fn.setreg('"', text)
110 + vim.notify('D2 preview copied to clipboard')
111 +end
113 + local diag_ns = vim.api.nvim_create_namespace(NS)
116 +local parse_validate_output = function(stderr)
117 + local diagnostics = {}
118 + for line in stderr:gmatch '[^\r\n]+' do
119 + if line:match '^err:' then
120 + local suffix = line:gsub('^err:%s*', '')
121 + local lnum, col, msg = suffix:match '.*:%s*(%d+):(%d+):%s*(.*)'
122 + if lnum and col then
123 + table.insert(diagnostics, {
124 + lnum = tonumber(lnum) - 1,
125 + col = tonumber(col) - 1,
126 + end_col = tonumber(col),
127 + message = msg,
128 + severity = vim.diagnostic.severity.ERROR,
129 + source = 'd2',
130 + })
131 + else
132 + table.insert(diagnostics, {
133 + lnum = 0,
134 + col = 0,
135 + end_col = 0,
136 + message = suffix,
137 + severity = vim.diagnostic.severity.ERROR,
138 + source = 'd2',
139 + })
140 + end
141 + end
142 + end
143 + return diagnostics
144 +end
146 +local validate = function(args)
147 + local bufnr = (args and args.bufnr) or vim.api.nvim_get_current_buf()
148 + local file = vim.api.nvim_buf_get_name(bufnr)
149 + if not d2_binary then
150 + vim.notify('d2 binary not found', vim.log.levels.ERROR)
151 + return
152 + end
153 + if file == '' then
154 + return
155 + end
156 + local result = vim.system({ d2_binary, 'validate', file }, { text = true }):wait()
157 + vim.diagnostic.reset(nil, bufnr)
158 + if result.code ~= 0 then
159 + local diags = parse_validate_output(result.stderr)
160 + vim.diagnostic.set(diag_ns, bufnr, diags, {})
161 + vim.diagnostic.show(diag_ns, bufnr)
162 + end
163 +end
165 +local validate_toggle = function()
166 + local autocmds_ok, autocmds = pcall(vim.api.nvim_get_autocmds, {
167 + group = 'd2_validate_autosave',
168 + event = 'BufWritePost',
169 + pattern = '*.d2',
170 + })
171 + if autocmds_ok and #autocmds > 0 then
172 + pcall(vim.api.nvim_del_augroup_by_name, 'd2_validate_autosave')
173 + vim.notify('D2 auto-validate disabled', vim.log.levels.INFO)
174 + else
175 + auto 'd2_validate_autosave' {
176 + events = 'BufWritePost',
177 + pattern = '*.d2',
178 + description = 'Auto-validate d2 files on save',
179 + command = validate,
181 + vim.notify('D2 auto-validate enabled', vim.log.levels.INFO)
182 + end
183 +end
185 +map.normal {
186 + description = 'Toggle D2 ASCII preview',
187 + category = 'd2',
188 + keys = '<leader>dp',
189 + command = preview_toggle,
190 + buffer = 0,
193 +map.normal {
194 + description = 'Update D2 ASCII preview',
195 + category = 'd2',
196 + keys = '<leader>du',
197 + command = preview_update,
198 + buffer = 0,
201 +map.normal {
202 + description = 'Copy D2 preview to clipboard',
203 + category = 'd2',
204 + keys = '<leader>dy',
205 + command = preview_copy,
206 + buffer = 0,
209 +map.normal {
210 + description = 'Validate D2 file',
211 + category = 'd2',
212 + keys = '<leader>dv',
213 + command = validate,
214 + buffer = 0,
217 +user_command.D2Preview 'Open D2 ASCII preview' (preview_toggle)
218 +user_command.D2PreviewToggle 'Toggle D2 ASCII preview' (preview_toggle)
219 +user_command.D2Validate 'Validate D2 file' (validate)
220 +user_command.D2ValidateToggle 'Toggle D2 auto-validate' (validate_toggle)
222 +auto 'd2_preview_autosave' {
223 + events = 'BufWritePost',
224 + pattern = '*.d2',
225 + description = 'Auto-update D2 ASCII preview on save',
226 + command = preview_update,
229 +auto 'd2_validate_autosave' {
230 + events = { 'BufWritePost', 'BufReadPost', 'BufEnter' },
231 + pattern = '*.d2',
232 + description = 'Auto-validate d2 files',
233 + command = validate,
236 +auto 'd2_preview_keymaps' {
237 + events = 'BufEnter',
238 + pattern = PREVIEW_BUF_NAME,
239 + description = 'D2 preview buffer keymaps',
240 + command = function(args)
241 + local preview_buf = args.bufnr
242 + vim.keymap.set('n', '<leader>dp', preview_toggle, { buffer = preview_buf, desc = 'Toggle D2 preview' })
243 + vim.keymap.set('n', '<leader>du', preview_update, { buffer = preview_buf, desc = 'Update D2 preview' })
244 + vim.keymap.set('n', 'q', close_preview_window, { buffer = preview_buf, desc = 'Close D2 preview' })
245 + end,
248 +return {
249 + preview_toggle = preview_toggle,
250 + preview_update = preview_update,
251 + preview_copy = preview_copy,
252 + validate = validate,
253 + validate_toggle = validate_toggle,
254 + _parse_validate_output = parse_validate_output,

neovim/lua/bugabinga/devicons.lua

Modified
1 1 local puk = require 'std.puk'
2 2 puk.defer('mini.icons')(function(icons)
3 3 icons.setup {}
4 + icons.mock_nvim_web_devicons()
4 5 end)

neovim/lua/bugabinga/format.lua

Modified
37 37 toml = { 'taplo' },
38 38 sh = { 'shfmt' },
39 39 just = { 'just' },
40 + d2 = { 'd2_fmt' },
40 41 markdown = { 'deno_fmt' },
41 42 javascript = { 'deno_fmt' },
42 43 typescript = { 'deno_fmt' },

neovim/lua/bugabinga/grapple.lua

Added
new file mode 100644
1 +local puk = require 'std.puk'
2 +local map = require 'std.map'
4 +puk.defer 'grapple' (function(grapple)
5 + grapple.setup {
6 + scope = "git",
7 + icons = true,
8 + quick_select = "123456789",
9 + }
11 + map.normal { description = 'toggle tag on current file', category = 'grapple', keys = '<leader>mt', command = grapple.toggle }
12 + map.normal { description = 'open tags window', category = 'grapple', keys = '<leader>mT', command = grapple.toggle_tags }
13 + map.normal { description = 'cycle to next tag', category = 'grapple', keys = '<leader>mn', command = function() grapple.cycle_tags("next") end }
14 + map.normal { description = 'cycle to previous tag', category = 'grapple', keys = '<leader>mp', command = function() grapple.cycle_tags("prev") end }
15 + map.normal { description = 'select tag 1', category = 'grapple', keys = '<leader>1', command = function() grapple.select { index = 1 } end }
16 + map.normal { description = 'select tag 2', category = 'grapple', keys = '<leader>2', command = function() grapple.select { index = 2 } end }
17 + map.normal { description = 'select tag 3', category = 'grapple', keys = '<leader>3', command = function() grapple.select { index = 3 } end }
18 + map.normal { description = 'select tag 4', category = 'grapple', keys = '<leader>4', command = function() grapple.select { index = 4 } end }
19 + map.normal { description = 'select tag 5', category = 'grapple', keys = '<leader>5', command = function() grapple.select { index = 5 } end }
21 + require('bugabinga.statusline').register(function()
22 + if not grapple.exists() then return '' end
23 + return '󰛢 ' .. grapple.name_or_index()
24 + end)
25 +end)

neovim/lua/bugabinga/key_preview.lua

Modified
1 1 local puk = require 'std.puk'
3 -puk.defer 'mini.clue' (function(clue)
4 - clue.setup {
5 - window = {
6 - config = {
7 - width = 'auto'
8 - }
9 - },
10 - triggers = {
11 - -- Leader triggers
12 - { mode = 'n', keys = '<Leader>' },
13 - { mode = 'x', keys = '<Leader>' },
3 +puk.defer 'mini.clue' ( function ( clue )
4 + clue.setup {
5 + window = {
6 + config = {
7 + width = 'auto',
8 + },
9 + },
10 + triggers = {
11 + -- Leader triggers
12 + { mode = 'n', keys = '<Leader>' },
13 + { mode = 'x', keys = '<Leader>' },
15 - -- Built-in completion
16 - { mode = 'i', keys = '<C-x>' },
15 + -- Built-in completion
16 + { mode = 'i', keys = '<C-x>' },
18 - -- Movement
19 - { mode = 'n', keys = '[' },
20 - { mode = 'n', keys = ']' },
18 + -- Movement
19 + { mode = 'n', keys = '[' },
20 + { mode = 'n', keys = ']' },
22 - -- `g` key
23 - { mode = 'n', keys = 'g' },
24 - { mode = 'x', keys = 'g' },
22 + -- `g` key
23 + { mode = 'n', keys = 'g' },
24 + { mode = 'x', keys = 'g' },
26 - -- Marks
27 - { mode = 'n', keys = "'" },
28 - { mode = 'n', keys = '`' },
29 - { mode = 'x', keys = "'" },
30 - { mode = 'x', keys = '`' },
26 + -- Marks
27 + { mode = 'n', keys = "'" },
28 + { mode = 'n', keys = '`' },
29 + { mode = 'x', keys = "'" },
30 + { mode = 'x', keys = '`' },
32 - -- Registers
33 - { mode = 'n', keys = '"' },
34 - { mode = 'x', keys = '"' },
35 - { mode = 'i', keys = '<C-r>' },
36 - { mode = 'c', keys = '<C-r>' },
32 + -- Registers
33 + { mode = 'n', keys = '"' },
34 + { mode = 'x', keys = '"' },
35 + { mode = 'i', keys = '<C-r>' },
36 + { mode = 'c', keys = '<C-r>' },
38 - -- Window commands
39 - { mode = 'n', keys = '<C-w>' },
38 + -- Window commands
39 + { mode = 'n', keys = '<C-w>' },
41 - -- `z` key
42 - { mode = 'n', keys = 'z' },
43 - { mode = 'x', keys = 'z' },
44 - },
41 + -- `z` key
42 + { mode = 'n', keys = 'z' },
43 + { mode = 'x', keys = 'z' },
44 + },
46 - clues = {
47 - -- Enhance this by adding descriptions for <Leader> mapping groups
48 - { mode = 'n', keys = '<Leader>t', desc = '+Toggle' },
49 - { mode = 'n', keys = '<Leader>s', desc = '+Session' },
50 - { mode = 'n', keys = '<Leader>f', desc = '+Find' },
51 - { mode = 'n', keys = '<Leader>r', desc = '+Rules' },
52 - { mode = 'n', keys = '<Leader>x', desc = '+Neovim' },
53 - { mode = 'n', keys = '<Leader>o', desc = '+Operators' },
54 - { mode = 'n', keys = 'grw', desc = '+Workspace' },
55 - { mode = 'n', keys = 'grp', desc = '+Peek' },
56 - clue.gen_clues.builtin_completion(),
57 - clue.gen_clues.g(),
58 - clue.gen_clues.marks(),
59 - clue.gen_clues.registers(),
60 - clue.gen_clues.windows(),
61 - clue.gen_clues.z(),
62 - },
63 - }
64 -end)
46 + clues = {
47 + -- Enhance this by adding descriptions for <Leader> mapping groups
48 + { mode = 'n', keys = '<Leader>t', desc = '+Toggle' },
49 + { mode = 'n', keys = '<Leader>s', desc = '+Session' },
50 + { mode = 'n', keys = '<Leader>f', desc = '+Find' },
51 + { mode = 'n', keys = '<Leader>r', desc = '+Rules' },
52 + { mode = 'n', keys = '<Leader>n', desc = '+Notify' },
53 + { mode = 'n', keys = '<Leader>d', desc = '+D2' },
54 + { mode = 'n', keys = '<Leader>x', desc = '+Neovim' },
55 + { mode = 'n', keys = '<Leader>m', desc = '+Marks' },
56 + { mode = 'n', keys = '<Leader>o', desc = '+OpenCode' },
57 + { mode = 'n', keys = 'grw', desc = '+Workspace' },
58 + { mode = 'n', keys = 'grp', desc = '+Peek' },
59 + clue.gen_clues.builtin_completion(),
60 + clue.gen_clues.g(),
61 + clue.gen_clues.marks(),
62 + clue.gen_clues.registers(),
63 + clue.gen_clues.windows(),
64 + clue.gen_clues.z(),
65 + },
66 + }
67 +end )

neovim/lua/bugabinga/lsp.lua

Modified
16 16 semanticTokens = {
17 17 multilineTokenSupport = true,
19 + completion = {
20 + completionItem = {
21 + snippetSupport = true,
22 + },
23 + },
45 50 if not client then return end
47 52 if client:supports_method 'textDocument/completion' then
48 - vim.lsp.completion.enable( true, client.id, bufnr, { autotrigger = true } )
53 + vim.lsp.completion.enable( true, client.id, bufnr, {
54 + autotrigger = true,
55 + } )
51 58 if client.server_capabilities.inlayHintProvider then

neovim/lua/bugabinga/lsp_info.lua

Modified
1 1 local icon = require 'std.icon'
2 2 local table = require 'std.table'
4 +local cap_fields = {
5 + hoverProvider = 'Hover',
6 + definitionProvider = 'Go to Definition',
7 + referencesProvider = 'References',
8 + completionProvider = 'Completion',
9 + renameProvider = 'Rename',
10 + codeActionProvider = 'Code Actions',
11 + documentFormattingProvider = 'Formatting',
12 + documentSymbolProvider = 'Document Symbols',
13 + workspaceSymbolProvider = 'Workspace Symbols',
14 + inlayHintProvider = 'Inlay Hints',
15 + semanticTokensProvider = 'Semantic Tokens',
16 + signatureHelpProvider = 'Signature Help',
17 + declarationProvider = 'Go to Declaration',
18 + typeDefinitionProvider = 'Go to Type Definition',
19 + implementationProvider = 'Go to Implementation',
20 + documentHighlightProvider = 'Document Highlight',
21 + codeLensProvider = 'Code Lens',
22 + documentLinkProvider = 'Document Links',
23 + foldingRangeProvider = 'Folding Range',
24 + selectionRangeProvider = 'Selection Range',
25 + callHierarchyProvider = 'Call Hierarchy',
26 + documentRangeFormattingProvider = 'Range Formatting',
27 + documentOnTypeFormattingProvider = 'On-Type Formatting',
28 + diagnosticProvider = 'Pull Diagnostics',
29 + executeCommandProvider = 'Execute Command',
4 32 local function show(clients)
5 33 if #clients == 0 then
6 34 vim.notify('No active LSP clients', vim.log.levels.INFO)
29 57 for i, client in ipairs(clients) do
30 58 if i > 1 then table.insert(lines, '') end
31 59 table.insert(lines, string.format('# %s %s', icon.lsp, client.name))
32 61 local root = client.config.root_dir or 'No root'
33 62 table.insert(lines, string.format('**Root:** %s', root))
64 + if client.config.filetypes then
65 + table.insert(lines, string.format('**Filetypes:** %s', table.concat(client.config.filetypes, ', ')))
66 + end
34 68 table.insert(lines, string.format('**ID:** %d', client.id))
35 - if client.rpc and client.rpc.pid then
36 - table.insert(lines, string.format('**PID:** %d', client.rpc.pid))
69 + local cmd = client.config.cmd
70 + if type(cmd) == 'table' and cmd[1] then
71 + table.insert(lines, string.format('**Binary:** %s', cmd[1]))
38 - table.insert(lines, string.format('**Attached Buffers:** %d', #client.attached_buffers))
39 - if client.server_info and client.server_info.version then
40 - table.insert(lines, string.format('**Version:** %s', client.server_info.version))
41 - end
42 - table.insert(lines, '**Capabilities:**')
43 - local caps = client.server_capabilities
44 - local cap_list = {}
45 - if caps.hoverProvider then table.insert(cap_list, 'Hover') end
46 - if caps.definitionProvider then table.insert(cap_list, 'Definition') end
47 - if caps.referencesProvider then table.insert(cap_list, 'References') end
48 - if caps.completionProvider then table.insert(cap_list, 'Completion') end
49 - if caps.renameProvider then table.insert(cap_list, 'Rename') end
50 - if caps.codeActionProvider then table.insert(cap_list, 'Code Actions') end
51 - if caps.documentFormattingProvider then table.insert(cap_list, 'Formatting') end
52 - if caps.documentSymbolProvider then table.insert(cap_list, 'Document Symbols') end
53 - if caps.workspaceSymbolProvider then table.insert(cap_list, 'Workspace Symbols') end
54 - if caps.inlayHintProvider then table.insert(cap_list, 'Inlay Hints') end
55 - if caps.semanticTokensProvider then table.insert(cap_list, 'Semantic Tokens') end
56 - table.insert(lines, ' - ' .. table.concat(cap_list, ', '))
57 74 if client.workspace_folders and #client.workspace_folders > 0 then
58 75 table.insert(lines, '**Workspace Folders:**')
59 76 for _, wf in ipairs(client.workspace_folders) do
60 77 table.insert(lines, string.format(' - %s', wf.name))
81 + local caps = client.server_capabilities
82 + local cap_list = {}
83 + for field, name in pairs(cap_fields) do
84 + if caps[field] then cap_list[#cap_list + 1] = name end
85 + end
86 + table.insert(lines, string.format('**Capabilities (%d):**', #cap_list))
87 + table.insert(lines, ' ' .. table.concat(cap_list, ', '))
89 + if client.server_info and client.server_info.version then
90 + table.insert(lines, string.format('**Version:** %s', client.server_info.version))
91 + end
65 94 vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
66 95 vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
96 + vim.api.nvim_buf_set_option(buf, 'spell', false)
67 97 vim.api.nvim_buf_set_option(buf, 'wrap', true)
98 + vim.api.nvim_buf_set_option(buf, 'readonly', true)
99 + vim.api.nvim_buf_set_option(buf, 'modifiable', false)
68 100 vim.api.nvim_buf_set_keymap(buf, 'n', 'q', '<cmd>close<CR>', { noremap = true, silent = true })
69 101 vim.api.nvim_buf_set_keymap(buf, 'n', '<Esc>', '<cmd>close<CR>', { noremap = true, silent = true })
70 102 vim.api.nvim_set_current_win(win)

neovim/lua/bugabinga/notify.lua

Added
new file mode 100644
1 +local puk = require 'std.puk'
2 +local map = require 'std.map'
3 +local user_command = require 'std.user_command'
5 + puk.defer 'mini.notify' ( function ( notify )
6 + notify.setup {
7 + lsp_progress = {
8 + enable = true,
9 + duration_last = 1000,
10 + },
11 + window = {
12 + winblend = 25,
13 + config = function()
14 + local has_statusline = vim.o.laststatus > 0
15 + local pad = vim.o.cmdheight + (has_statusline and 1 or 0)
16 + return { anchor = 'SE', col = vim.o.columns, row = vim.o.lines - pad }
17 + end,
18 + },
19 + }
20 + vim.notify = notify.make_notify()
22 + user_command.NotifyHistory 'Show notification history' ( function ()
23 + notify.show_history()
24 + end )
26 + map.normal {
27 + keys = '<leader>nn',
28 + command = function() notify.show_history() end,
29 + description = 'show notification history',
30 + category = 'notify',
31 + }
32 +end )

neovim/lua/bugabinga/nugu/init.lua

Modified
106 106 _.NormalFloat { bg = _.NormalUi.bg }
107 107 _.FloatBorder { fg = ui_accent, bg = _.NormalFloat.bg }
108 108 _.FloatBorderCorner { fg = ui_accent, bg = _.Normal.bg }
109 +_.FloatShadow { bg = content_unfocus, blend = 80 }
110 +_.FloatShadowThrough { bg = content_unfocus, blend = 100 }
109 111 _.FloatTitle { fg = _.FloatBorder.fg, bg = _.FloatBorder.bg, bold = true }
112 +_.CycleBufferFileName { fg = ui_accent, bold = true }
113 +_.CycleBufferIcon { fg = ui_minor }
110 114 _.EndOfBuffer { bg = _.Normal.bg }
111 115 _.Comment { fg = content_important_global, bold = true }
112 116 _.NotifyBackground = _.NormalUi
146 150 _.PmenuSel { fg = ui_important_local, sp = ui_important_local, bg = _.Pmenu.bg, bold = true, underline = true }
147 151 _.PmenuSbar { bg = ui_unfocus }
148 152 _.PmenuThumb { bg = ui_minor }
153 +_.PmenuMatch { fg = content_focus, bold = true }
154 +_.PmenuMatchSel { fg = content_focus, bold = true }
155 +_.ComplMatchIns { fg = content_accent }
156 +_.PmenuKind { fg = ui_minor }
157 +_.PmenuKindSel { fg = ui_important_local }
158 +_.BugabingaCmdlineCursor { fg = ui_important_local, bg = ui_unfocus, bold = true }
149 159 _.Question { fg = ui_important_local, bold = true }
150 160 _.QuickFixLine = _.PmenuSel
151 161 _.SpecialKey { fg = error, bg = content_unfocus, bold = true }
163 173 _.Title { fg = content_important_global, sp = content_important_global, bold = true, underline = true }
164 174 _.Visual { bg = content_unfocus }
165 175 _.VisualNOS { bg = ui_unfocus }
176 +_.SnippetTabstop { bg = content_unfocus, sp = content_focus, underline = true }
166 177 _.WarningMsg { fg = warning, bold = true }
167 -_.WildMenu = _.Debug
178 +_.WildMenu = _.PmenuSel
168 179 _.TextYankPost { fg = content_backdrop, bg = ui_important_local }
170 181 _.String { fg = content_focus, italic = true }
224 235 _.DiagnosticVirtualTextWarn = _.DiagnosticWarn
225 236 _.DiagnosticVirtualTextInfo = _.DiagnosticInfo
226 237 _.DiagnosticVirtualTextHint = _.DiagnosticHint
227 -_.DiagnosticVirtualOkHint = _.DiagnosticOk
238 +_.DiagnosticVirtualTextOk = _.DiagnosticOk
228 239 _.DiagnosticUnderlineError { fg = _.DiagnosticError.fg, sp = _.DiagnosticError.fg, underdouble = true }
229 240 _.DiagnosticUnderlineWarn { fg = _.DiagnosticWarn.fg, sp = _.DiagnosticWarn.fg, underline = true }
230 241 _.DiagnosticUnderlineInfo { fg = _.DiagnosticInfo.fg, sp = _.DiagnosticInfo.fg, underdashed = true }
231 242 _.DiagnosticUnderlineHint { fg = _.DiagnosticHint.fg, sp = _.DiagnosticHint.fg, italic = true, underdotted = true }
232 243 _.DiagnosticUnderlineOk { fg = _.DiagnosticOk.fg, italic = true }
233 244 _.DiagnosticSignError = _.DiagnosticError
234 -_.DiagnosticSignWarn = _.DiagnosticWarn
235 -_.DiagnosticSignInfo = _.DiagnosticInfo
236 -_.DiagnosticSignHint = _.DiagnosticHint
237 -_.DiagnosticSignOk = _.DiagnosticOk
245 +_.DiagnosticSignWarn = _.DiagnosticWarn
246 +_.DiagnosticSignInfo = _.DiagnosticInfo
247 +_.DiagnosticSignHint = _.DiagnosticHint
248 +_.DiagnosticSignOk = _.DiagnosticOk
250 +_.BugabingaCodeActionFixAll = _.DiagnosticWarn
251 +_.BugabingaCodeActionQuickFix = _.DiagnosticHint
252 +_.BugabingaCodeActionRefactor = _.DiagnosticInfo
253 +_.BugabingaCodeActionRefactorExtract = _.DiagnosticInfo
254 +_.BugabingaCodeActionRefactorMove = _.DiagnosticInfo
255 +_.BugabingaCodeActionSource = _.DiagnosticHint
256 +_.BugabingaCodeActionSourceImports = _.DiagnosticHint
257 +_.BugabingaCodeActionDefault = _.DiagnosticHint
239 259 _.LspReferenceText { sp = content_unfocus, underline = true }
240 260 _.LspReferenceRead = _.LspReferenceText
241 261 _.LspReferenceWrite = _.LspReferenceText
242 262 _.LspInlayHint { fg = content_minor, bg = _.Normal.bg }
243 -_.LspSignatureActiveParameter = _.Debug
263 +_.LspSignatureActiveParameter = _.PmenuSel
245 265 _.MiniHipatternsFixme { fg = ui_backdrop, bg = _.DiagnosticError.fg, bold = true, underline = true }
246 266 _.MiniHipatternsHack { fg = ui_backdrop, bg = _.DiagnosticWarn.fg, bold = true, underline = true }

neovim/lua/bugabinga/opencode.lua

Added
new file mode 100644
1 +local map = require 'std.map'
2 +local auto = require 'std.auto'
3 +local puk = require 'std.puk'
5 +puk 'opencode'
7 +vim.g.opencode_opts = {
8 + lsp = {
9 + enabled = true,
10 + },
11 + events = {
12 + enabled = true,
13 + reload = true,
14 + permissions = {
15 + enabled = true,
16 + edits = {
17 + enabled = true,
18 + },
19 + },
20 + },
23 +vim.o.autoread = true -- Required for `opts.events.reload`
25 +local opencode = require 'opencode'
27 +require('bugabinga.statusline').register(function()
28 + local ok, status = pcall(opencode.statusline)
29 + if not ok then return '' end
30 + return status
31 +end)
33 +map.normal.terminal {
34 + description = 'toggle opencode terminal',
35 + category = 'opencode',
36 + keys = '<C-.>',
37 + command = function ()
38 + opencode.toggle()
39 + end,
42 +map.normal.visual {
43 + description = 'ask opencode (with @this)',
44 + category = 'opencode',
45 + keys = '<leader>oa',
46 + command = function ()
47 + opencode.ask( '@this: ', { submit = true } )
48 + end,
51 +map.normal {
52 + description = 'ask opencode (free form)',
53 + category = 'opencode',
54 + keys = '<leader>oA',
55 + command = function ()
56 + opencode.ask()
57 + end,
60 +map.normal.visual {
61 + description = 'opencode picker',
62 + category = 'opencode',
63 + keys = '<leader>ox',
64 + command = function ()
65 + opencode.select()
66 + end,
69 +map.normal {
70 + description = 'scroll opencode up',
71 + category = 'opencode',
72 + keys = '<S-C-u>',
73 + command = function ()
74 + opencode.command 'session.half.page.up'
75 + end,
78 +map.normal {
79 + description = 'scroll opencode down',
80 + category = 'opencode',
81 + keys = '<S-C-d>',
82 + command = function ()
83 + opencode.command 'session.half.page.down'
84 + end,
87 +map.normal.visual {
88 + description = 'send motion to opencode',
89 + category = 'opencode',
90 + keys = 'go',
91 + command = function ()
92 + return opencode.operator '@this '
93 + end,
94 + expr = true,
97 +map.normal {
98 + description = 'send current line to opencode',
99 + category = 'opencode',
100 + keys = 'goo',
101 + command = function ()
102 + return opencode.operator '@this ' .. '_'
103 + end,
104 + expr = true,
107 +auto 'opencode_events' {
108 + events = 'User',
109 + pattern = 'OpencodeEvent:*',
110 + command = function ( args )
111 + local event = args.data.event
112 + if event.type == 'session.idle' then
113 + vim.notify( '`opencode` finished responding', vim.log.levels.INFO )
114 + elseif event.type == 'session.error' then
115 + vim.notify( '`opencode` encountered an error', vim.log.levels.ERROR )
116 + end
117 + end,

neovim/lua/bugabinga/options/behaviour.lua

Modified
26 26 end,
29 +auto 'restore_cursor_position' {
30 + description = 'Restore cursor position when opening a file',
31 + events = 'BufReadPost',
32 + command = function(ev)
33 + if dbg.get() then
34 + vim.notify(string.format('RCP stage1: buf=%d cursor_line=%d mark_line=%d',
35 + ev.buf, vim.fn.line('.'), vim.fn.line([['"]])), vim.log.levels.DEBUG)
36 + end
38 + local ft = vim.bo[ev.buf].filetype
39 + local bt = vim.bo[ev.buf].buftype
41 + if ignored.buftypes_kv[bt] then return end
42 + if ignored.filetypes_kv[ft] then return end
43 + for _, pattern in ipairs(ignored.filetypes_patterns) do
44 + if ft:find(pattern) then return end
45 + end
47 + local cursor_line = vim.fn.line('.')
48 + local mark_line = vim.fn.line([['"]])
49 + if cursor_line == mark_line then return end
51 + local col = vim.fn.col([['"]]) - 1
52 + if mark_line > 0 and mark_line <= vim.fn.line('$') then
53 + if dbg.get() then
54 + vim.notify(string.format('RCP: creating stage2 for line=%d col=%d', mark_line, col), vim.log.levels.DEBUG)
55 + end
56 + auto 'restore_cursor_stage2' {
57 + events = 'BufWinEnter',
58 + buffer = ev.buf,
59 + once = true,
60 + command = function()
61 + if dbg.get() then
62 + vim.notify(string.format('RCP stage2: restoring to %d,%d', mark_line, col), vim.log.levels.DEBUG)
63 + end
64 + vim.api.nvim_win_set_cursor(0, { mark_line, col })
65 + vim.cmd.normal { 'zvzz', bang = true }
66 + end,
67 + }
68 + end
69 + end,
29 72 auto 'handle_usr1_signal' {
30 73 description = 'Reloads the current theme, when USR1 signal is received',
31 74 events = { 'Signal' },

neovim/lua/bugabinga/options/core.lua

Modified
49 49 vim.opt.path:append '**'
50 50 -- ignore some files from path
51 51 vim.opt.wildignore = {
52 - "*.o",
53 - "*.obj",
54 - "*.class",
55 - "*.jar",
56 - "*.zig-cache",
57 - "zig-out/*",
58 - "target/*",
59 - "output/*",
60 - "*.rlib",
61 - "*.dylib",
62 - "*.so",
63 - "*.a",
64 - "*.exe",
65 - "*.dll",
66 - "*.pdb",
67 - "*.mod",
68 - "*.sum",
69 - "*.swp",
70 - "*.swo",
71 - "*.tmp",
72 - "*.bak",
73 - "*/vendor/*",
74 - "*/node_modules/*",
75 - "*/.git/*",
52 + '*.o',
53 + '*.obj',
54 + '*.class',
55 + '*.jar',
56 + '*.zig-cache',
57 + 'zig-out/*',
58 + 'target/*',
59 + 'output/*',
60 + '*.rlib',
61 + '*.dylib',
62 + '*.so',
63 + '*.a',
64 + '*.exe',
65 + '*.dll',
66 + '*.pdb',
67 + '*.mod',
68 + '*.sum',
69 + '*.swp',
70 + '*.swo',
71 + '*.tmp',
72 + '*.bak',
73 + '*/vendor/*',
74 + '*/node_modules/*',
75 + '*/.git/*',
78 78 -- wrap line movements, when start/end is reached
139 139 -- show trailing whitespace
140 140 vim.opt.list = false
141 141 vim.opt.listchars = {
142 - space = icon.space,
143 - eol = icon.eol,
144 - tab = icon.tab .. icon.middle_ellipsis,
145 - -- tab = ' ',
146 - trail = icon.trail,
147 - extends = icon.extends,
148 - precedes = icon.precedes,
149 - nbsp = icon.nbsp,
142 + space = icon.space,
143 + eol = icon.eol,
144 + tab = icon.tab .. icon.middle_ellipsis,
145 + -- tab = ' ',
146 + trail = icon.trail,
147 + extends = icon.extends,
148 + precedes = icon.precedes,
149 + nbsp = icon.nbsp,
152 152 -- do not spam the cmdline with every little input
160 160 -- completion popup in buffer
161 161 vim.opt.completeopt:append 'menuone'
162 -vim.opt.completeopt:append 'noselect'
163 -vim.opt.completeopt:append 'popup'
162 +vim.opt.completeopt:append 'preview'
163 +vim.opt.completeopt:append 'preinsert'
165 165 -- always display the signcolumn to avoid jitter
166 166 vim.opt.signcolumn = 'yes:2'
174 174 -- hide weird symbol at end of buffer
175 175 vim.opt.fillchars = {
176 - eob = ' ',
177 - lastline = ' ',
178 - diff = '╱',
179 - wbr = ' ',
176 + eob = ' ',
177 + lastline = ' ',
178 + diff = '╱',
179 + wbr = ' ',
181 - horiz = '─',
182 - horizup = '┴',
183 - horizdown = '┬',
184 - vert = '│',
185 - vertleft = '┤',
186 - vertright = '├',
187 - verthoriz = '┼',
181 + horiz = '─',
182 + horizup = '┴',
183 + horizdown = '┬',
184 + vert = '│',
185 + vertleft = '┤',
186 + vertright = '├',
187 + verthoriz = '┼',
190 +vim.opt.winborder = 'shadow'
190 192 -- better have no syntax highlighting than regex based, treesitter will take over later
191 193 vim.opt.syntax = 'off'
222 224 -- use this in various places for consistent border style
223 225 vim.g.border_style = {
224 - { "🬷", 'FloatBorderCorner' }, -- top left
225 - { "▔", 'FloatBorder' }, -- top
226 - { "🬲", 'FloatBorderCorner' }, -- top right
227 - { "🮈", 'FloatBorder' }, -- right
228 - { "🬕", 'FloatBorderCorner' }, -- bottom right
229 - { "▁", 'FloatBorder' }, -- bottom
230 - { "🬨", 'FloatBorderCorner' }, -- bottom left
231 - { "▍", 'FloatBorder' }, -- left
226 + { '🬷', 'FloatBorderCorner' }, -- top left
227 + { '▔', 'FloatBorder' }, -- top
228 + { '🬲', 'FloatBorderCorner' }, -- top right
229 + { '🮈', 'FloatBorder' }, -- right
230 + { '🬕', 'FloatBorderCorner' }, -- bottom right
231 + { '▁', 'FloatBorder' }, -- bottom
232 + { '🬨', 'FloatBorderCorner' }, -- bottom left
233 + { '▍', 'FloatBorder' }, -- left
234 236 -- hide the mode indicator in status

neovim/lua/bugabinga/options/init.lua

Modified
3 3 # keymaps sets leader key. needs to be early
4 4 require 'bugabinga.options.keymaps'
5 5 require 'bugabinga.options.filetypes'
6 6 require 'bugabinga.options.core'
8 +-- behaviour must load synchronously so its BufReadPost autocmds are registered
9 +-- before the first file is loaded ( BufReadPost fires during startup, not after )
10 +require 'bugabinga.options.behaviour'
8 12 vim.schedule(function()
9 - require 'bugabinga.options.behaviour'
10 13 require 'bugabinga.options.spelling'
11 14 require 'bugabinga.options.commands'
12 15 require 'bugabinga.options.menus'

neovim/lua/bugabinga/snippet.lua

Added
new file mode 100644
1 +local auto = require 'std.auto'
3 +auto 'snippet_cleanup' {
4 + events = 'InsertLeave',
5 + command = function()
6 + if vim.snippet.active() then
7 + vim.snippet.stop()
8 + end
9 + end,

neovim/lua/bugabinga/statusline.lua

Modified
30 30 return '%@v:lua.__bugabinga_lsp_click@' .. icon.lsp .. ' ' .. count .. '%X'
33 +local registered = {}
35 +local function register(fn)
36 + table.insert(registered, fn)
37 +end
39 +local function plugins_component()
40 + local results = vim.tbl_map(function(fn) return fn() end, registered)
41 + local filtered = vim.tbl_filter(function(c) return c ~= '' end, results)
42 + return table.concat(filtered, ' ')
43 +end
33 45 local function file_component()
34 46 local path = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ':~:.')
35 47 -- Truncate keeping last components visible (37 chars + ...)
77 89 local components = {
78 90 mode_component(),
79 91 lsp_component(),
92 + plugins_component(),
80 93 file_component(),
81 94 git_component(),
82 95 '%=' .. position_component(), -- right-align position
132 145 return setmetatable({
133 146 setup = setup,
147 + register = register,
134 148 git_component = git_component,
135 149 _get_cache = function() return cache end,
136 150 _get_cached_cwd = function() return cached_cwd end,

neovim/lua/bugabinga/suppress_warnings.lua

Added
new file mode 100644
1 +local puk = require 'std.puk'
2 +local map = require 'std.map'
4 +puk.defer 'rulebook' (function(rulebook)
5 + rulebook.setup()
6 + map.normal {
7 + description = 'ignore rule',
8 + category = 'lint',
9 + keys = '<leader>ri',
10 + command = rulebook.ignoreRule,
11 + }
12 + map.normal {
13 + description = 'lookup rule',
14 + category = 'lint',
15 + keys = '<leader>rl',
16 + command = rulebook.lookupRule,
17 + }
18 + map.normal {
19 + description = 'yank diagnostic code',
20 + category = 'lint',
21 + keys = '<leader>ry',
22 + command = rulebook.yankDiagnosticCode,
23 + }
24 + map.normal {
25 + description = 'supress formatter',
26 + category = 'lint',
27 + keys = '<leader>rf',
28 + command = rulebook.suppressFormatter,
29 + }
30 +end)

neovim/lua/bugabinga/supress_warnings.lua

Deleted
deleted file mode 100644
1 -local puk = require 'std.puk'
2 -local map = require 'std.map'
4 -puk.defer 'rulebook' (function(rulebook)
5 - rulebook.setup()
6 - map.normal {
7 - description = 'ignore rule',
8 - category = 'lint',
9 - keys = '<leader>ri',
10 - command = rulebook.ignoreRule,
11 - }
12 - map.normal {
13 - description = 'lookup rule',
14 - category = 'lint',
15 - keys = '<leader>rl',
16 - command = rulebook.lookupRule,
17 - }
18 - map.normal {
19 - description = 'yank diagnostic code',
20 - category = 'lint',
21 - keys = '<leader>ry',
22 - command = rulebook.yankDiagnosticCode,
23 - }
24 - map.normal {
25 - description = 'supress formatter',
26 - category = 'lint',
27 - keys = '<leader>rf',
28 - command = rulebook.suppressFormatter,
29 - }
30 -end)

neovim/lua/bugabinga/treesitter.lua

Modified
9 9 add_dependency { name_of_executable = 'tar' }
10 10 add_dependency { name_of_executable = 'curl' }
12 -local function is_ignored(match)
13 - for _, v in ipairs(ignored.filetypes) do
14 - if v == match or match:match(v) then
12 +local function is_ignored( match )
13 + for _, v in ipairs( ignored.filetypes ) do
14 + if v == match or match:match( v ) then
15 15 return true
21 21 local treesitter = puk 'nvim-treesitter'
22 22 treesitter.setup {}
24 - auto 'look_for_treesitter_parser' {
24 +auto 'look_for_treesitter_parser' {
25 25 description = 'Try loading a treesitter parser, if available.',
26 26 events = 'FileType',
27 27 pattern = '*',
28 - command = function(data)
28 + command = function ( data )
29 29 local match = data.match
30 30 if match == 'text' then return end
31 - if is_ignored(match) then
32 - dbg.print('Ignore ' .. match .. ' for treesitter.')
31 + if is_ignored( match ) then
32 + dbg.print( 'Ignore ' .. match .. ' for treesitter.' )
33 33 return
35 - local ok, _ = pcall(vim.treesitter.start, data.buf)
35 + local ok, _ = pcall( vim.treesitter.start, data.buf )
36 36 if not ok then
37 37 local available = require 'nvim-treesitter.parsers'
38 38 local potential_parser = available[match]
39 39 if potential_parser then
40 - vim.notify('Found potential treesitter parser for current filetype. Trying to install it. ' .. match)
41 - local task = require 'nvim-treesitter.install'.install(match, { force = false })
42 - task:await(function(err, success)
40 + vim.notify( 'Found potential treesitter parser for current filetype. Trying to install it. ' .. match )
41 + local task = require 'nvim-treesitter.install'.install( match, { force = false } )
42 + task:await( function ( err, success )
43 43 if not success then
44 - vim.notify('Failed to install treesitter parser: ' .. match, vim.log.levels.ERROR)
44 + vim.notify( 'Failed to install treesitter parser: ' .. match, vim.log.levels.ERROR )
45 45 return
47 - vim.treesitter.start(data.buf)
48 - end)
47 + vim.treesitter.start( data.buf )
48 + end )
50 50 return
56 56 -- add asciidoc parser
57 57 auto 'install_asciidoc_parser' {
58 - description = "Install asciidoc parser into nvim-treesitter",
58 + description = 'Install asciidoc parser into nvim-treesitter',
59 59 events = 'User',
60 60 pattern = 'TSUpdate',
61 - command = function()
62 - require('nvim-treesitter.parsers').asciidoc = {
61 + command = function ()
62 + require 'nvim-treesitter.parsers'.asciidoc = {
63 63 install_info = {
64 64 url = 'https://github.com/cathaysia/tree-sitter-asciidoc',
65 - revision = "5b6ccea9953b939959f447f7bfea699ae6968a99",
65 + revision = '5b6ccea9953b939959f447f7bfea699ae6968a99',
66 66 branch = 'master', -- only needed if different from default branch
67 67 location = 'tree-sitter-asciidoc',
68 68 generate = false,
73 73 end,
75 75 -- add d2 parser
76 -vim.treesitter.language.register("d2", "d2")
76 +vim.treesitter.language.register( 'd2', 'd2' )
77 77 auto 'install_d2_parser' {
78 - description = "Install d2 parser into nvim-treesitter",
78 + description = 'Install d2 parser into nvim-treesitter',
79 79 events = 'User',
80 80 pattern = 'TSUpdate',
81 - command = function()
82 - require('nvim-treesitter.parsers').d2 = {
81 + command = function ()
82 + require 'nvim-treesitter.parsers'.d2 = {
83 83 install_info = {
84 84 url = 'https://github.com/ravsii/tree-sitter-d2',
85 - revision = '519f92699691d101d1aa91f69956383de7b28ae6',
85 + revision = 'ffb66ce4c801a1e37ed145ebd5eca1ea8865e00f',
86 86 branch = 'main', -- only needed if different from default branch
87 87 generate = true,
88 88 generate_from_json = true,

neovim/lua/std/auto.lua

Modified
26 26 else
27 27 command = autocommand.command
29 - vim.api.nvim_create_autocmd(autocommand.events, {
30 - desc = autocommand.description,
31 - group = group,
32 - buffer = autocommand.buffer,
33 - pattern = autocommand.pattern,
34 - once = autocommand.once,
35 - command = command,
36 - callback = callback,
37 - })
29 + vim.api.nvim_create_autocmd(autocommand.events, {
30 + desc = autocommand.description,
31 + group = autocommand.buffer and nil or group,
32 + buffer = autocommand.buffer,
33 + pattern = autocommand.pattern,
34 + once = autocommand.once,
35 + command = command,
36 + callback = callback,
37 + })

neovim/lua/std/cheatsheet.lua

Deleted
deleted file mode 100644
1 -local buffer_options = {
2 - bufhidden = 'hide',
3 - modifiable = false,
4 - filetype = 'markdown',
5 -}
7 -local window_border = 'shadow'
9 -local window_options = {
10 - winblend = 42,
13 -local calculate_dimensions = function()
14 - local height = math.ceil(vim.o.lines * 0.6)
15 - local width = math.ceil(vim.o.columns * 0.7)
16 - return {
17 - height = height,
18 - width = width,
19 - row = math.ceil((vim.o.lines - height) / 2),
20 - col = math.ceil((vim.o.columns - width) / 2),
21 - }
22 -end
24 -local categories = {
25 - lsp = 'LSP',
26 - fuzzy = 'FZF',
27 - files = 'FILE',
28 - terminal = 'TERM',
29 - editing = 'EDIT',
30 - search = 'FIND',
31 - session = 'SESS',
32 - diff = 'DIFF',
33 - operator = 'OP',
34 - fun = 'FUN',
37 -local category_patterns = {
38 - '^lsp: ', 'lsp',
39 - '^fuzzy: ', 'fuzzy',
40 - '^files: ', 'files',
41 - '^terminal: ', 'terminal',
42 - '^editing: ', 'editing',
43 - '^search: ', 'search',
44 - '^session: ', 'session',
45 - '^diff: ', 'diff',
46 - '^operator: ', 'operator',
47 - '^fun: ', 'fun',
50 -local get_category_icon = function(category)
51 - return categories[category] or category:upper()
52 -end
54 -local parse_description = function(desc)
55 - if not desc or desc == '' then
56 - return 'general', '*no description*'
57 - end
59 - for i = 1, #category_patterns, 2 do
60 - local pattern, category = category_patterns[i], category_patterns[i + 1]
61 - if desc:match(pattern) then
62 - return category, desc:gsub(pattern, '')
63 - end
64 - end
66 - return 'general', desc
67 -end
69 -local format_keymaps = function(keymaps)
70 - if not keymaps or #keymaps == 0 then
71 - return { '*No keymaps configured*' }
72 - end
74 - local lines = {}
75 - local current_category = nil
77 - for _, km in ipairs(keymaps) do
78 - local category = km.category or 'general'
79 - if category ~= current_category then
80 - if current_category ~= nil then
81 - table.insert(lines, '')
82 - end
83 - table.insert(lines, '### ' .. get_category_icon(category) .. ' ' .. category:upper())
84 - table.insert(lines, '')
85 - current_category = category
86 - end
88 - local keys = km.keys
89 - if type(keys) == 'table' then
90 - keys = table.concat(keys, ', ')
91 - end
93 - local desc = km.description or '*no description*'
94 - table.insert(lines, '`' .. keys .. '` ' .. desc)
95 - end
97 - return lines
98 -end
100 -local collect_keymaps = function()
101 - local keymaps = {}
103 - local modes = { 'n', 'v', 'i', 'x', 's', 'o', 'c', 't' }
104 - local buffer = vim.api.nvim_get_current_buf()
106 - for _, mode in ipairs(modes) do
107 - local mode_keymaps = vim.api.nvim_buf_get_keymap(buffer, mode)
108 - for _, km in ipairs(mode_keymaps) do
109 - local category, description = parse_description(km.desc)
110 - table.insert(keymaps, {
111 - keys = km.lhs,
112 - description = description,
113 - category = category,
114 - mode = mode,
115 - })
116 - end
117 - end
119 - table.sort(keymaps, function(a, b)
120 - if a.category ~= b.category then
121 - return a.category < b.category
122 - end
123 - return a.keys < b.keys
124 - end)
126 - return keymaps
127 -end
129 -local is_cheatsheet_open = function()
130 - for _, win in ipairs(vim.api.nvim_list_wins()) do
131 - local buf = vim.api.nvim_win_get_buf(win)
132 - if vim.bo[buf].filetype == 'markdown' then
133 - local lines = vim.api.nvim_buf_get_lines(buf, 0, 2, false)
134 - if lines[1] and lines[1]:match('^# Cheat Sheet') then
135 - return win
136 - end
137 - end
138 - end
139 - return nil
140 -end
142 -local close = function(win)
143 - if win and vim.api.nvim_win_is_valid(win) then
144 - vim.api.nvim_win_close(win, false)
145 - end
146 -end
148 -local open = function()
149 - local existing_win = is_cheatsheet_open()
150 - if existing_win then
151 - close(existing_win)
152 - return
153 - end
155 - local buffer = vim.api.nvim_create_buf(false, true)
157 - local dimensions = calculate_dimensions()
159 - vim.api.nvim_buf_set_lines(buffer, 0, -1, false, {
160 - '# Cheat Sheet',
161 - '',
162 - '> Quick reference for keybindings',
163 - '',
164 - '*Press `<esc>` or `q` to close*',
165 - '',
166 - })
168 - local keymaps = collect_keymaps()
169 - local formatted = format_keymaps(keymaps)
171 - if #formatted > 0 then
172 - vim.api.nvim_buf_set_lines(buffer, #{}, -1, false, formatted)
173 - end
175 - for name, value in pairs(buffer_options) do
176 - vim.api.nvim_set_option_value(name, value, {
177 - scope = 'local',
178 - buf = buffer,
179 - })
180 - end
182 - local window = vim.api.nvim_open_win(buffer, true, {
183 - border = window_border,
184 - relative = 'editor',
185 - style = 'minimal',
186 - height = dimensions.height,
187 - width = dimensions.width,
188 - row = dimensions.row,
189 - col = dimensions.col,
190 - })
192 - for name, value in pairs(window_options) do
193 - vim.api.nvim_set_option_value(name, value, {
194 - scope = 'local',
195 - win = window,
196 - })
197 - end
199 - vim.api.nvim_buf_set_keymap(buffer, 'n', '<esc>', '', {
200 - noremap = true,
201 - silent = true,
202 - callback = function()
203 - close(window)
204 - end,
205 - })
207 - vim.api.nvim_buf_set_keymap(buffer, 'n', 'q', '', {
208 - noremap = true,
209 - silent = true,
210 - callback = function()
211 - close(window)
212 - end,
213 - })
215 - vim.api.nvim_buf_set_option(buffer, 'modifiable', false)
216 -end
218 -local toggle = function()
219 - local existing_win = is_cheatsheet_open()
220 - if existing_win then
221 - close(existing_win)
222 - else
223 - open()
224 - end
225 -end
227 -return {
228 - open = open,
229 - toggle = toggle,

neovim/lua/std/icon.lua

Modified
115 115 visual = '󰒉',
116 116 warn = '󰱯',
117 117 wrap = '󰖶',
118 + bookmark = '󰚰',
119 + clock = '󰥔',
120 + edit = '󰏫',
121 + format = '󰁦',
122 + hammer = '󱁢',
123 + search = '󰍉',
124 + star = '󰧑',

neovim/tests/bugabinga/cmdline/cursor_spec.lua

Added
new file mode 100644
1 +local cursor = require 'bugabinga.cmdline.cursor'
3 +describe('cursor.fix', function()
4 + before_each(function()
5 + package.loaded['bugabinga.cmdline.cursor'] = nil
6 + end)
8 + it('does not error when window is invalid', function()
9 + local cur = require 'bugabinga.cmdline.cursor'
10 + local ok = pcall(function()
11 + cur.fix(9999, 5)
12 + end)
13 + assert.is_true(ok)
14 + end)
15 +end)

neovim/tests/bugabinga/cmdline/format_spec.lua

Added
new file mode 100644
1 +local format = require 'bugabinga.cmdline.format'
3 +describe('format.detect', function()
4 + it('detects : as cmdline', function()
5 + local result = format.detect(':', 'hello', '')
6 + assert.equals('cmdline', result.type)
7 + assert.equals('󰘳', result.icon)
8 + end)
10 + it('detects / as search_down', function()
11 + local result = format.detect('/', 'hello', '')
12 + assert.equals('search_down', result.type)
13 + assert.equals('󰍉', result.icon)
14 + end)
16 + it('detects ? as search_up', function()
17 + local result = format.detect('?', 'hello', '')
18 + assert.equals('search_up', result.type)
19 + assert.equals('󰍉', result.icon)
20 + end)
22 + it('detects :lua as lua', function()
23 + local result = format.detect(':', 'lua print("hi")', '')
24 + assert.equals('lua', result.type)
25 + assert.equals('', result.icon)
26 + end)
28 + it('detects := as lua', function()
29 + local result = format.detect(':', '= { foo = 1 }', '')
30 + assert.equals('lua', result.type)
31 + assert.equals('', result.icon)
32 + end)
34 + it('detects input when prompt is non-empty', function()
35 + local result = format.detect(':', 'some input', 'Enter name: ')
36 + assert.equals('input', result.type)
37 + assert.equals('', result.icon)
38 + end)
40 + it('returns cmdline for unknown firstc', function()
41 + local result = format.detect('-', 'some text', '')
42 + assert.equals('cmdline', result.type)
43 + end)
45 + it('returns cmdline for empty firstc', function()
46 + local result = format.detect('', 'some text', '')
47 + assert.equals('cmdline', result.type)
48 + end)
49 +end)

neovim/tests/bugabinga/cmdline/init_spec.lua

Added
new file mode 100644
1 +describe('init.setup', function()
2 + before_each(function()
3 + package.loaded['bugabinga.cmdline'] = nil
4 + package.loaded['bugabinga.cmdline.state'] = nil
5 + package.loaded['bugabinga.cmdline.format'] = nil
6 + package.loaded['bugabinga.cmdline.position'] = nil
7 + package.loaded['bugabinga.cmdline.cursor'] = nil
8 + package.loaded['bugabinga.cmdline.render'] = nil
9 + package.loaded['bugabinga.cmdline.popupmenu'] = nil
10 + end)
12 + after_each(function()
13 + local ok, mod = pcall(require, 'bugabinga.cmdline')
14 + if ok and mod and mod.disable then
15 + mod.disable()
16 + end
17 + end)
19 + it('module loads without error', function()
20 + local ok = pcall(function()
21 + require 'bugabinga.cmdline'
22 + end)
23 + assert.is_true(ok)
24 + end)
25 +end)
27 +describe('init.disable', function()
28 + before_each(function()
29 + package.loaded['bugabinga.cmdline'] = nil
30 + package.loaded['bugabinga.cmdline.state'] = nil
31 + package.loaded['bugabinga.cmdline.format'] = nil
32 + package.loaded['bugabinga.cmdline.position'] = nil
33 + package.loaded['bugabinga.cmdline.cursor'] = nil
34 + package.loaded['bugabinga.cmdline.render'] = nil
35 + package.loaded['bugabinga.cmdline.popupmenu'] = nil
36 + end)
38 + after_each(function()
39 + local ok, mod = pcall(require, 'bugabinga.cmdline')
40 + if ok and mod and mod.disable then
41 + mod.disable()
42 + end
43 + end)
45 + it('disable is callable', function()
46 + require 'bugabinga.cmdline'
47 + local ok, mod = pcall(require, 'bugabinga.cmdline')
48 + if ok and mod.disable then
49 + local disable_ok = pcall(function()
50 + mod.disable()
51 + end)
52 + assert.is_true(disable_ok)
53 + end
54 + end)
55 +end)

neovim/tests/bugabinga/cmdline/popupmenu_spec.lua

Added
new file mode 100644
1 +describe('popupmenu.on_show', function()
2 + before_each(function()
3 + package.loaded['bugabinga.cmdline.popupmenu'] = nil
4 + end)
6 + after_each(function()
7 + local ok, popupmenu = pcall(require, 'bugabinga.cmdline.popupmenu')
8 + if ok then
9 + popupmenu.on_hide()
10 + end
11 + end)
13 + it('handles empty items', function()
14 + local popupmenu = require 'bugabinga.cmdline.popupmenu'
15 + local ok = pcall(function()
16 + popupmenu.on_show({}, -1, 0, 0, -1)
17 + end)
18 + assert.is_true(ok)
19 + end)
21 + it('creates window with items', function()
22 + local popupmenu = require 'bugabinga.cmdline.popupmenu'
23 + local items = {
24 + { 'foo', 'function', '', '' },
25 + { 'bar', 'variable', '', '' },
26 + }
27 + local ok = pcall(function()
28 + popupmenu.on_show(items, 0, 0, 0, -1)
29 + end)
30 + assert.is_true(ok)
31 + popupmenu.on_hide()
32 + end)
34 + it('hides safely when no window exists', function()
35 + local popupmenu = require 'bugabinga.cmdline.popupmenu'
36 + local ok = pcall(function()
37 + popupmenu.on_hide()
38 + popupmenu.on_hide()
39 + end)
40 + assert.is_true(ok)
41 + end)
42 +end)
44 +describe('popupmenu.on_select', function()
45 + before_each(function()
46 + package.loaded['bugabinga.cmdline.popupmenu'] = nil
47 + end)
49 + after_each(function()
50 + local ok, popupmenu = pcall(require, 'bugabinga.cmdline.popupmenu')
51 + if ok then
52 + popupmenu.on_hide()
53 + end
54 + end)
56 + it('does not error without window', function()
57 + local popupmenu = require 'bugabinga.cmdline.popupmenu'
58 + local ok = pcall(function()
59 + popupmenu.on_select(0)
60 + end)
61 + assert.is_true(ok)
62 + end)
63 +end)

neovim/tests/bugabinga/cmdline/position_spec.lua

Added
new file mode 100644
1 +describe('position.at_cursor', function()
2 + it('returns a table with row and col', function()
3 + local pos = require 'bugabinga.cmdline.position'
4 + local result = pos.at_cursor(40)
5 + assert.is_table(result)
6 + assert.is_number(result.row)
7 + assert.is_number(result.col)
8 + end)
10 + it('clamps col when width exceeds screen', function()
11 + vim.o.columns = 80
12 + vim.o.lines = 24
13 + local pos = require 'bugabinga.cmdline.position'
14 + local result = pos.at_cursor(100)
15 + assert.is_true(result.col <= 80)
16 + end)
17 +end)
19 +describe('position.get_cmdline_anchor', function()
20 + before_each(function()
21 + package.loaded['bugabinga.cmdline.position'] = nil
22 + end)
24 + after_each(function()
25 + local pos = require 'bugabinga.cmdline.position'
26 + pos.set_cmdline_anchor(nil)
27 + end)
29 + it('returns nil by default', function()
30 + local pos = require 'bugabinga.cmdline.position'
31 + assert.is_nil(pos.get_cmdline_anchor())
32 + end)
34 + it('returns the anchor after being set', function()
35 + local pos = require 'bugabinga.cmdline.position'
36 + local anchor = { screenpos = { row = 10, col = 20 }, cursor = 5 }
37 + pos.set_cmdline_anchor(anchor)
38 + assert.equals(anchor, pos.get_cmdline_anchor())
39 + end)
40 +end)
42 +describe('position.set_cmdline_anchor', function()
43 + before_each(function()
44 + package.loaded['bugabinga.cmdline.position'] = nil
45 + end)
47 + after_each(function()
48 + local pos = require 'bugabinga.cmdline.position'
49 + pos.set_cmdline_anchor(nil)
50 + end)
52 + it('stores and retrieves anchor', function()
53 + local pos = require 'bugabinga.cmdline.position'
54 + local anchor = { screenpos = { row = 5, col = 10 }, cursor = 3 }
55 + pos.set_cmdline_anchor(anchor)
56 + local result = pos.get_cmdline_anchor()
57 + assert.equals(5, result.screenpos.row)
58 + assert.equals(10, result.screenpos.col)
59 + assert.equals(3, result.cursor)
60 + end)
61 +end)

neovim/tests/bugabinga/cmdline/render_spec.lua

Added
new file mode 100644
1 +describe('render.show', function()
2 + before_each(function()
3 + package.loaded['bugabinga.cmdline.state'] = nil
4 + package.loaded['bugabinga.cmdline.format'] = nil
5 + package.loaded['bugabinga.cmdline.position'] = nil
6 + package.loaded['bugabinga.cmdline.cursor'] = nil
7 + package.loaded['bugabinga.cmdline.render'] = nil
8 + end)
10 + after_each(function()
11 + local ok, render = pcall(require, 'bugabinga.cmdline.render')
12 + if ok then
13 + render.hide()
14 + end
15 + local ok2, pos = pcall(require, 'bugabinga.cmdline.position')
16 + if ok2 then
17 + pos.set_cmdline_anchor(nil)
18 + end
19 + end)
21 + it('creates a floating window', function()
22 + local state = require 'bugabinga.cmdline.state'
23 + local render = require 'bugabinga.cmdline.render'
24 + local cmdline_state = state.new({
25 + { {}, ':hello' },
26 + }, 1, ':', '', 0, 1)
27 + render.show(cmdline_state)
28 + local pos = require('bugabinga.cmdline.position')
29 + local anchor = pos.get_cmdline_anchor()
30 + assert.is_not_nil(anchor)
31 + assert.is_not_nil(anchor.win)
32 + render.hide()
33 + end)
35 + it('sets buffer text with icon prefix', function()
36 + local state = require 'bugabinga.cmdline.state'
37 + local render = require 'bugabinga.cmdline.render'
38 + local cmdline_state = state.new({
39 + { {}, ':test' },
40 + }, 1, ':', '', 0, 1)
41 + render.show(cmdline_state)
42 + local pos = require('bugabinga.cmdline.position')
43 + local anchor = pos.get_cmdline_anchor()
44 + local buf = anchor.buf
45 + local lines = vim.api.nvim_buf_get_lines(buf, 0, 1, false)
46 + assert.is_true(#lines > 0)
47 + assert.is_true(lines[1]:find('󰘳') ~= nil)
48 + render.hide()
49 + end)
51 + it('has trailing space for cursor positioning', function()
52 + local state = require 'bugabinga.cmdline.state'
53 + local render = require 'bugabinga.cmdline.render'
54 + local cmdline_state = state.new({
55 + { {}, ':vim' },
56 + }, 4, ':', '', 0, 1)
57 + render.show(cmdline_state)
58 + local pos = require('bugabinga.cmdline.position')
59 + local anchor = pos.get_cmdline_anchor()
60 + local buf = anchor.buf
61 + local lines = vim.api.nvim_buf_get_lines(buf, 0, 1, false)
62 + assert.equals('󰘳 :vim ', lines[1])
63 + local icon = require('std.icon')
64 + local icon_bytes = #icon.command
65 + local cursor_byte = cmdline_state:cursor_byte()
66 + local expected_col = icon_bytes + 1 + cursor_byte
67 + assert.equals(icon_bytes + 1 + 4, expected_col)
68 + assert.equals(10, #lines[1])
69 + render.hide()
70 + end)
72 + it('hides safely when no window exists', function()
73 + local render = require 'bugabinga.cmdline.render'
74 + local ok = pcall(function()
75 + render.hide()
76 + render.hide()
77 + end)
78 + assert.is_true(ok)
79 + end)
80 +end)
82 +describe('render.hide', function()
83 + before_each(function()
84 + package.loaded['bugabinga.cmdline.state'] = nil
85 + package.loaded['bugabinga.cmdline.format'] = nil
86 + package.loaded['bugabinga.cmdline.position'] = nil
87 + package.loaded['bugabinga.cmdline.cursor'] = nil
88 + package.loaded['bugabinga.cmdline.render'] = nil
89 + end)
91 + after_each(function()
92 + local ok, render = pcall(require, 'bugabinga.cmdline.render')
93 + if ok then
94 + render.hide()
95 + end
96 + local ok2, pos = pcall(require, 'bugabinga.cmdline.position')
97 + if ok2 then
98 + pos.set_cmdline_anchor(nil)
99 + end
100 + end)
102 + it('clears anchor after hide', function()
103 + local state = require 'bugabinga.cmdline.state'
104 + local render = require 'bugabinga.cmdline.render'
105 + local cmdline_state = state.new({
106 + { {}, ':test' },
107 + }, 1, ':', '', 0, 1)
108 + render.show(cmdline_state)
109 + render.hide()
110 + local pos = require('bugabinga.cmdline.position')
111 + local anchor = pos.get_cmdline_anchor()
112 + assert.is_nil(anchor)
113 + end)
114 +end)

neovim/tests/bugabinga/cmdline/state_spec.lua

Added
new file mode 100644
1 +local state = require 'bugabinga.cmdline.state'
3 +describe('state.new', function()
4 + before_each(function()
5 + package.loaded['bugabinga.cmdline.state'] = nil
6 + end)
8 + it('concatenates content chunks into text', function()
9 + local s = state.new({
10 + { {}, 'hello ' },
11 + { {}, 'world' },
12 + }, 11, ':', '', 0, 1)
13 + assert.equals('hello world', s:text())
14 + end)
16 + it('stores cursor position', function()
17 + local s = state.new({}, 5, ':', '', 0, 1)
18 + assert.equals(5, s:cursor_byte())
19 + end)
21 + it('stores firstc, prompt, level', function()
22 + local s = state.new({}, 0, '/', 'search: ', 2, 3)
23 + assert.equals('/', s.firstc)
24 + assert.equals('search: ', s.prompt)
25 + assert.equals(3, s.level)
26 + end)
28 + it('handles empty content', function()
29 + local s = state.new({}, 0, ':', '', 0, 1)
30 + assert.equals('', s:text())
31 + end)
33 + it('handles single chunk content', function()
34 + local s = state.new({
35 + { {}, 'only' },
36 + }, 4, ':', '', 0, 1)
37 + assert.equals('only', s:text())
38 + end)
39 +end)
41 +describe('state methods', function()
42 + before_each(function()
43 + package.loaded['bugabinga.cmdline.state'] = nil
44 + end)
46 + it('text() returns concatenated string', function()
47 + local s = state.new({
48 + { {}, 'foo' },
49 + { {}, 'bar' },
50 + }, 6, ':', '', 0, 1)
51 + assert.equals('foobar', s:text())
52 + end)
54 + it('cursor_byte() returns byte offset', function()
55 + local s = state.new({}, 7, ':', '', 0, 1)
56 + assert.equals(7, s:cursor_byte())
57 + end)
59 + it('is_search() returns true for /', function()
60 + local s = state.new({}, 0, '/', '', 0, 1)
61 + assert.is_true(s:is_search())
62 + end)
64 + it('is_search() returns true for ?', function()
65 + local s = state.new({}, 0, '?', '', 0, 1)
66 + assert.is_true(s:is_search())
67 + end)
69 + it('is_search() returns false for :', function()
70 + local s = state.new({}, 0, ':', '', 0, 1)
71 + assert.is_false(s:is_search())
72 + end)
74 + it('is_input() returns true when prompt non-empty', function()
75 + local s = state.new({}, 0, ':', 'Name: ', 0, 1)
76 + assert.is_true(s:is_input())
77 + end)
79 + it('is_input() returns false when prompt empty', function()
80 + local s = state.new({}, 0, ':', '', 0, 1)
81 + assert.is_false(s:is_input())
82 + end)
83 +end)

neovim/tests/bugabinga/cursor_restore_spec.lua

Added
new file mode 100644
1 +local auto = require('std.auto')
2 +local ignored = require('std.ignored')
4 +describe('cursor restore behaviour', function()
5 + after_each(function()
6 + pcall(vim.api.nvim_del_augroup_by_name, 'restore_cursor_position')
7 + pcall(vim.api.nvim_del_augroup_by_name, 'restore_cursor_stage2')
8 + for _, buf in ipairs(vim.api.nvim_list_bufs()) do
9 + pcall(vim.api.nvim_buf_delete, buf, { force = true })
10 + end
11 + end)
13 + local function make_buffer_with_lines(buf, lines)
14 + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
15 + end
17 + local function set_shada_mark(buf, line, col)
18 + vim.api.nvim_set_current_buf(buf)
19 + vim.cmd.normal { string.format('%dG', line), bang = true }
20 + vim.cmd.normal { string.format('%dl', col - 1), bang = true }
21 + vim.cmd([[normal! m"]])
22 + end
24 + local function restore_cursor_logic(ev)
25 + local ft = vim.bo[ev.buf].filetype
26 + local bt = vim.bo[ev.buf].buftype
27 + if ignored.buftypes_kv[bt] then return end
28 + if ignored.filetypes_kv[ft] then return end
29 + for _, pattern in ipairs(ignored.filetypes_patterns) do
30 + if ft:find(pattern) then return end
31 + end
32 + if vim.fn.line('.') > 1 then return end
33 + local line = vim.fn.line([['"]])
34 + local col = vim.fn.col([['"]]) - 1
35 + if line > 0 and line <= vim.fn.line('$') then
36 + auto 'restore_cursor_stage2' {
37 + events = 'BufWinEnter',
38 + buffer = ev.buf,
39 + once = true,
40 + command = function()
41 + vim.api.nvim_win_set_cursor(0, { line, col })
42 + vim.cmd.normal { 'zvzz', bang = true }
43 + end,
44 + }
45 + end
46 + end
48 + describe('BufReadPost stage', function()
49 + it('should NOT create stage2 when buftype is nofile', function()
50 + local buf = vim.api.nvim_create_buf(false, false)
51 + vim.bo[buf].buftype = 'nofile'
52 + make_buffer_with_lines(buf, { 'line 1', 'line 2', 'line 3' })
53 + set_shada_mark(buf, 3, 5)
55 + auto 'restore_cursor_position' {
56 + events = 'BufReadPost',
57 + command = restore_cursor_logic,
58 + }
60 + vim.api.nvim_exec_autocmds('BufReadPost', { buffer = buf })
61 + local ok, stage2 = pcall(vim.api.nvim_get_autocmds, { group = 'restore_cursor_stage2' })
62 + if ok then
63 + assert.equals(0, #stage2)
64 + end
65 + end)
67 + it('should NOT create stage2 when filetype is help', function()
68 + local buf = vim.api.nvim_create_buf(false, false)
69 + vim.bo[buf].filetype = 'help'
70 + make_buffer_with_lines(buf, { 'line 1', 'line 2', 'line 3' })
71 + set_shada_mark(buf, 3, 5)
73 + auto 'restore_cursor_position' {
74 + events = 'BufReadPost',
75 + command = restore_cursor_logic,
76 + }
78 + vim.api.nvim_exec_autocmds('BufReadPost', { buffer = buf })
79 + local ok, stage2 = pcall(vim.api.nvim_get_autocmds, { group = 'restore_cursor_stage2' })
80 + if ok then
81 + assert.equals(0, #stage2)
82 + end
83 + end)
85 + it('should NOT create stage2 when cursor already at line > 1', function()
86 + local buf = vim.api.nvim_create_buf(false, false)
87 + make_buffer_with_lines(buf, { 'line 1', 'line 2', 'line 3', 'line 4', 'line 5' })
88 + set_shada_mark(buf, 3, 5)
89 + -- simulate nvim +3 file.lua - cursor already at line 3
90 + vim.api.nvim_set_current_buf(buf)
91 + vim.cmd.normal { '3G' }
93 + auto 'restore_cursor_position' {
94 + events = 'BufReadPost',
95 + command = restore_cursor_logic,
96 + }
98 + vim.api.nvim_exec_autocmds('BufReadPost', { buffer = buf })
99 + local ok, stage2 = pcall(vim.api.nvim_get_autocmds, { group = 'restore_cursor_stage2' })
100 + if ok then
101 + assert.equals(0, #stage2)
102 + end
103 + end)
105 + it('should create stage2 autocmd when conditions are met', function()
106 + local buf = vim.api.nvim_create_buf(false, false)
107 + make_buffer_with_lines(buf, { 'line 1', 'line 2', 'line 3', 'line 4', 'line 5' })
108 + set_shada_mark(buf, 3, 5)
109 + -- cursor at line 1
110 + vim.api.nvim_set_current_buf(buf)
111 + vim.cmd.normal { 'gg' }
113 + auto 'restore_cursor_position' {
114 + events = 'BufReadPost',
115 + command = restore_cursor_logic,
118 + vim.api.nvim_exec_autocmds('BufReadPost', { buffer = buf })
119 + local stage2 = vim.api.nvim_get_autocmds({ group = 'restore_cursor_stage2' })
120 + assert.equals(1, #stage2)
121 + assert.equals(buf, stage2[1].buffer)
122 + end)
123 + end)
125 + describe('BufWinEnter stage', function()
126 + it('should restore cursor to shada position', function()
127 + local buf = vim.api.nvim_create_buf(false, false)
128 + make_buffer_with_lines(buf, { 'line 1', 'line 2', 'line 3', 'line 4', 'line 5' })
129 + set_shada_mark(buf, 3, 5)
131 + -- create a window with this buffer
132 + vim.cmd.split()
133 + local win = vim.api.nvim_get_current_win()
134 + vim.api.nvim_win_set_buf(win, buf)
135 + vim.api.nvim_set_current_win(win)
136 + vim.cmd.normal { 'gg' } -- cursor at line 1
138 + auto 'restore_cursor_position' {
139 + events = 'BufReadPost',
140 + command = restore_cursor_logic,
143 + vim.api.nvim_exec_autocmds('BufReadPost', { buffer = buf })
144 + vim.api.nvim_exec_autocmds('BufWinEnter', { buffer = buf })
146 + local cursor = vim.api.nvim_win_get_cursor(win)
147 + assert.equals(3, cursor[1])
148 + assert.equals(4, cursor[2])
149 + end)
150 + end)
151 +end)

neovim/tests/bugabinga/cycle_spec.lua

Added
new file mode 100644
1 +local cycle = require 'bugabinga.cycle'
3 +describe('bugabinga.cycle', function()
4 + local function create_buffer(name)
5 + vim.api.nvim_command('new ' .. name)
6 + local bufnr = vim.api.nvim_get_current_buf()
7 + return bufnr
8 + end
10 + before_each(function()
11 + package.loaded['bugabinga.cycle'] = nil
12 + end)
14 + after_each(function()
15 + cycle.cancel()
16 + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
17 + if vim.api.nvim_buf_is_valid(bufnr) then
18 + pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
19 + end
20 + end
21 + if cycle.history then
22 + for i = #cycle.history, 1, -1 do
23 + cycle.history[i] = nil
24 + end
25 + end
26 + end)
28 + describe('history tracking', function()
29 + it('should track buffers on BufEnter', function()
30 + local bufnr1 = create_buffer('test1.lua')
31 + vim.api.nvim_set_current_buf(bufnr1)
32 + local bufnr2 = create_buffer('test2.lua')
33 + vim.api.nvim_set_current_buf(bufnr2)
34 + local bufnr3 = create_buffer('test3.lua')
35 + vim.api.nvim_set_current_buf(bufnr3)
36 + assert.is_true(#cycle.history >= 1)
37 + end)
39 + it('should skip unnamed buffers', function()
40 + vim.api.nvim_command('enew')
41 + local bufnr = vim.api.nvim_get_current_buf()
42 + vim.api.nvim_set_current_buf(bufnr)
43 + for _, b in ipairs(cycle.history) do
44 + assert.is_not_equal(bufnr, b)
45 + end
46 + end)
48 + it('should skip unlisted buffers', function()
49 + vim.api.nvim_command('new')
50 + local bufnr = vim.api.nvim_get_current_buf()
51 + vim.bo[bufnr].buflisted = false
52 + vim.api.nvim_set_current_buf(bufnr)
53 + for _, b in ipairs(cycle.history) do
54 + assert.is_not_equal(bufnr, b)
55 + end
56 + end)
58 + it('should move revisited buffer to end of history', function()
59 + local bufnr1 = create_buffer('mruseq1.lua')
60 + vim.api.nvim_set_current_buf(bufnr1)
61 + local bufnr2 = create_buffer('mruseq2.lua')
62 + vim.api.nvim_set_current_buf(bufnr2)
63 + local bufnr3 = create_buffer('mruseq3.lua')
64 + vim.api.nvim_set_current_buf(bufnr3)
65 + local last = cycle.history[#cycle.history]
66 + assert.is_equal(bufnr3, last)
67 + end)
69 + it('should remove deleted buffers from history', function()
70 + local bufnr1 = create_buffer('del1.lua')
71 + vim.api.nvim_set_current_buf(bufnr1)
72 + local bufnr2 = create_buffer('del2.lua')
73 + vim.api.nvim_set_current_buf(bufnr2)
74 + local bufnr3 = create_buffer('del3.lua')
75 + vim.api.nvim_set_current_buf(bufnr3)
76 + vim.api.nvim_buf_delete(bufnr2, { force = true })
77 + for _, b in ipairs(cycle.history) do
78 + assert.is_not_equal(bufnr2, b)
79 + end
80 + end)
81 + end)
83 + describe('cycling', function()
84 + it('should open popup with buffer list when multiple buffers exist', function()
85 + local bufnr1 = create_buffer('cycle1.lua')
86 + vim.api.nvim_set_current_buf(bufnr1)
87 + local bufnr2 = create_buffer('cycle2.lua')
88 + vim.api.nvim_set_current_buf(bufnr2)
89 + local win_count_before = #vim.api.nvim_list_wins()
90 + cycle.cycle(1)
91 + local win_count_after = #vim.api.nvim_list_wins()
92 + assert.is_true(win_count_after > win_count_before)
93 + cycle.cancel()
94 + end)
96 + it('should open popup with current buffer included in list', function()
97 + local bufnr1 = create_buffer('single1.lua')
98 + vim.api.nvim_set_current_buf(bufnr1)
99 + local win_count_before = #vim.api.nvim_list_wins()
100 + cycle.cycle(1)
101 + local win_count_after = #vim.api.nvim_list_wins()
102 + assert.is_true(win_count_after > win_count_before, 'popup should open')
103 + end)
105 + it('should cycle forward through buffer list', function()
106 + local bufnr1 = create_buffer('fwd1.lua')
107 + vim.api.nvim_set_current_buf(bufnr1)
108 + local bufnr2 = create_buffer('fwd2.lua')
109 + vim.api.nvim_set_current_buf(bufnr2)
110 + local bufnr3 = create_buffer('fwd3.lua')
111 + vim.api.nvim_set_current_buf(bufnr3)
112 + cycle.cycle(1)
113 + assert.is_not_nil(cycle.cancel)
114 + cycle.cancel()
115 + end)
117 + it('should not crash when cycling second time with multiple buffers', function()
118 + local bufnr1 = create_buffer('multifwd1.lua')
119 + vim.api.nvim_set_current_buf(bufnr1)
120 + local bufnr2 = create_buffer('multifwd2.lua')
121 + vim.api.nvim_set_current_buf(bufnr2)
122 + local bufnr3 = create_buffer('multifwd3.lua')
123 + vim.api.nvim_set_current_buf(bufnr3)
124 + cycle.cycle(1)
125 + local ok, err = pcall(cycle.cycle, 1)
126 + assert.is_true(ok, 'second cycle should not error: ' .. tostring(err))
127 + cycle.cancel()
128 + end)
130 + it('should cycle backward through buffer list', function()
131 + local bufnr1 = create_buffer('bwd1.lua')
132 + vim.api.nvim_set_current_buf(bufnr1)
133 + local bufnr2 = create_buffer('bwd2.lua')
134 + vim.api.nvim_set_current_buf(bufnr2)
135 + cycle.cycle(-1)
136 + assert.is_not_nil(cycle.cancel)
137 + cycle.cancel()
138 + end)
140 + it('should wrap from first to last when cycling forward', function()
141 + local bufnr1 = create_buffer('wrap1.lua')
142 + vim.api.nvim_set_current_buf(bufnr1)
143 + local bufnr2 = create_buffer('wrap2.lua')
144 + vim.api.nvim_set_current_buf(bufnr2)
145 + cycle.cycle(1)
146 + cycle.cancel()
147 + end)
148 + end)
150 + describe('cancel', function()
151 + it('should restore original buffer after cancel', function()
152 + local bufnr1 = create_buffer('rest1.lua')
153 + vim.api.nvim_set_current_buf(bufnr1)
154 + local bufnr2 = create_buffer('rest2.lua')
155 + vim.api.nvim_set_current_buf(bufnr2)
156 + local original = vim.api.nvim_get_current_buf()
157 + cycle.cycle(1)
158 + cycle.cancel()
159 + local restored = vim.api.nvim_get_current_buf()
160 + assert.is_equal(original, restored)
161 + end)
163 + it('should not crash when timer is already nil', function()
164 + local bufnr1 = create_buffer('nocancel1.lua')
165 + vim.api.nvim_set_current_buf(bufnr1)
166 + local bufnr2 = create_buffer('nocancel2.lua')
167 + vim.api.nvim_set_current_buf(bufnr2)
168 + cycle.cancel()
169 + end)
171 + it('should stop and clear timer on cancel', function()
172 + local bufnr1 = create_buffer('timerclear1.lua')
173 + vim.api.nvim_set_current_buf(bufnr1)
174 + local bufnr2 = create_buffer('timerclear2.lua')
175 + vim.api.nvim_set_current_buf(bufnr2)
176 + cycle.cycle(1)
177 + cycle.cancel()
178 + end)
179 + end)
181 + describe('commit_switch', function()
182 + it('should switch to highlighted buffer after timer fires', function()
183 + local bufnr1 = create_buffer('commit1.lua')
184 + vim.api.nvim_set_current_buf(bufnr1)
185 + local bufnr2 = create_buffer('commit2.lua')
186 + vim.api.nvim_set_current_buf(bufnr2)
187 + cycle.cycle(1)
188 + vim.wait(1100)
189 + local current = vim.api.nvim_get_current_buf()
190 + assert.is_equal(bufnr1, current)
191 + end)
193 + it('should not switch when no popup was opened', function()
194 + vim.api.nvim_command('enew')
195 + local bufnr = vim.api.nvim_get_current_buf()
196 + vim.api.nvim_set_current_buf(bufnr)
197 + local original = vim.api.nvim_get_current_buf()
198 + cycle.cycle(1)
199 + local current = vim.api.nvim_get_current_buf()
200 + assert.is_equal(original, current)
201 + end)
202 + end)
204 + describe('rendering', function()
205 + it('shorten_path should return basename for paths outside cwd', function()
206 + local short = '/a/b/c.lua'
207 + local result = cycle.shorten_path(short, 50)
208 + assert.is_equal('c.lua', result)
209 + end)
211 + it('shorten_path should keep full relative path when it fits', function()
212 + local path = '/home/user/project/file.lua'
213 + local result = cycle.shorten_path(path, 30)
214 + assert.is_true(#result <= 30, 'should fit: ' .. result .. ' (' .. #result .. ')')
215 + assert.is_true(result:find('file.lua', 1, true) ~= nil, 'basename must be present: ' .. result)
216 + end)
218 + it('shorten_path should return basename for paths outside cwd', function()
219 + local long = '/home/user/very/deep/nested/path/to/file.lua'
220 + local result = cycle.shorten_path(long, 25)
221 + local basename = 'file.lua'
222 + assert.is_equal(basename, result, 'should return basename: ' .. result)
223 + end)
225 + it('shorten_path should truncate dirname, result may exceed max if basename is long', function()
226 + local path = '/home/user/very/deep/nested/path/to/file.lua'
227 + local result = cycle.shorten_path(path, 15)
228 + local basename = vim.fn.fnamemodify(path, ':t')
229 + assert.is_true(result:find(basename, 1, true) ~= nil, 'basename should be present: ' .. result)
230 + assert.is_true(#result <= 20, 'should be shortened: ' .. result .. ' (' .. #result .. ')')
231 + end)
233 + it('get_icon should return a string', function()
234 + local icon, _ = cycle.get_icon('test.lua')
235 + assert.is_string(icon)
236 + assert.is_true(#icon > 0)
237 + end)
238 + end)
240 + describe('module API', function()
241 + it('should export cycle, cancel, and history', function()
242 + assert.is_function(cycle.cycle)
243 + assert.is_function(cycle.cancel)
244 + assert.is_table(cycle.history)
245 + end)
246 + end)
247 +end)

neovim/tests/bugabinga/d2_spec.lua

Added
new file mode 100644
1 +local d2 = require 'bugabinga.d2'
3 +local D2_STUB_OUTPUT = [[
4 ++-------+
5 +| hello |
6 ++-------+
8 +]]
10 +local mock_d2_system = function(output, code)
11 + local original_system = vim.system
12 + vim.system = function(cmd, opts)
13 + local handle = {
14 + wait = function()
15 + return { code = code or 0, stdout = output or '', stderr = '' }
16 + end,
17 + }
18 + return handle
19 + end
20 + return function()
21 + vim.system = original_system
22 + end
23 +end
25 +local create_d2_buffer = function(name, lines)
26 + vim.cmd(('edit! %s'):format(name))
27 + local bufnr = vim.api.nvim_get_current_buf()
28 + if lines then
29 + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
30 + end
31 + return bufnr
32 +end
34 +local cleanup_preview = function()
35 + local pbnr = vim.fn.bufnr('D2_ASCII_PREVIEW')
36 + if pbnr ~= -1 and vim.api.nvim_buf_is_valid(pbnr) then
37 + pcall(vim.api.nvim_buf_delete, pbnr, { force = true })
38 + end
39 +end
41 +local cleanup_d2_state = function()
42 + cleanup_preview()
43 + pcall(vim.api.nvim_del_augroup, 'd2_preview_autosave')
44 + pcall(vim.api.nvim_del_augroup, 'd2_validate_autosave')
45 + pcall(vim.api.nvim_del_augroup, 'd2_preview_keymaps')
46 + pcall(vim.api.nvim_del_user_command, 'D2Preview')
47 + pcall(vim.api.nvim_del_user_command, 'D2PreviewToggle')
48 + pcall(vim.api.nvim_del_user_command, 'D2Validate')
49 + pcall(vim.api.nvim_del_user_command, 'D2ValidateToggle')
50 +end
52 +describe('bugabinga.d2', function()
53 + before_each(function()
54 + package.loaded['bugabinga.d2'] = nil
55 + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
56 + if vim.api.nvim_buf_is_valid(bufnr) and vim.bo[bufnr].filetype ~= 'qf' then
57 + pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
58 + end
59 + end
60 + cleanup_d2_state()
61 + end)
63 + after_each(function()
64 + cleanup_d2_state()
65 + end)
67 + describe('module API', function()
68 + it('should export preview_toggle', function()
69 + local mod = require 'bugabinga.d2'
70 + assert.is_function(mod.preview_toggle)
71 + end)
73 + it('should export preview_update', function()
74 + local mod = require 'bugabinga.d2'
75 + assert.is_function(mod.preview_update)
76 + end)
78 + it('should export preview_copy', function()
79 + local mod = require 'bugabinga.d2'
80 + assert.is_function(mod.preview_copy)
81 + end)
83 + it('should export validate', function()
84 + local mod = require 'bugabinga.d2'
85 + assert.is_function(mod.validate)
86 + end)
88 + it('should export validate_toggle', function()
89 + local mod = require 'bugabinga.d2'
90 + assert.is_function(mod.validate_toggle)
91 + end)
92 + end)
94 + describe('user commands', function()
95 + it('should register D2Preview command', function()
96 + require 'bugabinga.d2'
97 + local ok = pcall(vim.cmd, 'command D2Preview')
98 + assert.is_true(ok, 'D2Preview command should exist')
99 + end)
101 + it('should register D2PreviewToggle command', function()
102 + require 'bugabinga.d2'
103 + local ok = pcall(vim.cmd, 'command D2PreviewToggle')
104 + assert.is_true(ok, 'D2PreviewToggle command should exist')
105 + end)
107 + it('should register D2Validate command without error', function()
108 + require 'bugabinga.d2'
109 + local ok, err = pcall(vim.cmd, 'D2Validate')
110 + assert.is_true(ok, 'D2Validate should not error: ' .. tostring(err))
111 + end)
113 + it('should register D2ValidateToggle command without error', function()
114 + require 'bugabinga.d2'
115 + local ok, err = pcall(vim.cmd, 'D2ValidateToggle')
116 + assert.is_true(ok, 'D2ValidateToggle should not error: ' .. tostring(err))
117 + end)
118 + end)
120 + describe('validate', function()
121 + it('should handle validate on unnamed buffer gracefully', function()
122 + local restore = mock_d2_system('', 0)
123 + require 'bugabinga.d2'
124 + vim.cmd 'enew'
125 + vim.bo.filetype = 'd2'
126 + local ok, err = pcall(d2.validate)
127 + restore()
128 + assert.is_true(ok, 'validate should not crash on unnamed buffer: ' .. tostring(err))
129 + end)
131 + it('should clear previous diagnostics on re-validate', function()
132 + require 'bugabinga.d2'
133 + local bufnr = create_d2_buffer('clear_test.d2', { 'x -> y' })
134 + vim.diagnostic.reset(nil, bufnr)
135 + local diag_count = #vim.diagnostic.get(bufnr)
136 + assert.is_equal(0, diag_count)
137 + end)
138 + end)
140 + describe('validate_toggle', function()
141 + it('should toggle auto-validate without error', function()
142 + require 'bugabinga.d2'
143 + local ok, err = pcall(d2.validate_toggle)
144 + assert.is_true(ok, 'validate_toggle should not error: ' .. tostring(err))
145 + ok, err = pcall(d2.validate_toggle)
146 + assert.is_true(ok, 'validate_toggle should not error on second call: ' .. tostring(err))
147 + end)
148 + end)
150 + describe('autocmds', function()
151 + it('should create d2_preview_autosave autocmds', function()
152 + require 'bugabinga.d2'
153 + local autocmds = vim.api.nvim_get_autocmds { group = 'd2_preview_autosave' }
154 + assert.is_true(#autocmds > 0, 'd2_preview_autosave autocmds should exist')
155 + end)
157 + it('should create d2_validate_autosave autocmds', function()
158 + require 'bugabinga.d2'
159 + local autocmds = vim.api.nvim_get_autocmds { group = 'd2_validate_autosave' }
160 + assert.is_true(#autocmds > 0, 'd2_validate_autosave autocmds should exist')
161 + end)
162 + end)
164 + describe('parse_validate_output', function()
165 + it('should parse line:col error format', function()
166 + local mod = require 'bugabinga.d2'
167 + local stderr = 'err: /path/file.d2:27:11: unexpected text after map\n'
168 + local results = mod._parse_validate_output(stderr)
169 + assert.is_table(results)
170 + assert.is_true(#results >= 1)
171 + assert.is_equal(26, results[1].lnum)
172 + assert.is_equal(10, results[1].col)
173 + end)
175 + it('should parse error with URL prefix', function()
176 + local mod = require 'bugabinga.d2'
177 + local stderr = 'err: oss.terrastruct.com/d2/d2cli.validateCmd: 27:9: unexpected text after map\n'
178 + local results = mod._parse_validate_output(stderr)
179 + assert.is_table(results)
180 + assert.is_true(#results >= 1)
181 + assert.is_equal(26, results[1].lnum)
182 + assert.is_equal(8, results[1].col)
183 + end)
185 + it('should return empty table for no errors', function()
186 + local mod = require 'bugabinga.d2'
187 + local stderr = ''
188 + local results = mod._parse_validate_output(stderr)
189 + assert.is_table(results)
190 + assert.is_equal(0, #results)
191 + end)
192 + end)
193 +end)

neovim/tests/lsp/denols_spec.lua

Added
new file mode 100644
1 +local denols = require('lsp.denols')
3 +describe('lsp.denols', function()
4 + describe('exported config', function()
5 + it('returns a table', function()
6 + assert.is_table(denols)
7 + end)
9 + it('has cmd set to deno lsp', function()
10 + assert.is_table(denols.cmd)
11 + assert.equals('deno', denols.cmd[1])
12 + assert.equals('lsp', denols.cmd[2])
13 + end)
15 + it('has NO_COLOR=true in cmd_env', function()
16 + assert.is_table(denols.cmd_env)
17 + assert.equals(true, denols.cmd_env.NO_COLOR)
18 + end)
20 + it('has correct filetypes', function()
21 + local expected = {
22 + 'javascript',
23 + 'javascriptreact',
24 + 'typescript',
25 + 'typescriptreact',
26 + 'json',
27 + 'jsonc',
28 + 'markdown',
29 + }
30 + assert.is_table(denols.filetypes)
31 + for _, v in ipairs(expected) do
32 + assert.is_true(vim.tbl_contains(denols.filetypes, v), string.format('missing filetypes: %s', v))
33 + end
34 + end)
36 + it('has root_markers for deno projects', function()
37 + local expected = { 'deno.json', 'deno.jsonc' }
38 + assert.is_table(denols.root_markers)
39 + for _, v in ipairs(expected) do
40 + assert.is_true(vim.tbl_contains(denols.root_markers, v), string.format('missing root_markers: %s', v))
41 + end
42 + end)
44 + it('has deno settings with enable=true', function()
45 + assert.is_table(denols.settings)
46 + assert.is_table(denols.settings.deno)
47 + assert.equals(true, denols.settings.deno.enable)
48 + end)
50 + it('has suggest.imports.hosts configured for deno.land', function()
51 + local hosts = denols.settings.deno.suggest.imports.hosts
52 + assert.is_table(hosts)
53 + assert.equals(true, hosts['https://deno.land'])
54 + end)
56 + it('has handlers for deno: URI resolution', function()
57 + assert.is_table(denols.handlers)
58 + assert.is_function(denols.handlers['textDocument/definition'])
59 + assert.is_function(denols.handlers['textDocument/typeDefinition'])
60 + assert.is_function(denols.handlers['textDocument/references'])
61 + end)
63 + it('has on_attach function', function()
64 + assert.is_function(denols.on_attach)
65 + end)
67 + it('on_attach creates DenolsCache command on the buffer', function()
68 + local mock_client = { id = 1, name = 'denols', config = {} }
69 + local mock_bufnr = vim.api.nvim_create_buf(false, true)
70 + denols.on_attach(mock_client, mock_bufnr)
71 + local commands = vim.api.nvim_buf_get_commands(mock_bufnr, {})
72 + assert.is_table(commands)
73 + assert.is_table(commands.DenolsCache)
74 + vim.api.nvim_buf_delete(mock_bufnr, { force = true })
75 + end)
77 + it('has commands table with DenolsCache', function()
78 + assert.is_table(denols.commands)
79 + assert.is_table(denols.commands.DenolsCache)
80 + assert.is_function(denols.commands.DenolsCache[1])
81 + end)
82 + end)
84 + describe('denols_handler', function()
85 + local denols_handler
87 + before_each(function()
88 + denols_handler = require('lsp.denols')._test.denols_handler
89 + end)
91 + it('returns nil for nil result', function()
92 + local result = denols_handler(nil, nil, nil, nil)
93 + assert.is_nil(result)
94 + end)
96 + it('returns nil for empty result table', function()
97 + local result = denols_handler(nil, {}, nil, nil)
98 + assert.is_nil(result)
99 + end)
101 + it('passes through non-deno: URIs unchanged', function()
102 + local err = nil
103 + local result = {
104 + { uri = 'file:///path/to/file.ts', range = { start = { line = 1 } } },
106 + local ctx = { method = 'textDocument/definition' }
107 + local config = {}
108 + local captured = nil
109 + local original_handler = vim.lsp.handlers['textDocument/definition']
110 + vim.lsp.handlers['textDocument/definition'] = function(_, res)
111 + captured = res
112 + end
113 + denols_handler(err, result, ctx, config)
114 + vim.lsp.handlers['textDocument/definition'] = original_handler
115 + assert.is_table(captured)
116 + assert.equals('file:///path/to/file.ts', captured[1].uri)
117 + end)
119 + it('calls virtual_text_document for deno: URIs and preserves them', function()
120 + local err = nil
121 + local result = {
122 + { uri = 'deno:https://deno.land/std/assert/assert.ts', range = { start = { line = 0 } } },
124 + local ctx = { method = 'textDocument/definition' }
125 + local config = {}
126 + local captured = nil
127 + local original_handler = vim.lsp.handlers['textDocument/definition']
128 + vim.lsp.handlers['textDocument/definition'] = function(_, res)
129 + captured = res
130 + end
131 + denols_handler(err, result, ctx, config)
132 + vim.lsp.handlers['textDocument/definition'] = original_handler
133 + assert.is_table(captured)
134 + assert.is_true(captured[1].uri:match('^deno:') ~= nil)
135 + end)
136 + end)
137 +end)

neovim/tests/minimal_init.lua

Modified
1 1 vim.cmd('packadd plenary')
3 +local config_root = vim.uv.fs_realpath(vim.fn.stdpath('config')) or vim.fn.stdpath('config')
4 +vim.opt.runtimepath:prepend(config_root)
5 +package.path = config_root .. '/?.lua;' .. config_root .. '/lua/?.lua;' .. package.path

neovim/tests/std/auto_spec.lua

Added
new file mode 100644
1 +local auto = require('std.auto')
3 +describe('std.auto', function()
4 + after_each(function()
5 + vim.api.nvim_del_augroup_by_name('test_group')
6 + end)
8 + describe('group-scoped autocmds (no buffer)', function()
9 + it('should register and fire a group autocmd', function()
10 + local fired = false
11 + auto 'test_group' {
12 + events = 'User',
13 + pattern = 'TestEvent',
14 + command = function() fired = true end,
15 + }
16 + vim.cmd('doautocmd User TestEvent')
17 + assert.is_true(fired)
18 + end)
20 + it('should pass group to nvim_create_autocmd', function()
21 + auto 'test_group' {
22 + events = 'User',
23 + pattern = 'TestGroupScoped',
24 + command = function() end,
25 + }
26 + local autocmds = vim.api.nvim_get_autocmds({ group = 'test_group' })
27 + assert.is_true(#autocmds > 0)
28 + end)
29 + end)
31 + describe('buffer-local autocmds (with buffer)', function()
32 + it('should fire a buffer-local autocmd', function()
33 + local buf = vim.api.nvim_create_buf(true, false)
34 + local fired = false
35 + auto 'test_group' {
36 + events = 'BufWinEnter',
37 + buffer = buf,
38 + command = function() fired = true end,
39 + }
40 + vim.api.nvim_exec_autocmds('BufWinEnter', { buffer = buf })
41 + assert.is_true(fired)
42 + vim.api.nvim_buf_delete(buf, { force = true })
43 + end)
45 + it('should respect once = true for buffer-local autocmds', function()
46 + local buf = vim.api.nvim_create_buf(true, false)
47 + local count = 0
48 + auto 'test_group' {
49 + events = 'BufWinEnter',
50 + buffer = buf,
51 + once = true,
52 + command = function() count = count + 1 end,
53 + }
54 + vim.api.nvim_exec_autocmds('BufWinEnter', { buffer = buf })
55 + assert.equals(1, count)
56 + vim.api.nvim_exec_autocmds('BufWinEnter', { buffer = buf })
57 + assert.equals(1, count)
58 + vim.api.nvim_buf_delete(buf, { force = true })
59 + end)
61 + it('should auto-clean when buffer is deleted', function()
62 + local buf = vim.api.nvim_create_buf(true, false)
63 + auto 'test_group' {
64 + events = 'BufWinEnter',
65 + buffer = buf,
66 + command = function() end,
67 + }
68 + vim.api.nvim_buf_delete(buf, { force = true })
69 + local autocmds = vim.api.nvim_get_autocmds({ event = 'BufWinEnter' })
70 + local found = false
71 + for _, a in ipairs(autocmds) do
72 + if a.buffer == buf then
73 + found = true
74 + break
75 + end
76 + end
77 + assert.is_false(found)
78 + end)
79 + end)
80 +end)