feat(nvim): more completion configs

This commit is contained in:
Barrett Ruth 2026-02-19 14:52:17 -05:00
parent e9aeacd1e6
commit dd13c34c92
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
7 changed files with 161 additions and 143 deletions

View file

@ -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',

View file

@ -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" },

View file

@ -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

View file

@ -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

View file

@ -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',
-- },
},
},
},

View file

@ -11,7 +11,7 @@ return {
}
end,
keys = {
{ 'gF', '<cmd>Guard fmt<CR>', mode = { 'n', 'x' } },
{ 'gF', '<cmd>Guard fmt<cr>', mode = { 'n', 'x' } },
},
config = function()
local ft = require('guard.filetype')

View file

@ -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