feat(nvim): more completion configs
This commit is contained in:
parent
e9aeacd1e6
commit
dd13c34c92
7 changed files with 161 additions and 143 deletions
|
|
@ -27,14 +27,6 @@ vim.lsp.config('*', {
|
||||||
flags = { debounce_text_changes = 0 },
|
flags = { debounce_text_changes = 0 },
|
||||||
})
|
})
|
||||||
|
|
||||||
map({
|
|
||||||
{ 'n', 'x' },
|
|
||||||
'gF',
|
|
||||||
function()
|
|
||||||
vim.lsp.buf.format({ async = true })
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
for _, server in ipairs({
|
for _, server in ipairs({
|
||||||
'bashls',
|
'bashls',
|
||||||
'basedpyright',
|
'basedpyright',
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
"blink-cmp-env": { "branch": "main", "commit": "99af62c1f9aa46005e8f50ad4ccee581946546ca" },
|
"blink-cmp-env": { "branch": "main", "commit": "99af62c1f9aa46005e8f50ad4ccee581946546ca" },
|
||||||
"blink-cmp-git": { "branch": "master", "commit": "e3ad0ffaaa3b3b7e2158cc72cd6dad2d19842c46" },
|
"blink-cmp-git": { "branch": "master", "commit": "e3ad0ffaaa3b3b7e2158cc72cd6dad2d19842c46" },
|
||||||
"blink-cmp-sshconfig": { "branch": "main", "commit": "91bf9bd80d53d2b6521cffb01da138ef6403d625" },
|
"blink-cmp-sshconfig": { "branch": "main", "commit": "91bf9bd80d53d2b6521cffb01da138ef6403d625" },
|
||||||
"blink-cmp-tmux": { "branch": "main", "commit": "1ef35d8e388475ab8eaeecfc12e196c78bd5de04" },
|
|
||||||
"blink.cmp": { "branch": "main", "commit": "4b18c32adef2898f95cdef6192cbd5796c1a332d" },
|
"blink.cmp": { "branch": "main", "commit": "4b18c32adef2898f95cdef6192cbd5796c1a332d" },
|
||||||
"dial.nvim": { "branch": "master", "commit": "f2634758455cfa52a8acea6f142dcd6271a1bf57" },
|
"dial.nvim": { "branch": "master", "commit": "f2634758455cfa52a8acea6f142dcd6271a1bf57" },
|
||||||
"fzf-lua": { "branch": "main", "commit": "b2c0603216adb92c6bba81053bc996d7ae95b77a" },
|
"fzf-lua": { "branch": "main", "commit": "b2c0603216adb92c6bba81053bc996d7ae95b77a" },
|
||||||
|
|
|
||||||
107
config/nvim/lua/config/blink/init.lua
Normal file
107
config/nvim/lua/config/blink/init.lua
Normal 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
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -14,6 +14,7 @@ return {
|
||||||
vim.o.pumheight = 15
|
vim.o.pumheight = 15
|
||||||
opts.completion.menu.max_height = vim.o.pumheight
|
opts.completion.menu.max_height = vim.o.pumheight
|
||||||
|
|
||||||
|
require('config.blink')
|
||||||
require('blink.cmp').setup(opts)
|
require('blink.cmp').setup(opts)
|
||||||
end,
|
end,
|
||||||
opts = {
|
opts = {
|
||||||
|
|
@ -47,8 +48,19 @@ return {
|
||||||
draw = {
|
draw = {
|
||||||
treesitter = { 'lsp', 'snippets', 'buffer' },
|
treesitter = { 'lsp', 'snippets', 'buffer' },
|
||||||
columns = {
|
columns = {
|
||||||
{ 'kind_icon' },
|
|
||||||
{ 'label', 'label_description', gap = 1 },
|
{ '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',
|
'buffer',
|
||||||
'env',
|
'env',
|
||||||
'snippets',
|
'snippets',
|
||||||
-- 'sshconfig',
|
'sshconfig',
|
||||||
},
|
},
|
||||||
providers = {
|
providers = {
|
||||||
git = {
|
git = {
|
||||||
module = 'blink-cmp-git',
|
module = 'blink-cmp-git',
|
||||||
name = 'Git',
|
name = 'Git',
|
||||||
},
|
},
|
||||||
|
sshconfig = {
|
||||||
|
name = 'SshConfig',
|
||||||
|
module = 'blink-cmp-sshconfig',
|
||||||
|
},
|
||||||
conventional_commits = {
|
conventional_commits = {
|
||||||
name = 'Conventional Commits',
|
name = 'Conventional Commits',
|
||||||
module = 'config.cmp_cc',
|
module = 'config.blink.conventional_commits',
|
||||||
},
|
},
|
||||||
lazydev = {
|
lazydev = {
|
||||||
name = 'LazyDev',
|
name = 'LazyDev',
|
||||||
|
|
@ -88,10 +104,6 @@ return {
|
||||||
name = 'Env',
|
name = 'Env',
|
||||||
module = 'blink-cmp-env',
|
module = 'blink-cmp-env',
|
||||||
},
|
},
|
||||||
-- sshconfig = {
|
|
||||||
-- name = 'SshConfig',
|
|
||||||
-- module = 'blink-cmp-sshconfig',
|
|
||||||
-- },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ return {
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
keys = {
|
keys = {
|
||||||
{ 'gF', '<cmd>Guard fmt<CR>', mode = { 'n', 'x' } },
|
{ 'gF', '<cmd>Guard fmt<cr>', mode = { 'n', 'x' } },
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local ft = require('guard.filetype')
|
local ft = require('guard.filetype')
|
||||||
|
|
|
||||||
|
|
@ -3,30 +3,6 @@ return {
|
||||||
'nvim-treesitter/nvim-treesitter',
|
'nvim-treesitter/nvim-treesitter',
|
||||||
branch = 'main',
|
branch = 'main',
|
||||||
build = ':TSUpdate all',
|
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 = {
|
opts = {
|
||||||
auto_install = true,
|
auto_install = true,
|
||||||
},
|
},
|
||||||
|
|
@ -79,33 +55,47 @@ return {
|
||||||
end
|
end
|
||||||
|
|
||||||
local move = require('nvim-treesitter-textobjects.move')
|
local move = require('nvim-treesitter-textobjects.move')
|
||||||
local move_maps = {
|
local move_textobjects = {
|
||||||
{ ']a', 'goto_next_start', '@parameter.inner' },
|
{ 'a', '@parameter.inner' },
|
||||||
{ ']s', 'goto_next_start', '@class.outer' },
|
{ 's', '@class.outer' },
|
||||||
{ ']f', 'goto_next_start', '@function.outer' },
|
{ 'f', '@function.outer' },
|
||||||
{ ']i', 'goto_next_start', '@conditional.outer' },
|
{ 'i', '@conditional.outer' },
|
||||||
{ ']/', 'goto_next_start', '@comment.outer' },
|
{ '/', '@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' },
|
|
||||||
}
|
}
|
||||||
for _, m in ipairs({ 'n', 'x', 'o' }) do
|
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({
|
map({
|
||||||
m,
|
m,
|
||||||
t[1],
|
']' .. key,
|
||||||
function()
|
function()
|
||||||
move[t[2]](t[3], 'textobjects')
|
move.goto_next_start(capture, 'textobjects')
|
||||||
end,
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue