Compare commits

...

2 commits

Author SHA1 Message Date
7393fc696a
feat: conform.nvim 2024-12-15 12:21:28 -08:00
83af9ac2ac
feat: mini.ai 2024-12-15 11:18:47 -08:00
8 changed files with 252 additions and 0 deletions

View file

@ -58,6 +58,10 @@ with final.pkgs.lib; let
lexima-vim lexima-vim
(mkNvimPlugin inputs.neotab-nvim "neotab.nvim") (mkNvimPlugin inputs.neotab-nvim "neotab.nvim")
ts-comments-nvim ts-comments-nvim
mini-ai
# Formatting
conform-nvim
# Treesitter # Treesitter
nvim-treesitter-textobjects nvim-treesitter-textobjects
@ -103,6 +107,10 @@ with final.pkgs.lib; let
# Language servers # Language servers
lua-language-server lua-language-server
nixd nixd
# Formatters
shfmt
stylua
]; ];
in { in {
# This is the neovim derivation returned by the overlay. # This is the neovim derivation returned by the overlay.

View file

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

View file

@ -1,4 +1,5 @@
return { return {
around = '󰅪',
bottom = '', bottom = '',
center = '󰘢', center = '󰘢',
change = '', change = '',
@ -35,9 +36,47 @@ return {
right = '󰉶', right = '󰉶',
increase = '󰉶', increase = '󰉶',
}, },
inner = '󰅩',
last = '󰘁', last = '󰘁',
lazygit = '', lazygit = '',
left = '', 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 = '', next = '',
notifications = '󰈸', notifications = '󰈸',
prev = '', prev = '',

View file

@ -5,4 +5,5 @@ return {
req('lexima-vim'), req('lexima-vim'),
req('neotab-nvim'), req('neotab-nvim'),
req('ts-comments-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,
}

View file

@ -0,0 +1,43 @@
return {
'conform.nvim',
event = { 'BufWritePre' },
cmd = { 'ConformInfo' },
keys = {
{
'<LEADER>cf',
function()
require('conform').format()
end,
desc = 'format',
},
{
'<LEADER>cF',
function()
require('conform').format({
formatters = { 'injected' },
timeout_ms = 3000,
})
end,
mode = { 'n', 'v' },
desc = 'format injected langs',
},
},
after = function()
require('conform').setup({
format_on_save = function(buf)
if (vim.g.autoformat == false) or (vim.b[buf].autoformat == false) then
return
end
return { timeout_ms = 3000, lsp_format = 'fallback' }
end,
formatters_by_ft = {
lua = { 'stylua' },
fish = { 'fish_indent' },
sh = { 'shfmt' },
},
})
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}

View file

@ -0,0 +1,5 @@
local req = MarleyVim.local_require('plugins.formatting')
return {
req('conform-nvim'),
}

View file

@ -61,6 +61,36 @@ if vim.lsp.inlay_hint then
toggle.inlay_hints():map('<LEADER>uh') toggle.inlay_hints():map('<LEADER>uh')
end end
toggle({
name = 'auto format (global)',
get = function()
return vim.g.autoformat == nil or vim.g.autoformat
end,
set = function(enable)
vim.g.autoformat = (enable == nil and true) or enable
vim.b.autoformat = nil
end,
}):map('<LEADER>uf')
toggle({
name = 'auto format (buffer)',
get = function()
local buf = vim.api.nvim_get_current_buf()
local gopt = vim.g.autoformat
local bopt = vim.b[buf].autoformat
if bopt ~= nil then
return bopt
end
return gopt == nil or gopt
end,
set = function(enable)
vim.b.autoformat = (enable == nil and true) or enable
end,
}):map('<LEADER>uF')
-- Git -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Git -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>gb', function() set({ 'n' }, '<LEADER>gb', function()