From dd13c34c9258ff06286ed94ccca82598014fb5f1 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 19 Feb 2026 14:52:17 -0500 Subject: [PATCH] feat(nvim): more completion configs --- config/nvim/after/plugin/lsp.lua | 8 -- config/nvim/lazy-lock.json | 1 - config/nvim/lua/config/blink/init.lua | 107 +++++++++++++++++++++++++ config/nvim/lua/config/cmp_cc.lua | 82 ------------------- config/nvim/lua/plugins/blink.lua | 26 ++++-- config/nvim/lua/plugins/guard.lua | 2 +- config/nvim/lua/plugins/treesitter.lua | 78 ++++++++---------- 7 files changed, 161 insertions(+), 143 deletions(-) create mode 100644 config/nvim/lua/config/blink/init.lua delete mode 100644 config/nvim/lua/config/cmp_cc.lua diff --git a/config/nvim/after/plugin/lsp.lua b/config/nvim/after/plugin/lsp.lua index 0409c05..55dabdf 100644 --- a/config/nvim/after/plugin/lsp.lua +++ b/config/nvim/after/plugin/lsp.lua @@ -27,14 +27,6 @@ vim.lsp.config('*', { flags = { debounce_text_changes = 0 }, }) -map({ - { 'n', 'x' }, - 'gF', - function() - vim.lsp.buf.format({ async = true }) - end, -}) - for _, server in ipairs({ 'bashls', 'basedpyright', diff --git a/config/nvim/lazy-lock.json b/config/nvim/lazy-lock.json index 08d037f..a516ec8 100644 --- a/config/nvim/lazy-lock.json +++ b/config/nvim/lazy-lock.json @@ -2,7 +2,6 @@ "blink-cmp-env": { "branch": "main", "commit": "99af62c1f9aa46005e8f50ad4ccee581946546ca" }, "blink-cmp-git": { "branch": "master", "commit": "e3ad0ffaaa3b3b7e2158cc72cd6dad2d19842c46" }, "blink-cmp-sshconfig": { "branch": "main", "commit": "91bf9bd80d53d2b6521cffb01da138ef6403d625" }, - "blink-cmp-tmux": { "branch": "main", "commit": "1ef35d8e388475ab8eaeecfc12e196c78bd5de04" }, "blink.cmp": { "branch": "main", "commit": "4b18c32adef2898f95cdef6192cbd5796c1a332d" }, "dial.nvim": { "branch": "master", "commit": "f2634758455cfa52a8acea6f142dcd6271a1bf57" }, "fzf-lua": { "branch": "main", "commit": "b2c0603216adb92c6bba81053bc996d7ae95b77a" }, diff --git a/config/nvim/lua/config/blink/init.lua b/config/nvim/lua/config/blink/init.lua new file mode 100644 index 0000000..29c225a --- /dev/null +++ b/config/nvim/lua/config/blink/init.lua @@ -0,0 +1,107 @@ +local M = {} + +local function make_source(def) + local src = {} + + function src.new() + local self = setmetatable({}, { __index = src }) + local Kind = require('blink.cmp.types').CompletionItemKind + self.Kind = Kind + self.items = def.items(Kind) + return self + end + + src.enabled = def.enabled + src.get_completions = def.get_completions + or function(self, _, callback) + callback({ + is_incomplete_forward = false, + is_incomplete_backward = false, + items = vim.deepcopy(self.items), + }) + end + + return src +end + +M.conventional_commits = make_source({ + enabled = function() + return vim.tbl_contains( + { 'gitcommit', 'octo', 'markdown' }, + vim.bo.filetype + ) + end, + items = function(Kind) + local types = { + { 'feat', 'A new feature (MINOR in semver)' }, + { 'fix', 'A bug fix (PATCH in semver)' }, + { 'docs', 'Documentation only' }, + { 'style', 'Formatting, whitespace — no behavioral change' }, + { 'refactor', 'Restructures code without changing behavior' }, + { 'perf', 'Performance improvement' }, + { 'test', 'Add or correct tests' }, + { 'build', 'Build system or external dependencies' }, + { 'ci', 'CI/CD configuration and scripts' }, + { 'chore', 'Routine tasks outside src and test' }, + { 'revert', 'Reverts a previous commit' }, + } + local out = {} + for _, t in ipairs(types) do + out[#out + 1] = { + label = t[1], + kind = Kind.Keyword, + documentation = { kind = 'markdown', value = t[2] }, + } + end + return out + end, + get_completions = function(self, ctx, callback) + local row, col = unpack(ctx.cursor) + local before = ctx.line:sub(1, col) + + if not before:find('%s') then + if row > 1 then + local item = { + label = 'BREAKING CHANGE', + kind = self.Kind.Keyword, + documentation = { + kind = 'markdown', + value = 'Adds a `BREAKING CHANGE` footer and marks the commit header with `!`.', + }, + } + local first = vim.api.nvim_buf_get_lines(0, 0, 1, false)[1] + if not first:match('!:') then + local colon = first:find(':') + if colon then + item.additionalTextEdits = { + { + range = { + start = { line = 0, character = colon - 1 }, + ['end'] = { line = 0, character = colon - 1 }, + }, + newText = '!', + }, + } + end + end + callback({ items = { item } }) + return + elseif not before:find('[():]') then + callback({ + is_incomplete_forward = false, + is_incomplete_backward = false, + items = vim.deepcopy(self.items), + }) + return + end + end + + callback({ items = {} }) + end, +}) + +for name, src in pairs(M) do + package.loaded['config.blink.' .. name] = src +end + +return M diff --git a/config/nvim/lua/config/cmp_cc.lua b/config/nvim/lua/config/cmp_cc.lua deleted file mode 100644 index 147d025..0000000 --- a/config/nvim/lua/config/cmp_cc.lua +++ /dev/null @@ -1,82 +0,0 @@ -local types = { - { 'feat', 'A new feature (MINOR in semver)' }, - { 'fix', 'A bug fix (PATCH in semver)' }, - { 'docs', 'Documentation only' }, - { 'style', 'Formatting, whitespace — no behavioral change' }, - { 'refactor', 'Restructures code without changing behavior' }, - { 'perf', 'Performance improvement' }, - { 'test', 'Add or correct tests' }, - { 'build', 'Build system or external dependencies' }, - { 'ci', 'CI/CD configuration and scripts' }, - { 'chore', 'Routine tasks outside src and test' }, - { 'revert', 'Reverts a previous commit' }, -} - -local source = {} - -function source.new() - local self = setmetatable({}, { __index = source }) - self.Kind = require('blink.cmp.types').CompletionItemKind - self.items = {} - for _, t in ipairs(types) do - self.items[#self.items + 1] = { - label = t[1], - kind = self.Kind.Keyword, - documentation = { - kind = 'markdown', - value = t[2] - }, - } - end - return self -end - -function source:enabled() - return vim.tbl_contains({ 'gitcommit', 'octo', 'markdown' }, vim.bo.filetype) -end - -function source:get_completions(ctx, callback) - local row, col = unpack(ctx.cursor) - local before = ctx.line:sub(1, col) - - if not before:find('%s') then - if row > 1 then - local item = { - label = 'BREAKING CHANGE', - kind = self.Kind.Keyword, - documentation = { - kind = 'markdown', - value = 'Adds a `BREAKING CHANGE` footer and marks the commit header with `!`.', - }, - } - local first = vim.api.nvim_buf_get_lines(0, 0, 1, false)[1] - if not first:match('!:') then - local colon = first:find(':') - if colon then - item.additionalTextEdits = { - { - range = { - start = { line = 0, character = colon - 1 }, - ['end'] = { line = 0, character = colon - 1 }, - }, - newText = '!', - }, - } - end - end - callback({ items = { item } }) - return - elseif not before:find('[():]') then - callback({ - is_incomplete_forward = false, - is_incomplete_backward = false, - items = vim.deepcopy(self.items), - }) - return - end - end - - callback({ items = {} }) -end - -return source diff --git a/config/nvim/lua/plugins/blink.lua b/config/nvim/lua/plugins/blink.lua index 36d2d64..d906888 100644 --- a/config/nvim/lua/plugins/blink.lua +++ b/config/nvim/lua/plugins/blink.lua @@ -14,6 +14,7 @@ return { vim.o.pumheight = 15 opts.completion.menu.max_height = vim.o.pumheight + require('config.blink') require('blink.cmp').setup(opts) end, opts = { @@ -47,8 +48,19 @@ return { draw = { treesitter = { 'lsp', 'snippets', 'buffer' }, columns = { - { 'kind_icon' }, { 'label', 'label_description', gap = 1 }, + { 'kind' }, + }, + components = { + kind = { + ellipsis = false, + text = function(ctx) + return '[' .. ctx.kind .. ']' + end, + highlight = function(ctx) + return ctx.kind_hl + end, + }, }, }, }, @@ -68,16 +80,20 @@ return { 'buffer', 'env', 'snippets', - -- 'sshconfig', + 'sshconfig', }, providers = { git = { module = 'blink-cmp-git', name = 'Git', }, + sshconfig = { + name = 'SshConfig', + module = 'blink-cmp-sshconfig', + }, conventional_commits = { name = 'Conventional Commits', - module = 'config.cmp_cc', + module = 'config.blink.conventional_commits', }, lazydev = { name = 'LazyDev', @@ -88,10 +104,6 @@ return { name = 'Env', module = 'blink-cmp-env', }, - -- sshconfig = { - -- name = 'SshConfig', - -- module = 'blink-cmp-sshconfig', - -- }, }, }, }, diff --git a/config/nvim/lua/plugins/guard.lua b/config/nvim/lua/plugins/guard.lua index df1018b..944e020 100644 --- a/config/nvim/lua/plugins/guard.lua +++ b/config/nvim/lua/plugins/guard.lua @@ -11,7 +11,7 @@ return { } end, keys = { - { 'gF', 'Guard fmt', mode = { 'n', 'x' } }, + { 'gF', 'Guard fmt', mode = { 'n', 'x' } }, }, config = function() local ft = require('guard.filetype') diff --git a/config/nvim/lua/plugins/treesitter.lua b/config/nvim/lua/plugins/treesitter.lua index 75b2c2b..17a09a4 100644 --- a/config/nvim/lua/plugins/treesitter.lua +++ b/config/nvim/lua/plugins/treesitter.lua @@ -3,30 +3,6 @@ return { 'nvim-treesitter/nvim-treesitter', branch = 'main', build = ':TSUpdate all', - init = function() - vim.api.nvim_create_autocmd('FileType', { - pattern = '*', - callback = function() - local bufnr = vim.api.nvim_get_current_buf() - local lines = vim.api.nvim_buf_line_count(bufnr) - - if lines < 5000 then - pcall(vim.treesitter.start) - else - vim.notify_once( - ('Skipping tree-sitter for bufnr %s; file too large (%s >= 5000 lines)'):format( - bufnr, - lines - ) - ) - end - end, - group = vim.api.nvim_create_augroup( - 'ATreeSitter', - { clear = true } - ), - }) - end, opts = { auto_install = true, }, @@ -79,33 +55,47 @@ return { end local move = require('nvim-treesitter-textobjects.move') - local move_maps = { - { ']a', 'goto_next_start', '@parameter.inner' }, - { ']s', 'goto_next_start', '@class.outer' }, - { ']f', 'goto_next_start', '@function.outer' }, - { ']i', 'goto_next_start', '@conditional.outer' }, - { ']/', 'goto_next_start', '@comment.outer' }, - { ']A', 'goto_next_end', '@parameter.inner' }, - { ']F', 'goto_next_end', '@function.outer' }, - { ']I', 'goto_next_end', '@conditional.outer' }, - { '[a', 'goto_previous_start', '@parameter.inner' }, - { '[s', 'goto_previous_start', '@class.outer' }, - { '[f', 'goto_previous_start', '@function.outer' }, - { '[i', 'goto_previous_start', '@conditional.outer' }, - { '[/', 'goto_previous_start', '@comment.outer' }, - { '[A', 'goto_previous_end', '@parameter.inner' }, - { '[F', 'goto_previous_end', '@function.outer' }, - { '[I', 'goto_previous_end', '@conditional.outer' }, + local move_textobjects = { + { 'a', '@parameter.inner' }, + { 's', '@class.outer' }, + { 'f', '@function.outer' }, + { 'i', '@conditional.outer' }, + { '/', '@comment.outer' }, } for _, m in ipairs({ 'n', 'x', 'o' }) do - for _, t in ipairs(move_maps) do + for _, t in ipairs(move_textobjects) do + local key, capture = t[1], t[2] map({ m, - t[1], + ']' .. key, function() - move[t[2]](t[3], 'textobjects') + move.goto_next_start(capture, 'textobjects') end, }) + map({ + m, + '[' .. key, + function() + move.goto_previous_start(capture, 'textobjects') + end, + }) + local upper = key:upper() + if upper ~= key then + map({ + m, + ']' .. upper, + function() + move.goto_next_end(capture, 'textobjects') + end, + }) + map({ + m, + '[' .. upper, + function() + move.goto_previous_end(capture, 'textobjects') + end, + }) + end end end