feat: mini.ai

This commit is contained in:
punkfairie 2024-12-15 11:18:47 -08:00
parent f71df2ee98
commit 83af9ac2ac
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696
5 changed files with 167 additions and 0 deletions

View file

@ -58,6 +58,7 @@ with final.pkgs.lib; let
lexima-vim
(mkNvimPlugin inputs.neotab-nvim "neotab.nvim")
ts-comments-nvim
mini-ai
# Treesitter
nvim-treesitter-textobjects

View file

@ -1,5 +1,6 @@
---@type {[string]:"azure" | "blue" | "cyan" | "green" | "grey" | "orange" | "purple" | "red" | "yellow"}
return {
around = 'purple',
buffers = 'cyan',
change = 'cyan',
delete = 'red',
@ -9,6 +10,7 @@ return {
format = 'purple',
git = 'orange',
go_to = 'cyan',
inner = 'purple',
notifications = 'orange',
replace = 'blue',
search = 'green',

View file

@ -1,4 +1,5 @@
return {
around = '󰅪',
bottom = '',
center = '󰘢',
change = '',
@ -35,9 +36,47 @@ return {
right = '󰉶',
increase = '󰉶',
},
inner = '󰅩',
last = '󰘁',
lazygit = '',
left = '',
lsp = {
array = '',
boolean = '󰨙',
class = '',
color = '',
control = '',
constant = '󰏿',
constructor = '',
enum = '',
enummember = '',
event = '',
field = '',
file = '',
folder = '',
['function'] = '󰊕',
interface = '',
key = '',
keyword = '',
method = '󰊕',
module = '',
namespace = '󰦮',
null = '',
number = '󰎠',
object = '',
operator = '',
package = '',
property = '',
reference = '',
snippet = '󱄽',
string = '',
struct = '',
text = '',
typeparameter = '',
unit = '',
value = '',
variable = '',
},
next = '',
notifications = '󰈸',
prev = '',

View file

@ -5,4 +5,5 @@ return {
req('lexima-vim'),
req('neotab-nvim'),
req('ts-comments-nvim'),
req('mini-ai'),
}

View file

@ -0,0 +1,124 @@
return {
'mini.ai',
event = 'DeferredUIEnter',
before = function()
require('lz.n').trigger_load('which-key.nvim')
end,
after = function()
local ai = require('mini.ai')
ai.setup({
n_lines = 500,
custom_textobjects = {
-- code blOck
o = ai.gen_spec.treesitter({
a = { '@block.outer', '@conditional.outer', '@loop.outer' },
i = { '@block.inner', '@conditional.inner', '@loop.inner' },
}),
-- Class
c = ai.gen_spec.treesitter({
a = '@class.outer',
i = '@class.inner',
}),
-- Usage (fn call)
u = ai.gen_spec.function_call(),
-- Usage (to last .)
U = ai.gen_spec.function_call({ name_pattern = '[%w_]' }),
-- Digit
d = { '%f[%d]%d+' },
-- word within casE (snake_case, CamelCase, etc)
e = {
{
'%u[%l%d]+%f[^%l%d]',
'%f[%S][%l%d]+%f[^%l%d]',
'%f[%P][%l%d]+%f[^%l%d]',
'^[%l%d]+%f[^%l%d]',
},
'^().*()$',
},
-- buffer
g = {
from = { line = 1, col = 1 },
to = {
line = vim.fn.line('$'),
col = math.max(vim.fn.getline('$'):len(), 1),
},
},
},
})
local i = require('icons')
local c = require('colors')
local mkA = MarleyVim.wkSpec(c.around)
local mkI = MarleyVim.wkSpec(c.inner)
---@param lhs string
---@param icon string
---@param opts table
local function mkKey(lhs, icon, opts)
if lhs:sub(1, 1) == 'a' then
return mkA(lhs, nil, icon, opts)
else
return mkI(lhs, nil, icon, opts)
end
end
local groups = {
around = { 'a', i.around },
around_last = { 'al', i.around },
around_next = { 'an', i.around },
inner = { 'i', i.inner },
inner_last = { 'il', i.inner },
inner_next = { 'in', i.inner },
}
local mappings = {
{ '<SPACE>', '', 'whitespace' },
{ '"', '', 'double quotes' },
{ "'", '', 'single quotes' },
{ '`', '', 'backticks' },
{ '(', '󰅲', '()' },
{ ')', '󰅲', '() with ws' },
{ '[', '󰅪', '[] block' },
{ ']', '󰅪', '[] block with ws' },
{ '{', '󰅩', '{} block' },
{ '}', '󰅩', '{} block with ws' },
{ '<', '󰅴', '<>' },
{ '>', '󰅴', '<> with ws' },
{ '_', '󱁐', 'underscores' },
{ '?', '󰘎', 'user prompt' },
{ 'a', i.lsp.variable, 'argument' },
{ 'b', '󰅲', ')]} block' },
{ 'c', i.lsp.class, 'class' },
{ 'd', i.lsp.number, 'numbers' },
{ 'e', i.lsp.variable, 'word within case' },
{ 'f', i.lsp['function'], 'function' },
{ 'g', i.lsp.file, 'entire buffer' },
{ 'o', i.lsp.control, 'block, conditional, loop' },
{ 'q', i.lsp.string, 'quotes/backticks' },
{ 't', '󰅴', 'tags' },
{ 'u', i.lsp.method, 'use/call' },
{ 'U', i.lsp.method, 'use/call without dot' },
}
local spec = { mode = { 'o', 'x' } }
for name, data in pairs(groups) do
name = name:gsub('^around_', ''):gsub('^insude_', '')
spec[#spec + 1] = mkKey(data[1], data[2], { group = name })
for _, item in ipairs(mappings) do
spec[#spec + 1] = mkKey(data[1] .. item[1], item[2], { desc = item[3] })
end
end
require('which-key').add({ spec })
end,
}