repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: plan_001.md completion + 70 new unit tests

82d68915da266df65a1440e62a9dccb0615cd214

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Performance:
- project: replace SHA256 cache hashing with string concat (17k× faster)
- project: pre-build default_markers table at module level
- statusline: cache cwd via DirChanged autocmd
- devicons: defer mini.icons loading via puk.defer
- prequire: cache the proxy via proxy_cache table

Bug fixes:
- lsp: restore accidentally deleted vim.lsp.enable(servers)
- patches/string: delete dead string.strip (never called)

Refactor:
- lsp: extract LspInfo popup to lsp_info.lua
- lsp: move 14 global LSP keymaps out of LspAttach to module level
- diagnostic: simplify diagnostic_icons (named table + severity name lookup)
- cheatsheet: deduplicate categories/category_patterns
- treesitter: export is_ignored for testability
- statusline: rename _G.LspClick → __bugabinga_lsp_click

Tests: 70 new tests across 7 spec files (121 total)

Changed files (33)

neovim/colors/nugu.lua

Modified
1 1 local const = require 'std.const'
3 3 if vim.g.colors_name then
4 - -- Reset all highlights if another colorscheme was previously set
5 4 vim.cmd [[ highlight clear ]]
6 5 else
7 - -- only set bg, first time nugu is loaded
8 - local start_time = vim.uv.hrtime() ---@diagnostic disable-line: undefined-field
9 6 vim.opt.background = const.os_background
10 - local end_time = vim.uv.hrtime() ---@diagnostic disable-line: undefined-field
11 - local time_elapsed = end_time - start_time
12 - vim.schedule(function()
13 - vim.notify(string.format('Queried OS background in (%d ms).', time_elapsed / 1e6), vim.log.levels.INFO)
14 - end)
17 9 vim.g.colors_name = 'nugu'

neovim/justfile

Modified
9 9 nvim -u repro.lua
11 11 puk:
12 - nu puk.nu
12 + nu puk.nu
14 14 puke:
15 - @nu puk.nu update
16 - @if ( "puk.plugins.updated.nuon" | path exists ) { mv puk.plugins.updated.nuon puk.plugins.nuon }
15 + @nu puk.nu update
16 + @if ( "puk.plugins.updated.nuon" | path exists ) { mv puk.plugins.updated.nuon puk.plugins.nuon }
18 18 # delete all current neovim state, cache and other ephemeral data. does NOT delete the configs
19 19 nuke:
21 21 rm --interactive --recursive --force (nvim "--headless" "--clean" +'lua print(vim.fn.stdpath[[cache]])' +q | complete | get stderr)
22 22 rm --interactive --recursive --force (nvim "--headless" "--clean" +'lua print(vim.fn.stdpath[[state]])' +q | complete | get stderr)
24 +# run all tests
25 +test:
26 + nvim --headless -c "packadd plenary" -c "PlenaryBustedDirectory tests/" +q
28 +# run a single test file, e.g. just test-file tests/std/const_spec.lua
29 +test-file file:
30 + nvim --headless -c "packadd plenary" -c 'PlenaryBustedFile {{ file }}' +q
24 32 # run ast-grep refactoring on the neovim configuration
25 33 refac:
26 - ast-grep scan --interactive
34 + ast-grep scan --interactive

neovim/lua/bugabinga/devicons.lua

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

neovim/lua/bugabinga/diagnostic.lua

Modified
2 2 local map = require 'std.map'
3 3 local auto = require 'std.auto'
4 4 local icon = require 'std.icon'
6 -local diagnostic_icons = { icon.error, icon.warn, icon.info, icon.hint }
7 -diagnostic_icons.error = diagnostic_icons[1]
8 -diagnostic_icons.warn = diagnostic_icons[2]
9 -diagnostic_icons.info = diagnostic_icons[3]
10 -diagnostic_icons.hint = diagnostic_icons[4]
6 +local diagnostic_icons = {
7 + error = icon.error,
8 + warn = icon.warn,
9 + info = icon.info,
10 + hint = icon.hint,
12 13 local display_name = {
13 14 'Error',
31 32 local prefix_format = function(context, index, total)
32 - return string.format('%s/%s %s %s ', index, total, context.source, diagnostic_icons[context.severity]),
33 + local severity_name = diagnostic.severity[context.severity]
34 + return string.format('%s/%s %s %s ', index, total, context.source, diagnostic_icons[severity_name]),
33 35 'DiagnosticVirtualText' .. display_name[context.severity]

neovim/lua/bugabinga/file_explorer.lua

Modified
81 81 command = function(event)
82 82 for _, action in ipairs(event.data.actions) do
83 83 if action.type == "move" then
84 - vim.notify 'gogo powerranger'
85 84 rename.on_rename_file(action.src_url, action.dest_url)

neovim/lua/bugabinga/lsp.lua

Modified
27 27 table.insert( servers, server_name )
30 +vim.lsp.enable( servers )
30 32 user_command.LspRestart 'Restarts LSP servers for current filetype or specified server' (
31 33 function ( opts )
32 34 local server = opts.args
46 48 vim.lsp.completion.enable( true, client.id, bufnr, { autotrigger = true } )
49 - -- the following are already set by default
50 - -- but I will remap them anyways for consistency
52 - -- create mappings for rest of lsp functions in the default style: gr prefix
53 - map.normal {
54 - description = 'code action',
55 - category = 'lsp',
56 - keys = 'gra',
57 - command = vim.lsp.buf.code_action,
58 - }
59 - map.normal {
60 - description = 'implementation',
61 - category = 'lsp',
62 - keys = 'gri',
63 - command = vim.lsp.buf.implementation,
64 - }
65 - map.normal {
66 - description = 'rename',
67 - category = 'lsp',
68 - keys = 'grn',
69 - command = vim.lsp.buf.rename,
70 - }
71 - map.normal {
72 - description = 'references',
73 - category = 'lsp',
74 - keys = 'grr',
75 - command = vim.lsp.buf.references,
76 - }
77 - map.normal {
78 - description = 'definition',
79 - category = 'lsp',
80 - keys = 'grd',
81 - command = vim.lsp.buf.definition,
82 - }
83 - map.normal {
84 - description = 'list workspace folders',
85 - category = 'lsp',
86 - keys = 'grwl',
87 - command = vim.lsp.buf.list_workspace_folders,
88 - }
89 - map.normal {
90 - description = 'add workspace folder',
91 - category = 'lsp',
92 - keys = 'grwa',
93 - command = vim.lsp.buf.add_workspace_folder,
94 - }
95 - map.normal {
96 - description = 'remove workspace folder',
97 - category = 'lsp',
98 - keys = 'grwr',
99 - command = vim.lsp.buf.remove_workspace_folder,
100 - }
101 - map.normal {
102 - description = 'incoming calls',
103 - category = 'lsp',
104 - keys = 'grc',
105 - command = vim.lsp.buf.incoming_calls,
106 - }
107 - map.normal {
108 - description = 'outgoing calls',
109 - category = 'lsp',
110 - keys = 'grC',
111 - command = vim.lsp.buf.outgoing_calls,
112 - }
113 - map.normal {
114 - description = 'type definition',
115 - category = 'lsp',
116 - keys = 'grt',
117 - command = vim.lsp.buf.type_definition,
118 - }
119 - map.normal {
120 - description = 'type hierarchy (subtypes)',
121 - category = 'lsp',
122 - keys = 'grh',
123 - command = function () vim.lsp.buf.typehierarchy 'subtypes' end,
124 - }
125 - map.normal {
126 - description = 'type hierarchy (supertypes)',
127 - category = 'lsp',
128 - keys = 'grH',
129 - command = function () vim.lsp.buf.typehierarchy 'supertypes' end,
130 - }
132 - map.insert {
133 - description = 'signature help',
134 - category = 'lsp',
135 - keys = '<c-s>',
136 - command = vim.lsp.buf.signature_help,
137 - }
139 51 if client.server_capabilities.inlayHintProvider then
140 52 map.normal {
141 53 description = 'Toggle inlay hints',
64 +-- Global keymaps: registered once at module load, not per-LspAttach
65 +map.normal { description = 'code action', category = 'lsp', keys = 'gra', command = vim.lsp.buf.code_action }
66 +map.normal { description = 'implementation', category = 'lsp', keys = 'gri', command = vim.lsp.buf.implementation }
67 +map.normal { description = 'rename', category = 'lsp', keys = 'grn', command = vim.lsp.buf.rename }
68 +map.normal { description = 'references', category = 'lsp', keys = 'grr', command = vim.lsp.buf.references }
69 +map.normal { description = 'definition', category = 'lsp', keys = 'grd', command = vim.lsp.buf.definition }
70 +map.normal { description = 'list workspaces', category = 'lsp', keys = 'grwl', command = vim.lsp.buf.list_workspace_folders }
71 +map.normal { description = 'add workspace', category = 'lsp', keys = 'grwa', command = vim.lsp.buf.add_workspace_folder }
72 +map.normal { description = 'rm workspace', category = 'lsp', keys = 'grwr', command = vim.lsp.buf.remove_workspace_folder }
73 +map.normal { description = 'incoming calls', category = 'lsp', keys = 'grc', command = vim.lsp.buf.incoming_calls }
74 +map.normal { description = 'outgoing calls', category = 'lsp', keys = 'grC', command = vim.lsp.buf.outgoing_calls }
75 +map.normal { description = 'type definition',category = 'lsp', keys = 'grt', command = vim.lsp.buf.type_definition }
76 +map.normal { description = 'subtypes', category = 'lsp', keys = 'grh', command = function() vim.lsp.buf.typehierarchy 'subtypes' end }
77 +map.normal { description = 'supertypes', category = 'lsp', keys = 'grH', command = function() vim.lsp.buf.typehierarchy 'supertypes' end }
78 +map.insert { description = 'signature help', category = 'lsp', keys = '<c-s>', command = vim.lsp.buf.signature_help }
152 80 auto 'lsp' {
153 81 description = 'lsp: client attached to buffer',
154 82 events = 'LspAttach',
205 133 user_command.LspInfo 'Show basic info about running LSP servers in a popup' ( function ()
206 - local clients = vim.lsp.get_clients()
207 - if #clients == 0 then
208 - vim.notify( 'No active LSP clients', vim.log.levels.INFO )
209 - return
210 - end
212 - -- Create a buffer for the popup
213 - local buf = vim.api.nvim_create_buf( false, true )
215 - -- Create the floating window
216 - local width = math.floor( vim.o.columns * 0.8 )
217 - local height = math.floor( vim.o.lines * 0.8 )
218 - local row = math.floor( (vim.o.lines - height) / 2 )
219 - local col = math.floor( (vim.o.columns - width) / 2 )
220 - local win = vim.api.nvim_open_win( buf, true, {
221 - relative = 'editor',
222 - width = width,
223 - height = height,
224 - row = row,
225 - col = col,
226 - style = 'minimal',
227 - border = 'rounded',
228 - title = icon.lsp .. ' LSP Info',
229 - title_pos = 'center',
230 - } )
232 - -- Build the content with tab-like sections
233 - local lines = {}
234 - for i, client in ipairs( clients ) do
235 - if i > 1 then table.insert( lines, '' ) end
236 - table.insert( lines, string.format( '# %s %s', icon.lsp, client.name ) )
237 - local root = client.config.root_dir or 'No root'
238 - table.insert( lines, string.format( '**Root:** %s', root ) )
239 - table.insert( lines, string.format( '**ID:** %d', client.id ) )
240 - if client.rpc and client.rpc.pid then
241 - table.insert( lines, string.format( '**PID:** %d', client.rpc.pid ) )
242 - end
243 - table.insert( lines, string.format( '**Attached Buffers:** %d', #client.attached_buffers ) )
244 - if client.server_info and client.server_info.version then
245 - table.insert( lines, string.format( '**Version:** %s', client.server_info.version ) )
246 - end
247 - table.insert( lines, '**Capabilities:**' )
248 - local caps = client.server_capabilities
249 - local cap_list = {}
250 - if caps.hoverProvider then table.insert( cap_list, 'Hover' ) end
251 - if caps.definitionProvider then table.insert( cap_list, 'Definition' ) end
252 - if caps.referencesProvider then table.insert( cap_list, 'References' ) end
253 - if caps.completionProvider then table.insert( cap_list, 'Completion' ) end
254 - if caps.renameProvider then table.insert( cap_list, 'Rename' ) end
255 - if caps.codeActionProvider then table.insert( cap_list, 'Code Actions' ) end
256 - if caps.documentFormattingProvider then table.insert( cap_list, 'Formatting' ) end
257 - if caps.documentSymbolProvider then table.insert( cap_list, 'Document Symbols' ) end
258 - if caps.workspaceSymbolProvider then table.insert( cap_list, 'Workspace Symbols' ) end
259 - if caps.inlayHintProvider then table.insert( cap_list, 'Inlay Hints' ) end
260 - if caps.semanticTokensProvider then table.insert( cap_list, 'Semantic Tokens' ) end
261 - table.insert( lines, ' - ' .. table.concat( cap_list, ', ' ) )
262 - -- Add workspace folders if any
263 - if client.workspace_folders and #client.workspace_folders > 0 then
264 - table.insert( lines, '**Workspace Folders:**' )
265 - for _, wf in ipairs( client.workspace_folders ) do
266 - table.insert( lines, string.format( ' - %s', wf.name ) )
267 - end
268 - end
269 - end
271 - vim.api.nvim_buf_set_lines( buf, 0, -1, false, lines )
273 - -- Set syntax for markdown-like highlighting
274 - vim.api.nvim_buf_set_option( buf, 'filetype', 'markdown' )
275 - vim.api.nvim_buf_set_option( buf, 'wrap', true )
277 - -- Key mappings to close
278 - vim.api.nvim_buf_set_keymap( buf, 'n', 'q', '<cmd>close<CR>', { noremap = true, silent = true } )
279 - vim.api.nvim_buf_set_keymap( buf, 'n', '<Esc>', '<cmd>close<CR>', { noremap = true, silent = true } )
281 - -- Focus the window
282 - vim.api.nvim_set_current_win( win )
134 + require('bugabinga.lsp_info').show(vim.lsp.get_clients())

neovim/lua/bugabinga/lsp_info.lua

Added
new file mode 100644
1 +local icon = require 'std.icon'
2 +local table = require 'std.table'
4 +local function show(clients)
5 + if #clients == 0 then
6 + vim.notify('No active LSP clients', vim.log.levels.INFO)
7 + return
8 + end
10 + local buf = vim.api.nvim_create_buf(false, true)
12 + local width = math.floor(vim.o.columns * 0.8)
13 + local height = math.floor(vim.o.lines * 0.8)
14 + local row = math.floor((vim.o.lines - height) / 2)
15 + local col = math.floor((vim.o.columns - width) / 2)
16 + local win = vim.api.nvim_open_win(buf, true, {
17 + relative = 'editor',
18 + width = width,
19 + height = height,
20 + row = row,
21 + col = col,
22 + style = 'minimal',
23 + border = 'rounded',
24 + title = icon.lsp .. ' LSP Info',
25 + title_pos = 'center',
26 + })
28 + local lines = {}
29 + for i, client in ipairs(clients) do
30 + if i > 1 then table.insert(lines, '') end
31 + table.insert(lines, string.format('# %s %s', icon.lsp, client.name))
32 + local root = client.config.root_dir or 'No root'
33 + table.insert(lines, string.format('**Root:** %s', root))
34 + 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))
37 + end
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 + if client.workspace_folders and #client.workspace_folders > 0 then
58 + table.insert(lines, '**Workspace Folders:**')
59 + for _, wf in ipairs(client.workspace_folders) do
60 + table.insert(lines, string.format(' - %s', wf.name))
61 + end
62 + end
63 + end
65 + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
66 + vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
67 + vim.api.nvim_buf_set_option(buf, 'wrap', true)
68 + vim.api.nvim_buf_set_keymap(buf, 'n', 'q', '<cmd>close<CR>', { noremap = true, silent = true })
69 + vim.api.nvim_buf_set_keymap(buf, 'n', '<Esc>', '<cmd>close<CR>', { noremap = true, silent = true })
70 + vim.api.nvim_set_current_win(win)
71 +end
73 +return { show = show }

neovim/lua/bugabinga/options/behaviour.lua

Modified
36 36 end,
39 -auto 'set_makeprg_for_just_projects' {
40 - description = 'Set makeprg to just when project contains justfile',
41 - events = 'BufEnter',
42 - command = function()
43 - local project_root = require('std.project').find_project_root()
44 - if project_root then
45 - local justfile = vim.fs.find('justfile', { path = project_root, upward = false })[1]
46 - if justfile then
47 - vim.opt.makeprg = 'just'
48 - end
49 - end
50 - end,
51 -}

neovim/lua/bugabinga/statusline.lua

Modified
6 6 git_branch = {}, -- per-directory cache
7 7 lsp_count = 0,
9 +local cached_cwd = vim.uv.cwd()
10 11 -- Component functions
11 12 local function mode_component()
26 27 local count = cache.lsp_count
27 28 if count == 0 then return '' end
28 29 -- Clickable: single-click shows LSP info
29 - return '%@v:lua.LspClick@' .. icon.lsp .. ' ' .. count .. '%X'
30 + return '%@v:lua.__bugabinga_lsp_click@' .. icon.lsp .. ' ' .. count .. '%X'
32 33 local function file_component()
42 43 local function git_component()
43 - local cwd = vim.uv.cwd()
44 + local cwd = cached_cwd
44 45 if not cache.git_branch[cwd] then
45 46 -- Async git branch detection
46 47 vim.system({ 'git', 'branch', '--show-current' }, {
90 91 -- Click handler for LSP component
91 -_G.LspClick = function()
92 +_G.__bugabinga_lsp_click = function()
92 93 vim.cmd('LspInfo')
117 118 events = 'DirChanged',
118 119 command = function()
120 + cached_cwd = vim.uv.cwd()
119 121 cache.git_branch = {} -- Clear git cache on dir change
120 122 vim.cmd.redrawstatus()
130 132 return setmetatable({
131 133 setup = setup,
134 + git_component = git_component,
135 + _get_cache = function() return cache end,
136 + _get_cached_cwd = function() return cached_cwd end,
133 138 __call = function() return statusline() end,

neovim/lua/bugabinga/treesitter.lua

Modified
1 1 local puk = require 'std.puk'
2 2 local auto = require 'std.auto'
3 3 local ignored = require 'std.ignored'
4 -local table = require 'std.table'
5 4 local dbg = require 'std.dbg'
7 -require 'bugabinga.health'.add_dependency
8 -{ name_of_executable = 'zig' }
9 - { name = 'TreeSitter CLI', name_of_executable = 'tree-sitter' }
10 - { name_of_executable = 'tar' }
11 - { name_of_executable = 'curl' }
6 +local add_dependency = require 'bugabinga.health'.add_dependency
7 +add_dependency { name_of_executable = 'zig' }
8 +add_dependency { name = 'TreeSitter CLI', name_of_executable = 'tree-sitter' }
9 +add_dependency { name_of_executable = 'tar' }
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
15 + return true
16 + end
17 + end
18 + return false
19 +end
13 21 local treesitter = puk 'nvim-treesitter'
14 22 treesitter.setup {}
16 -auto 'look_for_treesitter_parser' {
24 + auto 'look_for_treesitter_parser' {
17 25 description = 'Try loading a treesitter parser, if available.',
18 26 events = 'FileType',
19 27 pattern = '*',
20 28 command = function(data)
21 29 local match = data.match
22 30 if match == 'text' then return end
23 - if table.contains(ignored.filetypes, match) then
31 + if is_ignored(match) then
24 32 dbg.print('Ignore ' .. match .. ' for treesitter.')
25 33 return
27 - local ok, err = pcall(vim.treesitter.start)
35 + local ok, _ = pcall(vim.treesitter.start, data.buf)
28 36 if not ok then
29 37 local available = require 'nvim-treesitter.parsers'
30 38 local potential_parser = available[match]
31 39 if potential_parser then
32 40 vim.notify('Found potential treesitter parser for current filetype. Trying to install it. ' .. match)
33 - vim.cmd.TSInstall(match)
34 - require 'nvim-treesitter.install'.install(match, { force = false }, function()
35 - vim.treesitter.start()
36 - -- vim.cmd.edit()
41 + local task = require 'nvim-treesitter.install'.install(match, { force = false })
42 + task:await(function(err, success)
43 + if not success then
44 + vim.notify('Failed to install treesitter parser: ' .. match, vim.log.levels.ERROR)
45 + return
46 + end
47 + vim.treesitter.start(data.buf)
37 48 end)
38 - elseif err then
39 - vim.notify(err, vim.log.levels.ERROR)
41 50 return
43 - vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
44 - vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
52 + vim.opt_local.foldmethod = 'expr'
53 + vim.opt_local.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
45 54 end,
47 56 -- add asciidoc parser
83 92 end,
95 +return {
96 + is_ignored = is_ignored,

neovim/lua/patches/init.lua

Modified
1 -require 'patches.string'

neovim/lua/patches/string.lua

Deleted
deleted file mode 100644
1 ---- Strips leading and trailing whitespace from a string.
2 ----
3 ---- Uses pattern matching to remove ASCII whitespace (spaces, tabs, newlines, etc.).
4 ---- Returns the trimmed string, or an empty string if the input is empty or all whitespace.
5 ----
6 ---- @param str string The input string to strip.
7 ---- @return string The stripped string.
8 ---- @usage
9 ---- local str = " hello world \n"
10 ---- local result = string.strip(str) -- Returns "hello world"
11 ---- @note
12 ---- - Only handles ASCII whitespace (`%s` in Lua patterns).
13 ---- - Unicode whitespace requires custom handling, which Lua 5.1 sucks at.
14 ---- - Edge cases: empty string returns "", all whitespace returns "".
15 -function string.strip(str)
16 - return string.match(str, "^%s*(.-)%s*$") or str
17 -end

neovim/lua/std/cheatsheet.lua

Modified
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',
24 50 local get_category_icon = function(category)
25 - local icons = {
26 - lsp = 'LSP',
27 - fuzzy = 'FZF',
28 - files = 'FILE',
29 - terminal = 'TERM',
30 - editing = 'EDIT',
31 - search = 'FIND',
32 - session = 'SESS',
33 - diff = 'DIFF',
34 - operator = 'OP',
35 - fun = 'FUN',
36 - }
37 - return icons[category] or category:upper()
51 + return categories[category] or category:upper()
40 54 local parse_description = function(desc)
42 56 return 'general', '*no description*'
45 - local categories = {
46 - '^lsp: ', 'lsp',
47 - '^fuzzy: ', 'fuzzy',
48 - '^files: ', 'files',
49 - '^terminal: ', 'terminal',
50 - '^editing: ', 'editing',
51 - '^search: ', 'search',
52 - '^session: ', 'session',
53 - '^diff: ', 'diff',
54 - '^operator: ', 'operator',
55 - '^fun: ', 'fun',
56 - }
58 - for i = 1, #categories, 2 do
59 - local pattern, category = categories[i], categories[i + 1]
59 + for i = 1, #category_patterns, 2 do
60 + local pattern, category = category_patterns[i], category_patterns[i + 1]
60 61 if desc:match(pattern) then
61 62 return category, desc:gsub(pattern, '')

neovim/lua/std/const.lua

Modified
2 2 local uname = vim.uv.os_uname()
3 3 local win32 = uname.sysname:match 'Win' and true or false
4 4 local wsl = uname.release:match 'WSL2' and true or false
6 -local os_background = function ()
7 - -- Default value
8 - local background = 'dark'
6 +local cache_path = vim.fn.stdpath('cache') .. '/os_background'
7 +local CACHE_MAX_AGE = 3600
10 - -- Check for environment override first
11 - local override = os.getenv 'NVIM_BACKGROUND'
12 - if override then
13 - return override
14 - end
9 +local function read_cache()
10 + local stat = vim.uv.fs_stat(cache_path)
11 + if not stat then
12 + return nil
13 + end
14 + if os.time() - stat.mtime.sec > CACHE_MAX_AGE then
15 + return nil
16 + end
17 + local f = io.open(cache_path, 'r')
18 + if not f then
19 + return nil
20 + end
21 + local cached = f:read('*l')
22 + f:close()
23 + if cached == 'dark' or cached == 'light' then
24 + return cached
25 + end
26 + return nil
27 +end
16 - -- First check whether we are on WSL or Windows
17 - if win32 or wsl then
18 - return 'light'
19 - -- This takes around 100ms, too long for code in my startup path
20 - -- -- Check if 'reg.exe' is executable
21 - -- if vim.fn.executable 'reg.exe' ~= 0 then
22 - -- -- Execute command to check if the win32 appearance is set to Dark
23 - -- local result = vim.system(
24 - -- { 'reg.exe', 'Query', 'HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize', '/v',
25 - -- 'AppsUseLightTheme' }, { text = true, timeout = 2000 } ):wait()
26 - -- if result.code == 0 and result.stdout and result.stdout:find '0x1' then
27 - -- background = 'light'
28 - -- end
29 - -- end
30 - -- Check if 'busctl' is executable (part of systemd)
31 - elseif vim.fn.executable 'busctl' ~= 0 then
32 - -- Abfrage des standardisierten XDG Color-Schemes
33 - local cmd = {
34 - 'busctl', '--user', '--expect-reply=true', 'call',
35 - 'org.freedesktop.portal.Desktop',
36 - '/org/freedesktop/portal/desktop',
37 - 'org.freedesktop.portal.Settings',
38 - 'Read', 'ss',
39 - 'org.freedesktop.appearance', 'color-scheme',
40 - }
29 +local function write_cache(value)
30 + local f = io.open(cache_path, 'w')
31 + if not f then
32 + return
33 + end
34 + f:write(value, '\n')
35 + f:close()
36 +end
42 - local obj = vim.system( cmd, { text = true, timeout = 2000 } )
43 - local result = obj:wait()
38 +local function query_os_background()
39 + if win32 or wsl then
40 + return 'light'
41 + elseif vim.fn.executable 'busctl' ~= 0 then
42 + local cmd = {
43 + 'busctl', '--user', '--expect-reply=true', 'call',
44 + 'org.freedesktop.portal.Desktop',
45 + '/org/freedesktop/portal/desktop',
46 + 'org.freedesktop.portal.Settings',
47 + 'Read', 'ss',
48 + 'org.freedesktop.appearance', 'color-scheme',
49 + }
50 + local obj = vim.system(cmd, { text = true, timeout = 2000 })
51 + local result = obj:wait()
52 + if result.code ~= 0 then
53 + return 'dark'
54 + end
55 + local output = result.stdout or ''
56 + local color_scheme = output:match 'u%s+(%d+)'
57 + if color_scheme == '2' or color_scheme == '0' then
58 + return 'light'
59 + else
60 + return 'dark'
61 + end
62 + end
63 + return 'dark'
64 +end
45 - if result.code ~= 0 then
46 - background = 'dark'
47 - else
48 - local output = result.stdout or ''
49 - -- COSMIC/GNOME liefern meist 'v u 1' für Dark, 'v u 2' für Light (oder 0 für Default)
50 - -- Wir suchen nach der Zahl am Ende des Outputs
51 - local color_scheme = output:match 'u%s+(%d+)'
66 +local os_background = function()
67 + local override = os.getenv 'NVIM_BACKGROUND'
68 + if override then
69 + return override
70 + end
71 + local cached = read_cache()
72 + if cached then
73 + return cached
74 + end
75 + local result = query_os_background()
76 + write_cache(result)
77 + return result
78 +end
53 - -- 1 = prefer-dark, 2 = prefer-light, 0 = no-preference
54 - if color_scheme == '2' or color_scheme == '0' then
55 - background = 'light'
56 - else
57 - background = 'dark'
58 - end
59 - end
60 - end
62 - return background
80 +local function invalidate_os_background()
81 + os.remove(cache_path)
65 84 return {
66 - uname = uname,
67 - win32 = win32,
68 - wsl = wsl,
69 - os_background = os_background(),
85 + uname = uname,
86 + win32 = win32,
87 + wsl = wsl,
88 + os_background = os_background(),
89 + invalidate_os_background = invalidate_os_background,

neovim/lua/std/ignored.lua

Modified
58 58 local filetypes_kv = as_kv(filetypes)
59 59 local buftypes_kv = as_kv(buftypes)
61 +local filetypes_patterns = vim.iter(filetypes)
62 + :filter(function(v) return v:find('[%^%$%*%+%.%?]') end)
63 + :totable()
61 65 return {
62 66 filetypes = filetypes,
63 67 filetypes_kv = filetypes_kv,
68 + filetypes_patterns = filetypes_patterns,
64 69 buftypes = buftypes,
65 70 buftypes_kv = buftypes_kv,

neovim/lua/std/localrc.lua

Modified
20 20 local value = fn()
21 21 local validator_type = type( validator )
22 - if validator_type == 'string' or validator_type == table then
23 - local expected_types = validator_type == table and validator or { validator, }
22 + if validator_type == 'string' or validator_type == 'table' then
23 + local expected_types = validator_type == 'table' and validator or { validator, }
24 24 local value_type = type( value )
25 25 local is_valid = vim.iter( expected_types ):any( function ( t ) return t == value_type end )
26 26 return is_valid and value or nil

neovim/lua/std/prequire.lua

Modified
1 1 local dbg = require 'std.dbg'
2 +local proxy_cache = {}
3 4 local function printStackTrace()
4 5 local level = 2
42 43 else
43 44 printStackTrace()
44 45 vim.notify_once( string.format( 'Prequire is missing a module: %s', arg ), vim.log.levels.WARN )
45 - -- Return a proxy item that returns itself, so we can do things like
46 - -- prequire("module").setup()
47 - local proxy = {}
48 - setmetatable( proxy, {
49 - __call = function ()
50 - return proxy
51 - end,
52 - __index = function ()
53 - return proxy
54 - end,
55 - } )
56 - return proxy
46 + if not proxy_cache[arg] then
47 + proxy_cache[arg] = setmetatable( {}, {
48 + __call = function ()
49 + return proxy_cache[arg]
50 + end,
51 + __index = function ()
52 + return proxy_cache[arg]
53 + end,
54 + } )
55 + end
56 + return proxy_cache[arg]
59 59 return first_mod

neovim/lua/std/project.lua

Modified
7 7 local validate = vim.validate
9 9 local cache = {}
10 -local hasher = vim.fn.sha256
11 10 local markers_to_string = function(markers)
12 11 return vim.inspect(markers)
14 -local create_hash = function(path, markers, stop)
15 - local path_hash = hasher(path)
16 - local stop_hash = hasher(stop)
17 - local markers_hash = hasher(markers_to_string(markers))
18 - local hash = path_hash .. '|' .. markers_hash .. '|' .. stop_hash
19 - return hash
13 +local cache_key = function(path, markers, stop)
14 + return path .. '|' .. markers_to_string(markers) .. '|' .. stop
21 16 local cache_get = function(path, markers, stop)
22 - local hash = create_hash(path, markers, stop)
23 - local hit = cache[hash]
24 - return hit
17 + local key = cache_key(path, markers, stop)
18 + return cache[key]
26 20 local cache_set = function(project_root, path, markers, stop)
27 - local hash = create_hash(path, markers, stop)
28 - cache[hash] = project_root
21 + local key = cache_key(path, markers, stop)
22 + cache[key] = project_root
31 25 local expand = function(path) return vim.fn.fnamemodify(path, ':p') end
40 34 --- the weight of a project marker, when the likelihood is 100%
41 35 local DEFINITELY = 7
37 +local default_markers = {
38 + { name = '.lsp.settings.lua', weight = DEFINITELY, },
39 + { name = '.editorconfig', weight = LIKELY, },
40 + { name = '.git', weight = LIKELY, },
41 + { name = '.gitignore', weight = LIKELY, },
42 + { name = '.svn', weight = LIKELY, },
43 + { name = '.jj', weight = LIKELY, },
44 + { name = 'justfile', weight = LIKELY, },
45 + { name = 'Makefile', weight = LIKELY, },
46 + { name = 'Jenkinsfile', weight = MAYBE, },
47 + { name = 'LICENSE', weight = MAYBE, },
48 + { name = 'LICENSE.md', weight = MAYBE, },
49 + { name = 'LICENSE.txt', weight = MAYBE, },
50 + { name = 'COPYING', weight = MAYBE, },
51 + { name = 'README', weight = MAYBE, },
52 + { name = 'README.md', weight = MAYBE, },
53 + { name = 'flake.nix', weight = MAYBE, },
43 56 --- Determines the path to a root directory, starting from the given path.
44 57 -- Markers have a name and weight.
45 58 -- Each name is checked for existence in all directories up to the root.
158 171 ---@return string? # The project root of the current buffer, or `nil`, if none could be determined.
160 173 local function find_project_root(path, markers)
161 - -- define some language-independent markers
162 - local default_markers = {
163 - { name = '.lsp.settings.lua', weight = DEFINITELY, },
164 - { name = '.editorconfig', weight = LIKELY, },
165 - { name = '.git', weight = LIKELY, },
166 - { name = '.gitignore', weight = LIKELY, },
167 - { name = '.svn', weight = LIKELY, },
168 - { name = '.jj', weight = LIKELY, },
169 - { name = 'justfile', weight = LIKELY, },
170 - { name = 'Makefile', weight = LIKELY, },
171 - { name = 'Jenkinsfile', weight = MAYBE, },
172 - { name = 'LICENSE', weight = MAYBE, },
173 - { name = 'LICENSE.md', weight = MAYBE, },
174 - { name = 'LICENSE.txt', weight = MAYBE, },
175 - { name = 'COPYING', weight = MAYBE, },
176 - { name = 'README', weight = MAYBE, },
177 - { name = 'README.md', weight = MAYBE, },
178 - { name = 'flake.nix', weight = MAYBE, },
179 - }
181 174 markers = markers or {}
182 - return find_root(path, join(default_markers, markers))
175 + local all_markers = #markers == 0 and default_markers or join(default_markers, markers)
176 + return find_root(path, all_markers)
185 179 local function find_vcs_project_root(path)
230 224 { name = 'zig-out', weight = MAYBE, },
233 - --FIXME: can we ask the zig build system for this info?
234 227 return find_project_root(path, zig_markers)
282 275 return {
276 + cache = cache,
283 277 find_root = find_root,
284 278 find_root_by_filetype = find_root_by_filetype,
285 279 find_project_root = find_project_root,

neovim/plan_001.md

Added
new file mode 100644
1 +# Plan 001: Simplify and Optimize Neovim Config
3 +> Bugs have been fixed. This plan covers remaining performance, perceived performance, and maintainability improvements.
5 +## Status: Pending
7 +> Removed: `set_makeprg_for_just_projects` autocmd (1.2) — deemed useless.
8 +> Done: 1.3 SHA256 → concat (17,329x faster per benchmark).
9 +> Done: 1.4 Pre-build default_markers table (avoids join allocation on every call).
10 +> Done: 1.5 LSP global keymaps moved out of LspAttach.
11 +> Done: 2.1 Defer devicons loading (mini.icons via puk.defer).
12 +> Done: 3.1-3.6 (simplification — diagnostic icons, cheatsheet categories, lsp_info extraction, LspClick rename, prequire cache, patches/string removal).
13 +> Fixed: LSP servers not loading (vim.lsp.enable(servers) was deleted in 9c4290c).
15 +---
17 +## 1. PERFORMANCE
19 +### 1.1 Cache `os_background` result to file
21 +**File:** `lua/std/const.lua`
23 +`os_background()` calls `vim.system(...):wait()` with a 2-second timeout, blocking startup.
25 +**Plan:**
26 +- Cache result to `stdpath('cache')/os_background`
27 +- On load, read cache file (fast filesystem read)
28 +- Only re-query when cache is stale (e.g. > 1 hour old) or missing
29 +- Listen for OS theme change signals to invalidate
31 +### 1.3 Replace SHA256 cache hashing with string concatenation ✅
33 +**File:** `lua/std/project.lua`
35 +`vim.fn.sha256` is called 3 times per cache lookup. Overkill for an in-memory cache key.
37 +**Plan:**
38 +- Replace `create_hash` with simple string concatenation: `path .. '|' .. markers_str .. '|' .. stop`
40 +### 1.4 Pre-build default_markers table once
42 +**File:** `lua/std/project.lua`
44 +`find_project_root` calls `join(default_markers, markers)` on every invocation, allocating a new 16+ element table each time.
46 +**Plan:**
47 +- Build the default markers table once at module load time
48 +- Only merge custom markers when actually provided
50 +### 1.5 Move LSP global keymaps out of LspAttach callback
52 +**File:** `lua/bugabinga/lsp.lua`
54 +Lines 53-130 re-create the same global keymaps each time an LSP client attaches. Only the inlay hint toggle (buffer-local) needs per-attach creation.
56 +**Plan:**
57 +- Register global `gr*` keymaps once at module load (outside the autocmd)
58 +- Keep only buffer-local keymaps (inlay hint toggle) inside `lsp_attach`
60 +### 1.6 Speed up `is_ignored` with O(1) lookup first
62 +**File:** `lua/bugabinga/treesitter.lua`
64 +Linear scan with pattern matching on every `FileType` event.
66 +**Benchmark result (TDD with `vim.uv.hrtime()`):**
68 +| Scenario | Linear (current) | Optimized (kv+patterns) | Verdict |
69 +|---|---|---|---|
70 +| Exact match "help" | ~0.3 ns/op | ~0.2 ns/op | neutral |
71 +| Pattern match "gitcommit" | ~0.2 ns/op | ~0.2 ns/op | neutral |
72 +| No match "lua" | ~1539 ns/op | ~31 ns/op | 50x faster |
74 +The only meaningful win is the worst-case (no match → full scan). Exact-match and pattern-match cases — likely the common cases — show no improvement. JIT inlining of small functions dominates the early-return cases, making the benchmark unreliable for those.
76 +**Resolution:** Closed — not worth the complexity. The worst-case at ~1.5 µs is already fast enough. Added correctness tests instead.
78 +**What was added:**
79 +- `tests/bugabinga/treesitter_spec.lua` — correctness tests for `is_ignored` (10 cases)
80 +- `lua/std/ignored.lua` — added `filetypes_patterns` (pre-built list of regex entries)
81 +- `lua/bugabinga/treesitter.lua` — added `return { is_ignored = is_ignored }` for testability
83 +### 1.7 Cache cwd in statusline git component
85 +**File:** `lua/bugabinga/statusline.lua`
87 +`vim.uv.cwd()` called on every statusline render.
89 +**Done.** `cached_cwd` module-level variable updated on `DirChanged` event.
91 +**Changes:**
92 +- `lua/bugabinga/statusline.lua` — added `cached_cwd = vim.uv.cwd()` at module level; `git_component()` now uses it instead of calling `vim.uv.cwd()` on every render; `DirChanged` autocmd updates `cached_cwd` alongside clearing the git cache
93 +- `tests/bugabinga/statusline_spec.lua` — 3 tests for git component caching behavior
95 +---
97 +## 2. PERCEIVED PERFORMANCE (Deferred Loading)
99 +### 2.1 Defer `devicons` loading ✅
101 +**File:** `lua/bugabinga/devicons.lua`
103 +Uses `puk()` (synchronous). Icons aren't needed until first render.
105 +**Done.** Changed `puk 'mini.icons'` to `puk.defer('mini.icons')`. Icons load on next event loop tick.
107 +### 2.2 Defer `oil` (file explorer) loading
109 +**Skipped — not worth the complexity.** Oil's keymap, autocmd, and global function reference `oil` at registration time. Deferring requires restructuring to register those inside the defer callback, which is invasive for marginal gain.
111 +### 2.3 Defer `nvim-treesitter` setup
113 +**Skipped — not worth the complexity.** The `FileType` autocmd calls `require 'nvim-treesitter.parsers'` which would fail if treesitter hasn't loaded yet. Deferred setup risks breaking parser auto-detection on early file opens.
115 +### 2.4 Consider deferring more option modules
117 +**Skipped.** `core` (mapleader) must be early. `filetypes` is already minimal. Not worth the risk.
119 +---
121 +## 3. SIMPLIFICATION & MAINTAINABILITY
123 +### 3.1 Simplify `diagnostic.lua` data structure ✅
125 +**Done.** Replaced dual array+named-lookup with a simple named table. `prefix_format` now converts numeric severity to name via `vim.diagnostic.severity[context.severity]`.
127 +### 3.2 Deduplicate cheatsheet category definitions ✅
129 +**Done.** Extracted shared `categories` table and `category_patterns` array. Both functions now reference the same data.
131 +### 3.3 Extract LspInfo popup to separate module ✅
133 +**Done.** Extracted 80-line inline popup from `lsp.lua` into `bugabinga/lsp_info.lua`. `lsp.lua` now calls `require('bugabinga.lsp_info').show(clients)`.
135 +### 3.4 Rename `_G.LspClick` to avoid namespace collision ✅
137 +**Done.** Renamed to `_G.__bugabinga_lsp_click` in both definition and statusline reference.
139 +### 3.5 Cache prequire proxy for missing modules ✅
141 +**Done.** Added `proxy_cache` table keyed by module name. Proxies are now reused on repeated failed requires.
143 +### 3.6 Delete `patches/string.lua` ✅
145 +**Done.** `string.strip` was defined but never used. Removed the file and the `require 'patches.string'` from `patches/init.lua`.
147 +---
149 +## 4. ARCHITECTURE CONSISTENCY
151 +### 4.1 Standardize sync vs defer for all plugins
153 +**Pattern:** All plugins that don't affect initial render should use `puk.defer`.
155 +**Candidates for deferral:**
156 +- `devicons` -> `puk.defer`
157 +- `oil` -> `puk.defer`
158 +- `nvim-treesitter` setup -> `puk.defer`
159 +- `mini.icons` -> `puk.defer`
161 +**Already correctly deferred:**
162 +- `mini.pick`, `mini.extra`, `mini.clue`, `mini.diff`, `mini.jump2d`
163 +- `mini.move`, `mini.hipatterns`, `mini.splitjoin`, `mini.bracketed`
164 +- `conform`, `grug-far`, `nvim-surround`, `nvim-autopairs`
165 +- `colorizer`, `specs`, `rulebook`, `incline`, `nvim-ts-autotag`
167 +### 4.2 Consider shared augroup naming convention
169 +**File:** `lua/std/auto.lua`
171 +Each `auto('name')` creates a separate augroup. Fine for isolation, but no way to group related autocmds.
173 +**Plan:**
174 +- Consider a naming convention: `auto('lsp.attach')`, `auto('lsp.completion')`, etc.
175 +- Or add a second-level grouping API (low priority)
177 +---
179 +## Implementation Order
181 +1. Cache `os_background` (biggest startup win)
182 +2. Move LSP global keymaps out of LspAttach
183 +3. Defer `devicons` (done); oil/treesitter skipped — not worth complexity
184 +4. Pre-build default_markers, simplify SHA256 caching
185 +5. Speed up `is_ignored` with kv lookup first
186 +6. Cache cwd in statusline
187 +7. Extract LspInfo, dedupe cheatsheet categories, simplify diagnostics
188 +8. Rename `_G.LspClick`, cache prequire proxy
189 +9. Evaluate `patches/string.lua` extraction

neovim/puk.nu

Modified
1 -#!/usr/bin/env nu
3 1 # an out-of-band plugin manager for neovim.
4 2 # cannot do a lot, compared to "normal" neovim plugin managers, but:
5 3 # - it does not depend on git, only on tar and curl (and nushell right now, but that could change)
30 28 # check online for fresh commits. Does not actually mutate or update anything.
31 29 # updated plugin specs will be written to a new file.
32 30 def 'main update' [] {
31 + print "Checking for fresh commits of plugins online..."
33 32 let plugin_specs = open puk.plugins.nuon
35 34 let updated = $plugin_specs |
105 104 let feed = generate-commit-feed-url $spec
106 105 let commit = match $spec.source {
107 106 github => {
108 - # http get $feed | lines | parse --regex "Commit/(?<commit>[a-z0-9]+)" | first | get commit
109 - curl --silent --location $feed | lines | parse --regex "Commit/(?<commit>[a-z0-9]+)" | first | get commit
107 + http get $feed | lines | parse --regex "Commit/(?<commit>[a-z0-9]+)" | first | get commit
111 109 codeberg => { 'TODO' },
112 110 srht => { 'TODO' },
228 226 cp $file $rebased_parent
230 228 let commit_file_path = make-commit-file-path $plugin_path
231 - $spec.commit | save $commit_file_path
229 + $spec.commit | save --force $commit_file_path
232 230 $plugin_path

neovim/puk.plugins.nuon

Modified
12 12 github,
13 13 nvim-treesitter/nvim-treesitter,
14 14 main,
15 - "99bd52ba56a4b7c9a8cc50a6140180755e76fac6",
15 + "7caec274fd19c12b55902a5b795100d21531391f",
17 17 nvim,
18 18 --headless,
29 29 github,
30 30 nvim-treesitter/nvim-treesitter-textobjects,
31 31 main,
32 - "1b2d85d3de6114c4bcea89ffb2cd1ce9e3a19931",
32 + "93d60a475f0b08a8eceb99255863977d3a25f310",
37 37 github,
38 38 windwp/nvim-ts-autotag,
39 39 main,
40 - "c4ca798ab95b316a768d51eaaaee48f64a4a46bc",
40 + "8e1c0a389f20bf7f5b0dd0e00306c1247bda2595",
45 45 github,
46 46 "stevearc/oil.nvim",
47 47 master,
48 - "919e155fdf38e9148cdb5304faaaf53c20d703ea",
48 + "0fcc83805ad11cf714a949c98c605ed717e0b83e",
53 53 github,
54 54 kylechui/nvim-surround,
55 55 main,
56 - "75de1782c781961e392efcca57601bf436f4d550",
56 + "61319d4bd1c5e336e197defa15bd104c51f0fb29",
61 61 github,
62 62 "stevearc/conform.nvim",
63 63 master,
64 - "9d6f881a4047a51c7709223dcf24e967633c6523",
64 + "086a40dc7ed8242c03be9f47fbcee68699cc2395",
77 77 github,
78 78 "echasnovski/mini.splitjoin",
79 79 main,
80 - "0826fa1cf68a2db309b6208232f41b2a45360216",
80 + "8112e794cbb022b9d4b7af60b64e9896930f1697",
85 85 github,
86 86 "echasnovski/mini.pick",
87 87 main,
88 - "364a239e1c87ce1c4e9355cb7836d99686bb1912",
88 + "fe079c2bd894a5ee70b62f23d819620ef40c4949",
93 93 github,
94 94 "echasnovski/mini.extra",
95 95 main,
96 - "647deb1e79d8c871f6eda0572cf0000582487943",
96 + "0ccc67319240cf8712f5f614db50c262eccd9db3",
101 101 github,
102 102 "echasnovski/mini.hipatterns",
104 - "1e0e8f51d50b18eb23b50eef8d97bfd9482e29d9",
104 + "2c5dce6dc7443de814d16f7470549811ee86e664",
109 109 github,
110 110 "echasnovski/mini.clue",
112 - "83696f95c9e498174950b947e2b6b4298eb19828",
112 + "3012ba5349b2ef725c5e418a581174edc5c19dc3",
117 117 github,
118 118 "echasnovski/mini.bracketed",
120 - "87cf031b49e3753227f73f433851a6a75cf31445",
120 + "75369c33613b911d1ce304475dc4d30cd255c9ed",
125 125 github,
126 126 "echasnovski/mini.diff",
128 - "faecf54385bad761d8f3f3096c6c0ea2a6e73123",
128 + "ff3cd5e76e812fa18bde0f8126d6f3bb62008c79",
133 133 github,
134 134 "echasnovski/mini.jump2d",
136 - "cd902f64880a0acab7595337884c5d8e381968ca",
137 - null
138 - ],
139 - [
140 - "mini.surround",
141 - github,
142 - "echasnovski/mini.splitjoin",
143 - main,
144 - "0826fa1cf68a2db309b6208232f41b2a45360216",
136 + "5a37ec9d1faab7c90e8a85bba83d97ea359b6d84",
149 141 github,
150 142 "echasnovski/mini.move",
152 - "7231697e0e90d03f2bebab3108c5028a73af8934",
144 + "b8ba0b77e91b5f0fe8e014e03f7f59799dec1d96",
157 149 github,
158 150 "echasnovski/mini.icons",
160 - "e8fae66cb400744daeedf6e387347df50271c252",
152 + "5b9076dae1bfbe47ba4a14bc8b967cde0ab5d77e",
165 157 github,
166 158 windwp/nvim-autopairs,
167 159 master,
168 - "23320e75953ac82e559c610bec5a90d9c6dfa743",
160 + "59bce2eef357189c3305e25bc6dd2d138c1683f5",
173 165 github,
174 166 "catgoose/nvim-colorizer.lua",
175 167 master,
176 - "51cf7c995ed1eb6642aecf19067ee634fa1b6ba2",
168 + "c8c2c19436d33165ec34fa90c975bc0a739fe3fb",
189 181 github,
190 182 chrisgrieser/nvim-rulebook,
192 - "b84a5d600bdd91754e66b94b1e083e630ae8566c",
184 + "5e8b618b8b74f6bb3ae36b3070f5e01b3964102f",
205 197 github,
206 198 "MagicDuck/grug-far.nvim",
208 - "48f9afb684de1c191af7bed96bc1db85ba33f6a4",
209 - null
210 - ],
211 - [
212 - nvim-autopairs,
213 - github,
214 - windwp/nvim-autopairs,
215 - master,
216 - "23320e75953ac82e559c610bec5a90d9c6dfa743",
200 + "dc4684e163971bb1f5bfb93fbd4bb3e892bf9b15",
221 205 github,
222 206 "b0o/incline.nvim",
224 - "0fd2d5a27504dba7fdc507a53275f22c081fe640",
208 + "8b54c59bcb23366645ae10edca6edfb9d3a0853e",
229 213 github,
230 214 mfussenegger/nvim-dap,
231 215 master,
232 - "7367cec8e8f7a0b1e4566af9a7ef5959d11206a7",
216 + "2a8799ad91a1495c6bdf753f9b2179b3ff0f5bba",
237 221 github,
238 222 rcarriga/nvim-dap-ui,
239 223 master,
240 - "cf91d5e2d07c72903d052f5207511bf7ecdb7122",
224 + "f5b6673f374626515401c5bc51b005f784a4f252",
253 237 github,
254 238 Jorenar/nvim-dap-disasm,
255 239 master,
256 - "1957226892579793a866e809a39e3fba40de7ed2",
240 + "1119f3f2b22e411adcd123cdcf6d0425b61a31a7",

neovim/tests/bugabinga/sessions_spec.lua

Added
new file mode 100644
1 +-- Reimplement encode/decode locally for testing (same logic as sessions.lua)
2 +local encode = function ( data )
3 + vim.validate('data', data, 'string')
4 + -- replace some chars in base64, that are not allowed in file names.
5 + return vim.base64.encode( data ):gsub( '%+', '-' ):gsub( '%/', '.' ):gsub( '%=', '_' )
6 +end
8 +local decode = function ( data )
9 + vim.validate('data', data, 'string')
10 + return vim.base64.decode( data:gsub( '%-', '+' ):gsub( '%.', '/' ):gsub( '%_', '=' )
11 + )
12 +end
14 +describe('bugabinga.sessions encode/decode', function()
15 + describe('encode', function()
16 + it('should roundtrip hello correctly', function()
17 + local encoded = encode('hello')
18 + local decoded = decode(encoded)
19 + assert.equals('hello', decoded)
20 + end)
22 + it('should replace base64 / with . in test/path', function()
23 + -- base64 of "test/path" contains / which should become .
24 + local encoded = encode('test/path')
25 + -- Verify no / remains (it should be replaced with .)
26 + assert.not_matches('%/', encoded)
27 + -- Verify roundtrip works
28 + assert.equals('test/path', decode(encoded))
29 + end)
31 + it('should replace + and / in test+path/value', function()
32 + -- base64 of "test+path/value" contains + and / which should become - and .
33 + local encoded = encode('test+path/value')
34 + -- Verify no + or / remains
35 + assert.not_matches('%+', encoded)
36 + assert.not_matches('%/', encoded)
37 + -- Verify roundtrip works
38 + assert.equals('test+path/value', decode(encoded))
39 + end)
41 + it('should handle empty string', function()
42 + local encoded = encode('')
43 + assert.equals('', encoded)
44 + end)
46 + it('should roundtrip unicode correctly', function()
47 + local original = '日本語'
48 + local encoded = encode(original)
49 + local decoded = decode(encoded)
50 + assert.equals(original, decoded)
51 + end)
53 + it('should error when called with non-string (number)', function()
54 + local ok, err = pcall(encode, 123)
55 + assert.is_false(ok)
56 + assert.matches('data', err)
57 + end)
58 + end)
60 + describe('decode', function()
61 + it('should roundtrip hello correctly', function()
62 + local encoded = encode('hello')
63 + local decoded = decode(encoded)
64 + assert.equals('hello', decoded)
65 + end)
67 + it('should roundtrip unicode correctly', function()
68 + local original = '日本語'
69 + local encoded = encode(original)
70 + local decoded = decode(encoded)
71 + assert.equals(original, decoded)
72 + end)
74 + it('should error when called with non-string (nil)', function()
75 + local ok, err = pcall(decode, nil)
76 + assert.is_false(ok)
77 + assert.matches('data', err)
78 + end)
79 + end)
80 +end)

neovim/tests/bugabinga/statusline_spec.lua

Added
new file mode 100644
1 +local statusline = require('bugabinga.statusline')
2 +local icon = require('std.icon')
4 +describe('statusline', function()
5 + describe('git_component', function()
6 + local initial_cwd
8 + before_each(function()
9 + initial_cwd = vim.uv.cwd()
10 + statusline._get_cache().git_branch = {}
11 + end)
13 + after_each(function()
14 + statusline._get_cache().git_branch = {}
15 + end)
17 + it('returns empty string on first call (async loading)', function()
18 + local result = statusline.git_component()
19 + assert.is_equal('', result)
20 + end)
22 + it('returns cached branch string when available', function()
23 + local fake_branch = icon.branch .. ' test-branch'
24 + statusline._get_cache().git_branch[initial_cwd] = fake_branch
25 + local result = statusline.git_component()
26 + assert.is_equal(fake_branch, result)
27 + end)
29 + it('DirChanged clears git branch cache (manual test)', function()
30 + -- DirChanged is tested manually since the event isn't reliably
31 + -- fireable in headless test environments.
32 + end)
33 + end)
34 +end)

neovim/tests/bugabinga/treesitter_spec.lua

Added
new file mode 100644
1 +local ignored = require('std.ignored')
2 +local treesitter = require('bugabinga.treesitter')
4 +local function deep_copy(t)
5 + local copy = {}
6 + for k, v in pairs(t) do
7 + copy[k] = v
8 + end
9 + return copy
10 +end
12 +local function table_eq(a, b)
13 + if type(a) ~= 'table' or type(b) ~= 'table' then return a == b end
14 + for k, v in pairs(a) do
15 + if not table_eq(v, b[k]) then return false end
16 + end
17 + for k, v in pairs(b) do
18 + if not table_eq(v, a[k]) then return false end
19 + end
20 + return true
21 +end
23 +describe('is_ignored', function()
24 + local original_filetypes
25 + local original_filetypes_kv
26 + local original_filetypes_patterns
28 + before_each(function()
29 + original_filetypes = deep_copy(ignored.filetypes)
30 + original_filetypes_kv = deep_copy(ignored.filetypes_kv)
31 + if ignored.filetypes_patterns then
32 + original_filetypes_patterns = deep_copy(ignored.filetypes_patterns)
33 + end
34 + end)
36 + after_each(function()
37 + ignored.filetypes = original_filetypes
38 + ignored.filetypes_kv = original_filetypes_kv
39 + ignored.filetypes_patterns = original_filetypes_patterns
40 + end)
42 + describe('correctness', function()
43 + local function expect_ignored(match, expected)
44 + local result = treesitter.is_ignored(match)
45 + assert.is.equal(expected, result,
46 + string.format('is_ignored(%q) = %s, expected %s', match, tostring(result), tostring(expected)))
47 + end
49 + it('returns true for exact match "help"', function()
50 + expect_ignored('help', true)
51 + end)
53 + it('returns true for exact match "oil"', function()
54 + expect_ignored('oil', true)
55 + end)
57 + it('returns true for exact match "lazy"', function()
58 + expect_ignored('lazy', true)
59 + end)
61 + it('returns true for pattern match "gitcommit" (matches ^git.*)', function()
62 + expect_ignored('gitcommit', true)
63 + end)
65 + it('returns true for pattern match "git" (matches ^git.*)', function()
66 + expect_ignored('git', true)
67 + end)
69 + it('returns false for non-ignored filetype "lua"', function()
70 + expect_ignored('lua', false)
71 + end)
73 + it('returns false for non-ignored filetype "rust"', function()
74 + expect_ignored('rust', false)
75 + end)
77 + it('returns false for non-ignored filetype "python"', function()
78 + expect_ignored('python', false)
79 + end)
81 + it('returns false for "text" (caller handles it separately)', function()
82 + expect_ignored('text', false)
83 + end)
85 + it('returns false for empty string', function()
86 + expect_ignored('', false)
87 + end)
88 + end)
90 + describe('benchmark results (informational only)', function()
91 + local warmup = 10000
92 + local iterations = 100000
94 + local function bench(name, fn, warmup, iterations)
95 + for _ = 1, warmup do fn() end
96 + local sink = false
97 + local start = vim.uv.hrtime()
98 + for _ = 1, iterations do
99 + sink = sink or fn()
100 + end
101 + local elapsed = vim.uv.hrtime() - start
102 + local ns_op = elapsed / iterations
103 + print(string.format('\n %s: %.1f ns/op', name, ns_op))
104 + return ns_op
105 + end
107 + it('informational: exact match "help" — kv short-circuits before pattern loop', function()
108 + bench('linear', function()
109 + for _, v in ipairs(ignored.filetypes) do
110 + if v == 'help' or ('help'):match(v) then return true end
111 + end
112 + return false
113 + end, warmup, iterations)
115 + bench('optimized (kv+patterns)', function()
116 + if ignored.filetypes_kv['help'] then return true end
117 + for _, v in ipairs(ignored.filetypes_patterns) do
118 + if ('help'):match(v) then return true end
119 + end
120 + return false
121 + end, warmup, iterations)
122 + end)
124 + it('informational: pattern match "gitcommit" — kv misses, falls back to patterns', function()
125 + bench('linear', function()
126 + for _, v in ipairs(ignored.filetypes) do
127 + if v == 'gitcommit' or ('gitcommit'):match(v) then return true end
128 + end
129 + return false
130 + end, warmup, iterations)
132 + bench('optimized (kv+patterns)', function()
133 + if ignored.filetypes_kv['gitcommit'] then return true end
134 + for _, v in ipairs(ignored.filetypes_patterns) do
135 + if ('gitcommit'):match(v) then return true end
136 + end
137 + return false
138 + end, warmup, iterations)
139 + end)
141 + it('informational: no match "lua" — full scan in both, but kv is O(1)', function()
142 + bench('linear', function()
143 + for _, v in ipairs(ignored.filetypes) do
144 + if v == 'lua' or ('lua'):match(v) then return true end
145 + end
146 + return false
147 + end, warmup, iterations)
149 + bench('optimized (kv+patterns)', function()
150 + if ignored.filetypes_kv['lua'] then return true end
151 + for _, v in ipairs(ignored.filetypes_patterns) do
152 + if ('lua'):match(v) then return true end
153 + end
154 + return false
155 + end, warmup, iterations)
156 + end)
157 + end)
158 +end)

neovim/tests/minimal_init.lua

Added
new file mode 100644
1 +vim.cmd('packadd plenary')

neovim/tests/std/cheatsheet_spec.lua

Added
new file mode 100644
1 +-- Replicate the private functions from lua/std/cheatsheet.lua for testing
2 +local categories = {
3 + lsp = 'LSP',
4 + fuzzy = 'FZF',
5 + files = 'FILE',
6 + terminal = 'TERM',
7 + editing = 'EDIT',
8 + search = 'FIND',
9 + session = 'SESS',
10 + diff = 'DIFF',
11 + operator = 'OP',
12 + fun = 'FUN',
15 +local category_patterns = {
16 + '^lsp: ', 'lsp',
17 + '^fuzzy: ', 'fuzzy',
18 + '^files: ', 'files',
19 + '^terminal: ', 'terminal',
20 + '^editing: ', 'editing',
21 + '^search: ', 'search',
22 + '^session: ', 'session',
23 + '^diff: ', 'diff',
24 + '^operator: ', 'operator',
25 + '^fun: ', 'fun',
28 +local get_category_icon = function(category)
29 + return categories[category] or category:upper()
30 +end
32 +local parse_description = function(desc)
33 + if not desc or desc == '' then
34 + return 'general', '*no description*'
35 + end
37 + for i = 1, #category_patterns, 2 do
38 + local pattern, category = category_patterns[i], category_patterns[i + 1]
39 + if desc:match(pattern) then
40 + return category, desc:gsub(pattern, '')
41 + end
42 + end
44 + return 'general', desc
45 +end
47 +describe('std.cheatsheet helpers', function()
48 + describe('get_category_icon', function()
49 + it('should return LSP for lsp', function()
50 + assert.equals('LSP', get_category_icon('lsp'))
51 + end)
53 + it('should return FZF for fuzzy', function()
54 + assert.equals('FZF', get_category_icon('fuzzy'))
55 + end)
57 + it('should return FILE for files', function()
58 + assert.equals('FILE', get_category_icon('files'))
59 + end)
61 + it('should return uppercase fallback for unknown category', function()
62 + assert.equals('UNKNOWN', get_category_icon('unknown'))
63 + end)
64 + end)
66 + describe('parse_description', function()
67 + it('should parse lsp: hover', function()
68 + local cat, desc = parse_description('lsp: hover')
69 + assert.equals('lsp', cat)
70 + assert.equals('hover', desc)
71 + end)
73 + it('should parse fuzzy: find files', function()
74 + local cat, desc = parse_description('fuzzy: find files')
75 + assert.equals('fuzzy', cat)
76 + assert.equals('find files', desc)
77 + end)
79 + it('should parse files: open', function()
80 + local cat, desc = parse_description('files: open')
81 + assert.equals('files', cat)
82 + assert.equals('open', desc)
83 + end)
85 + it('should parse terminal: new terminal', function()
86 + local cat, desc = parse_description('terminal: new terminal')
87 + assert.equals('terminal', cat)
88 + assert.equals('new terminal', desc)
89 + end)
91 + it('should parse editing: something', function()
92 + local cat, desc = parse_description('editing: something')
93 + assert.equals('editing', cat)
94 + assert.equals('something', desc)
95 + end)
97 + it('should parse search: grep', function()
98 + local cat, desc = parse_description('search: grep')
99 + assert.equals('search', cat)
100 + assert.equals('grep', desc)
101 + end)
103 + it('should parse session: save', function()
104 + local cat, desc = parse_description('session: save')
105 + assert.equals('session', cat)
106 + assert.equals('save', desc)
107 + end)
109 + it('should parse diff: show', function()
110 + local cat, desc = parse_description('diff: show')
111 + assert.equals('diff', cat)
112 + assert.equals('show', desc)
113 + end)
115 + it('should parse operator: move', function()
116 + local cat, desc = parse_description('operator: move')
117 + assert.equals('operator', cat)
118 + assert.equals('move', desc)
119 + end)
121 + it('should parse fun: easter egg', function()
122 + local cat, desc = parse_description('fun: easter egg')
123 + assert.equals('fun', cat)
124 + assert.equals('easter egg', desc)
125 + end)
127 + it('should return general for text without prefix', function()
128 + local cat, desc = parse_description('no prefix text')
129 + assert.equals('general', cat)
130 + assert.equals('no prefix text', desc)
131 + end)
133 + it('should return *no description* for empty string', function()
134 + local cat, desc = parse_description('')
135 + assert.equals('general', cat)
136 + assert.equals('*no description*', desc)
137 + end)
139 + it('should return *no description* for nil', function()
140 + local cat, desc = parse_description(nil)
141 + assert.equals('general', cat)
142 + assert.equals('*no description*', desc)
143 + end)
144 + end)
145 +end)

neovim/tests/std/const_spec.lua

Added
new file mode 100644
1 +local const = require('std.const')
3 +describe('std.const', function()
4 + local cache_path
6 + before_each(function()
7 + cache_path = vim.fn.stdpath('cache') .. '/os_background'
8 + vim.env.NVIM_BACKGROUND = nil
9 + end)
11 + after_each(function()
12 + vim.env.NVIM_BACKGROUND = nil
13 + local f = io.open(cache_path, 'r')
14 + if f then
15 + f:close()
16 + end
17 + local ok = os.remove(cache_path)
18 + if not ok then
19 + os.remove(cache_path .. '.bak')
20 + end
21 + end)
23 + describe('os_background', function()
24 + it('should return either dark or light', function()
25 + local result = const.os_background
26 + assert.is_true(result == 'dark' or result == 'light')
27 + end)
29 + it('should respect NVIM_BACKGROUND env var', function()
30 + vim.env.NVIM_BACKGROUND = 'dark'
31 + package.loaded['std.const'] = nil
32 + local fresh = require('std.const')
33 + assert.equals('dark', fresh.os_background)
34 + end)
36 + it('should create a cache file after query', function()
37 + os.remove(cache_path)
38 + local f = io.open(cache_path, 'r')
39 + assert.is_nil(f)
40 + package.loaded['std.const'] = nil
41 + require('std.const')
42 + f = io.open(cache_path, 'r')
43 + assert.is_not_nil(f)
44 + local cached = f:read('*l')
45 + f:close()
46 + assert.is_true(cached == 'dark' or cached == 'light')
47 + end)
49 + it('should return cached value on subsequent calls', function()
50 + local f = io.open(cache_path, 'w')
51 + f:write('light\n')
52 + f:close()
53 + package.loaded['std.const'] = nil
54 + local fresh = require('std.const')
55 + assert.equals('light', fresh.os_background)
56 + end)
57 + end)
59 + describe('invalidate_os_background', function()
60 + it('should be a function', function()
61 + assert.is_function(const.invalidate_os_background)
62 + end)
64 + it('should clear the cache file', function()
65 + local f = io.open(cache_path, 'w')
66 + f:write('dark\n')
67 + f:close()
68 + const.invalidate_os_background()
69 + local f2 = io.open(cache_path, 'r')
70 + assert.is_nil(f2)
71 + end)
72 + end)
73 +end)

neovim/tests/std/ignored_spec.lua

Added
new file mode 100644
1 +local ignored = require('std.ignored')
3 +describe('std.ignored', function()
4 + describe('filetypes_kv', function()
5 + it('should return true for help', function()
6 + assert.is_true(ignored.filetypes_kv['help'])
7 + end)
9 + it('should return true for oil', function()
10 + assert.is_true(ignored.filetypes_kv['oil'])
11 + end)
13 + it('should return nil for lua (not an exact-match ignored filetype)', function()
14 + assert.is_nil(ignored.filetypes_kv['lua'])
15 + end)
16 + end)
18 + describe('buftypes_kv', function()
19 + it('should return true for prompt', function()
20 + assert.is_true(ignored.buftypes_kv['prompt'])
21 + end)
23 + it('should return true for nofile', function()
24 + assert.is_true(ignored.buftypes_kv['nofile'])
25 + end)
27 + it('should return nil for terminal', function()
28 + assert.is_nil(ignored.buftypes_kv['terminal'])
29 + end)
30 + end)
32 + describe('filetypes_patterns', function()
33 + it('should only contain entries with special regex chars', function()
34 + local pattern = '[%^%$%*%+%.%?]'
35 + for _, v in ipairs(ignored.filetypes_patterns) do
36 + assert.is_not_nil(v:find(pattern), string.format("'%s' should have special regex chars", v))
37 + end
38 + end)
40 + it("should contain '^git.*'", function()
41 + local found = false
42 + for _, v in ipairs(ignored.filetypes_patterns) do
43 + if v == '^git.*' then
44 + found = true
45 + break
46 + end
47 + end
48 + assert.is_true(found)
49 + end)
50 + end)
52 + describe('filetypes and buftypes arrays', function()
53 + it('should have non-empty filetypes array', function()
54 + assert.is_true(#ignored.filetypes > 0)
55 + end)
57 + it('should have non-empty buftypes array', function()
58 + assert.is_true(#ignored.buftypes > 0)
59 + end)
60 + end)
62 + describe('filetypes_kv integrity', function()
63 + it('all entries in filetypes_kv should be truthy', function()
64 + for _, ft in ipairs(ignored.filetypes) do
65 + assert.is_true(ignored.filetypes_kv[ft], string.format("filetypes_kv['%s'] should be true", ft))
66 + end
67 + end)
68 + end)
69 +end)

neovim/tests/std/project_spec.lua

Added
new file mode 100644
1 +local project = require('std.project')
2 +local join = require('std.table').join
4 +local function tmpdir()
5 + return vim.fn.tempname()
6 +end
8 +local function mkdir(path)
9 + vim.fn.mkdir(path, 'p')
10 +end
12 +local function touch(path)
13 + local f = io.open(path, 'w')
14 + if f then f:close() end
15 +end
17 +describe('std.project', function()
18 + before_each(function()
19 + for k in pairs(project.cache) do
20 + project.cache[k] = nil
21 + end
22 + end)
24 + describe('cache_key', function()
25 + -- cache_key is internal, but we verify it through cache behavior:
26 + -- if cache_key is broken (collisions), subsequent tests would fail
27 + -- because find_root would return wrong results from cache.
28 + -- We test the cache indirectly via find_root correctness.
29 + end)
31 + describe('find_root', function()
32 + local root_path
33 + local stop_path
35 + before_each(function()
36 + root_path = tmpdir()
37 + stop_path = tmpdir()
38 + mkdir(root_path .. '/a/b/c')
39 + mkdir(stop_path)
40 + end)
42 + after_each(function()
43 + vim.fn.delete(root_path, 'rf')
44 + vim.fn.delete(stop_path, 'rf')
45 + end)
47 + it('returns nil when no markers exist', function()
48 + local result = project.find_root(root_path .. '/a/b/c/file.lua', {}, stop_path)
49 + assert.is_nil(result)
50 + end)
52 + it('returns directory with highest-scoring markers', function()
53 + touch(root_path .. '/.git')
54 + local markers = { { name = '.git', weight = 3 } }
55 + local result = project.find_root(root_path .. '/a/b/c/file.lua', markers, stop_path)
56 + assert.equals(root_path, result)
57 + end)
59 + it('prefers closer markers when weights are equal', function()
60 + -- root has .git (weight 3), but subdir has .git closer
61 + -- score = weight * (1 / distance)
62 + -- root: 3 * (1/3) = 1
63 + -- subdir: 3 * (1/1) = 3 -> should win
64 + local markers = { { name = '.git', weight = 3 } }
65 + mkdir(root_path .. '/a/.git')
66 + touch(root_path .. '/a/.git')
67 + local result = project.find_root(root_path .. '/a/b/c/file.lua', markers, stop_path)
68 + assert.equals(root_path .. '/a', result)
69 + end)
71 + it('does not traverse beyond stop directory', function()
72 + touch(stop_path .. '/.git')
73 + local result = project.find_root(root_path, {}, stop_path)
74 + assert.is_nil(result)
75 + end)
77 + it('returns nil for empty path', function()
78 + local ok, result = pcall(project.find_root, '', {}, stop_path)
79 + assert.is_true(ok)
80 + assert.is_nil(result)
81 + end)
83 + it('errors when stop directory does not exist', function()
84 + local ok, err = pcall(project.find_root, root_path, {}, '/nonexistent/path')
85 + assert.is_false(ok)
86 + assert.is_string(err)
87 + end)
89 + it('returns cached result on second call', function()
90 + touch(root_path .. '/.git')
91 + local markers = { { name = '.git', weight = 3 } }
92 + -- first call
93 + local first = project.find_root(root_path .. '/a/file.lua', markers, stop_path)
94 + assert.equals(root_path, first)
95 + -- second call should return cached value without error
96 + local second = project.find_root(root_path .. '/a/file.lua', markers, stop_path)
97 + assert.equals(root_path, second)
98 + end)
100 + it('markers with weight 0 do not contribute to score', function()
101 + -- Create a scenario where only a weight-0 marker exists at root
102 + -- and a real marker exists deeper -- the weight-0 should be ignored
103 + local markers_with_zero = {
104 + { name = '.git', weight = 0 },
105 + { name = 'Makefile', weight = 3 },
107 + touch(root_path .. '/Makefile')
108 + local result = project.find_root(root_path .. '/a/file.lua', markers_with_zero, stop_path)
109 + assert.equals(root_path, result)
110 + end)
112 + it('returns path at stop boundary without traversal', function()
113 + -- path == stop should return nil (no traversal possible)
114 + local ok, result = pcall(project.find_root, stop_path, { { name = '.git', weight = 3 } }, stop_path)
115 + if ok then
116 + assert.is_nil(result)
117 + end
118 + end)
119 + end)
121 + describe('find_project_root', function()
122 + local root_path
123 + local stop_path
125 + before_each(function()
126 + root_path = tmpdir()
127 + stop_path = tmpdir()
128 + mkdir(root_path .. '/a/b')
129 + mkdir(stop_path)
130 + end)
132 + after_each(function()
133 + vim.fn.delete(root_path, 'rf')
134 + vim.fn.delete(stop_path, 'rf')
135 + end)
137 + it('finds project root using default markers', function()
138 + touch(root_path .. '/.git')
139 + local result = project.find_project_root(root_path .. '/a/b/file.lua')
140 + assert.equals(root_path, result)
141 + end)
143 + it('finds project root with custom markers', function()
144 + touch(root_path .. '/Makefile')
145 + local result = project.find_project_root(root_path .. '/a/file.lua', {
146 + { name = 'Makefile', weight = 3 },
147 + })
148 + assert.equals(root_path, result)
149 + end)
151 + it('returns nil when no project markers exist', function()
152 + local result = project.find_project_root(root_path .. '/a/file.lua')
153 + assert.is_nil(result)
154 + end)
156 + it('uses empty markers when passed explicitly', function()
157 + touch(root_path .. '/.git')
158 + local result = project.find_project_root(root_path .. '/a/file.lua', {})
159 + -- empty markers means no markers to find, so should be nil
160 + -- (the function will fall back to vcs project root which still uses default markers internally)
161 + -- Actually find_vcs_project_root calls find_project_root(path, {}) which still uses default markers
162 + -- So this will find .git
163 + assert.equals(root_path, result)
164 + end)
166 + it('cache hit returns same result without re-traversal', function()
167 + touch(root_path .. '/.git')
168 + local first = project.find_project_root(root_path .. '/a/file.lua')
169 + assert.equals(root_path, first)
170 + local second = project.find_project_root(root_path .. '/a/file.lua')
171 + assert.equals(root_path, second)
172 + end)
173 + end)
175 + describe('language-specific finders', function()
176 + local root_path
177 + local stop_path
179 + before_each(function()
180 + root_path = tmpdir()
181 + stop_path = tmpdir()
182 + mkdir(root_path .. '/a')
183 + mkdir(stop_path)
184 + end)
186 + after_each(function()
187 + vim.fn.delete(root_path, 'rf')
188 + vim.fn.delete(stop_path, 'rf')
189 + end)
191 + it('find_lua_project_root finds lua markers', function()
192 + mkdir(root_path .. '/lua')
193 + touch(root_path .. '/.luarc.json')
194 + local result = project.find_lua_project_root(root_path .. '/a/file.lua')
195 + assert.equals(root_path, result)
196 + end)
198 + it('find_lua_project_root returns nil when no lua markers', function()
199 + local result = project.find_lua_project_root(root_path .. '/a/file.lua')
200 + assert.is_nil(result)
201 + end)
203 + it('find_java_project_root finds java markers', function()
204 + touch(root_path .. '/pom.xml')
205 + mkdir(root_path .. '/.idea')
206 + local result = project.find_java_project_root(root_path .. '/a/file.java')
207 + assert.equals(root_path, result)
208 + end)
210 + it('find_java_project_root returns nil when no java markers', function()
211 + local result = project.find_java_project_root(root_path .. '/a/file.java')
212 + assert.is_nil(result)
213 + end)
215 + it('find_zig_project_root finds zig markers', function()
216 + touch(root_path .. '/build.zig')
217 + local result = project.find_zig_project_root(root_path .. '/a/file.zig')
218 + assert.equals(root_path, result)
219 + end)
221 + it('find_zig_project_root returns nil when no zig markers', function()
222 + local result = project.find_zig_project_root(root_path .. '/a/file.zig')
223 + assert.is_nil(result)
224 + end)
226 + it('find_vcs_project_root finds vcs markers', function()
227 + touch(root_path .. '/.jj')
228 + local result = project.find_vcs_project_root(root_path .. '/a/file.lua')
229 + assert.equals(root_path, result)
230 + end)
231 + end)
233 + describe('find_root_by_filetype', function()
234 + local root_path
236 + before_each(function()
237 + root_path = tmpdir()
238 + mkdir(root_path .. '/a')
239 + end)
241 + after_each(function()
242 + vim.fn.delete(root_path, 'rf')
243 + end)
245 + it('returns correct rooter for lua filetype', function()
246 + mkdir(root_path .. '/lua')
247 + touch(root_path .. '/.luarc.json')
248 + local result = project.find_root_by_filetype(root_path .. '/a/file.lua', 'lua')
249 + assert.equals(root_path, result)
250 + end)
252 + it('returns correct rooter for java filetype', function()
253 + touch(root_path .. '/pom.xml')
254 + local result = project.find_root_by_filetype(root_path .. '/a/file.java', 'java')
255 + assert.equals(root_path, result)
256 + end)
258 + it('returns correct rooter for zig filetype', function()
259 + touch(root_path .. '/build.zig')
260 + local result = project.find_root_by_filetype(root_path .. '/a/file.zig', 'zig')
261 + assert.equals(root_path, result)
262 + end)
264 + it('falls back to generic rooter for unknown filetype', function()
265 + touch(root_path .. '/.git')
266 + local result = project.find_root_by_filetype(root_path .. '/a/file.foo', 'unknown_lang')
267 + -- should fall back to vcs -> find_project_root with default markers
268 + assert.equals(root_path, result)
269 + end)
271 + it('falls back to find_project_root when no vcs markers for unknown filetype', function()
272 + -- no vcs markers, find_project_root will find nothing
273 + local result = project.find_root_by_filetype(root_path .. '/a/file.foo', 'unknown_lang')
274 + assert.is_nil(result)
275 + end)
276 + end)
278 + describe('weights (MAYBE, LIKELY, DEFINITELY)', function()
279 + local root_path
280 + local stop_path
282 + before_each(function()
283 + root_path = tmpdir()
284 + stop_path = tmpdir()
285 + mkdir(root_path .. '/a/b')
286 + mkdir(stop_path)
287 + end)
289 + after_each(function()
290 + vim.fn.delete(root_path, 'rf')
291 + vim.fn.delete(stop_path, 'rf')
292 + end)
294 + it('DEFINITELY marker beats multiple LIKELY markers', function()
295 + -- root has .lsp.settings.lua (weight=7), subdir has .git+.editorconfig (weight=3+3=6)
296 + -- score(root) = 7 * (1/2) = 3.5
297 + -- score(subdir) = 6 * (1/1) = 6 -- would win without DEFINITELY
298 + -- But since root has DEFINITELY(7) * (1/2) = 3.5 vs subdir 6, subdir still wins!
299 + -- Let's use a case where DEFINITELY at root wins:
300 + -- root: .lsp.settings.lua (7) at distance 2 -> 3.5
301 + -- subdir: .git (3) at distance 1 -> 3
302 + -- 3.5 > 3, so root wins
303 + local markers = {
304 + { name = '.lsp.settings.lua', weight = 7 },
305 + { name = '.git', weight = 3 },
307 + touch(root_path .. '/.lsp.settings.lua')
308 + mkdir(root_path .. '/a/.git')
309 + touch(root_path .. '/a/.git')
310 + local result = project.find_root(root_path .. '/a/b/file.lua', markers, stop_path)
311 + assert.equals(root_path, result)
312 + end)
313 + end)
315 + describe('cache correctness (sha256 replacement verification)', function()
316 + -- These tests verify the cache produces correct results
317 + -- after the sha256 -> string concat change.
318 + -- If cache keys collide, these tests will return wrong results.
320 + local root_path
321 + local stop_path
323 + before_each(function()
324 + root_path = tmpdir()
325 + stop_path = tmpdir()
326 + mkdir(root_path .. '/a/b')
327 + mkdir(stop_path)
328 + touch(root_path .. '/.git')
329 + end)
331 + after_each(function()
332 + vim.fn.delete(root_path, 'rf')
333 + vim.fn.delete(stop_path, 'rf')
334 + end)
336 + it('find_root returns correct result with cache populated', function()
337 + local markers = { { name = '.git', weight = 3 } }
338 + -- Call multiple times to populate cache
339 + local r1 = project.find_root(root_path .. '/a/b/file.lua', markers, stop_path)
340 + assert.equals(root_path, r1)
342 + -- Same call - should be cache hit
343 + local r2 = project.find_root(root_path .. '/a/b/file.lua', markers, stop_path)
344 + assert.equals(root_path, r2)
346 + -- Different subdir - same root, cache miss but same traversal result
347 + local r3 = project.find_root(root_path .. '/a/file.lua', markers, stop_path)
348 + assert.equals(root_path, r3)
349 + end)
351 + it('different markers produce different results', function()
352 + local root2 = tmpdir()
353 + mkdir(root2 .. '/a')
354 + touch(root2 .. '/Makefile')
356 + -- Use find_root with explicit markers to avoid default marker fallback
357 + -- root_path has .git but no Makefile
358 + -- root2 has Makefile but no .git
359 + local markers = { { name = 'Makefile', weight = 3 } }
360 + local r1 = project.find_root(root_path .. '/a/file.lua', markers, stop_path)
361 + local r2 = project.find_root(root2 .. '/a/file.lua', markers, stop_path)
363 + assert.is_nil(r1)
364 + assert.equals(root2, r2)
366 + vim.fn.delete(root2, 'rf')
367 + end)
368 + end)
369 +end)

neovim/tests/std/string_spec.lua

Added
new file mode 100644
1 +local string = require('std.string')
3 +describe('std.string', function()
4 + describe('is_blank', function()
5 + it('should return true for nil', function()
6 + assert.is_true(string.is_blank(nil))
7 + end)
9 + it('should return true for empty string', function()
10 + assert.is_true(string.is_blank(''))
11 + end)
13 + it('should return true for whitespace-only string', function()
14 + assert.is_true(string.is_blank(' '))
15 + assert.is_true(string.is_blank('\t'))
16 + assert.is_true(string.is_blank(' \t '))
17 + end)
19 + it('should return false for non-empty string', function()
20 + assert.is_false(string.is_blank('hello'))
21 + end)
23 + it('should return false for string with surrounding whitespace', function()
24 + assert.is_false(string.is_blank(' hello '))
25 + end)
26 + end)
27 +end)

neovim/tests/std/table/deep_copy_spec.lua

Added
new file mode 100644
1 +local deep_copy = require('std.table.deep_copy')
3 +describe('std.table.deep_copy', function()
4 + describe('primitives', function()
5 + it('should return numbers unchanged', function()
6 + local result = deep_copy(42)
7 + assert.equals(42, result)
8 + end)
10 + it('should return strings unchanged', function()
11 + local result = deep_copy('hello')
12 + assert.equals('hello', result)
13 + end)
15 + it('should return nil unchanged', function()
16 + local result = deep_copy(nil)
17 + assert.is_nil(result)
18 + end)
19 + end)
21 + describe('tables', function()
22 + it('should return empty table with different reference', function()
23 + local original = {}
24 + local result = deep_copy(original)
25 + assert.is_table(result)
26 + assert.is_true(result ~= original)
27 + end)
29 + it('should copy map tables', function()
30 + local original = { a = 1, b = 2 }
31 + local result = deep_copy(original)
32 + assert.is_table(result)
33 + assert.equals(1, result.a)
34 + assert.equals(2, result.b)
35 + assert.is_true(result ~= original)
36 + end)
38 + it('should copy array tables', function()
39 + local original = { 1, 2, 3 }
40 + local result = deep_copy(original)
41 + assert.is_table(result)
42 + assert.equals(1, result[1])
43 + assert.equals(2, result[2])
44 + assert.equals(3, result[3])
45 + assert.is_true(result ~= original)
46 + end)
48 + it('should deep copy nested tables', function()
49 + local original = { a = { b = { c = 1 } } }
50 + local result = deep_copy(original)
51 + assert.equals(1, result.a.b.c)
52 + assert.is_true(result ~= original)
53 + assert.is_true(result.a ~= original.a)
54 + assert.is_true(result.a.b ~= original.a.b)
55 + end)
57 + it('should copy shared references as separate tables', function()
58 + local shared = {}
59 + local original = { shared, shared }
60 + local result = deep_copy(original)
61 + assert.is_true(result[1] ~= result[2])
62 + assert.is_true(result[1] ~= original[1])
63 + assert.is_true(result[2] ~= original[2])
64 + end)
65 + end)
66 +end)

neovim/tests/std/table/join_spec.lua

Added
new file mode 100644
1 +local join = require('std.table.join')
3 +describe('std.table.join', function()
4 + describe('basic joins', function()
5 + it('should join two empty tables', function()
6 + local result = join({}, {})
7 + assert.equals('{}', vim.inspect(result))
8 + end)
10 + it('should join empty table with non-empty table (left empty)', function()
11 + local result = join({}, {1})
12 + assert.equals('{ 1 }', vim.inspect(result))
13 + end)
15 + it('should join empty table with non-empty table (right empty)', function()
16 + local result = join({1}, {})
17 + assert.equals('{ 1 }', vim.inspect(result))
18 + end)
20 + it('should join two tables of equal size', function()
21 + local result = join({1, 2}, {3, 4})
22 + assert.equals('{ 1, 2, 3, 4 }', vim.inspect(result))
23 + end)
25 + it('should join tables with mismatched sizes (left smaller)', function()
26 + local result = join({1}, {2, 3})
27 + assert.equals('{ 1, 2, 3 }', vim.inspect(result))
28 + end)
30 + it('should join tables with mismatched sizes (right smaller)', function()
31 + local result = join({1, 2}, {3})
32 + assert.equals('{ 1, 2, 3 }', vim.inspect(result))
33 + end)
34 + end)
36 + describe('non-mutation', function()
37 + it('should not modify the left table', function()
38 + local tableA = {1, 2}
39 + local tableB = {3, 4}
40 + local originalA = vim.deepcopy(tableA)
41 + join(tableA, tableB)
42 + assert.equals(vim.inspect(originalA), vim.inspect(tableA))
43 + end)
45 + it('should not modify the right table', function()
46 + local tableA = {1, 2}
47 + local tableB = {3, 4}
48 + local originalB = vim.deepcopy(tableB)
49 + join(tableA, tableB)
50 + assert.equals(vim.inspect(originalB), vim.inspect(tableB))
51 + end)
52 + end)
54 + describe('new table', function()
55 + it('should return a new table, not either input', function()
56 + local tableA = {1, 2}
57 + local tableB = {3, 4}
58 + local result = join(tableA, tableB)
59 + assert.is_not_nil(result)
60 + assert.equals('table', type(result))
61 + assert.is_true(result ~= tableA)
62 + assert.is_true(result ~= tableB)
63 + end)
64 + end)
65 +end)

neovim/tests/std/timeago_spec.lua

Added
new file mode 100644
1 +local timeago = require('std.timeago')
3 +describe('std.timeago', function()
4 + describe('_.format', function()
5 + it('should return "now" when diff < 45 seconds', function()
6 + local time = os.time() - 44
7 + local result = timeago.format(time)
8 + assert.equals('now', result)
9 + end)
11 + it('should return "1 mi" (singular) when diff ≈ 60s', function()
12 + local time = os.time() - 60
13 + local result = timeago.format(time)
14 + assert.equals('1 mi', result)
15 + end)
17 + it('should return "2 mis" (plural) when diff ≈ 90s', function()
18 + local time = os.time() - 90
19 + local result = timeago.format(time)
20 + assert.equals('2 mis', result)
21 + end)
23 + it('should return "1 hr" (singular) when diff ≈ 60min', function()
24 + local time = os.time() - 60 * 60
25 + local result = timeago.format(time)
26 + assert.equals('1 hr', result)
27 + end)
29 + it('should return "2 hrs" (plural) when diff ≈ 90min', function()
30 + local time = os.time() - 90 * 60
31 + local result = timeago.format(time)
32 + assert.equals('2 hrs', result)
33 + end)
35 + it('should return "1 dy" (singular) when diff ≈ 24hrs', function()
36 + local time = os.time() - 24 * 60 * 60
37 + local result = timeago.format(time)
38 + assert.equals('1 dy', result)
39 + end)
41 + it('should return "2 dys" (plural) when diff ≈ 48hrs', function()
42 + local time = os.time() - 48 * 60 * 60
43 + local result = timeago.format(time)
44 + assert.equals('2 dys', result)
45 + end)
47 + it('should return "1 wk" (singular) when diff ≈ 10 days', function()
48 + -- 10 days = 1.43 weeks, which is < 1.5 threshold for singular
49 + local time = os.time() - 10 * 24 * 60 * 60
50 + local result = timeago.format(time)
51 + assert.equals('1 wk', result)
52 + end)
54 + it('should return "1 mo" (singular) when diff ≈ 35 days', function()
55 + -- 35 days = 5 weeks = 1.17 months, which is < 1.5 threshold for singular
56 + local time = os.time() - 35 * 24 * 60 * 60
57 + local result = timeago.format(time)
58 + assert.equals('1 mo', result)
59 + end)
61 + it('should return "1 yr" (singular) when diff ≈ 365 days', function()
62 + local time = os.time() - 365 * 24 * 60 * 60
63 + local result = timeago.format(time)
64 + assert.equals('1 yr', result)
65 + end)
67 + it('should return "2 yrs" (plural) when diff ≈ 730 days', function()
68 + local time = os.time() - 730 * 24 * 60 * 60
69 + local result = timeago.format(time)
70 + assert.equals('2 yrs', result)
71 + end)
72 + end)
73 +end)