pkg(nixvim): Add blink-cmp, lazydev, mini-ai, mini-pairs and ts-comments plugins to improve coding UX

This commit is contained in:
ulic-youthlic 2025-07-13 06:04:55 +08:00
parent 7477166d9e
commit cfdd89c080
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
6 changed files with 265 additions and 16 deletions

View file

@ -1,16 +0,0 @@
{...}: {
plugins = {
# mini-pairs = {
# enable = true;
# };
# ts-comments = {
# enable = true;
# };
# mini-ai = {
# enable = true;
# };
# lazydev = {
# enable = true;
# };
};
}

View file

@ -0,0 +1,55 @@
{...}: {
youthlic.plugins.blink-cmp = {
enable = true;
setupLspCapabilities = true;
settings = {
snippets = {
expand = {
__raw =
#lua
''
function(snippet, _)
return {}
end
'';
};
};
appearance = {
# use_nvim_cmp_as_default = false;
};
completion = {
accept = {
auto_brackets = {
enabled = true;
};
};
menu = {
draw = {
treesitter = ["lsp"];
};
};
documentation = {
auto_show = true;
auto_show_delay_ms = 200;
};
ghost_text = {
enabled = {
__raw =
#lua
''vim.g.ai_cmp'';
};
};
};
sources = {
compat = [];
default = ["lsp" "path" "snippets" "buffer"];
};
cmdline = {
enabled = false;
};
keymap = {
preset = "enter";
};
};
};
}

View file

@ -0,0 +1,15 @@
{...}: {
youthlic.plugins = {
lazydev = {
enable = true;
settings = {
library = [
{
path = "$''{3rd}/luv/library";
words = ["vim%.uv"];
}
];
};
};
};
}

View file

@ -0,0 +1,121 @@
{...}: {
youthlic.plugins.mini-ai = {
enable = true;
luaConfig.pre =
#lua
''
do
local ai = require("mini.ai")
_M.__coding_plugin_mini_ai_opts = {
n_lines = 500,
custom_textobjects = {
o = ai.gen_spec.treesitter({ -- code block
a = { "@block.outer", "@conditional.outer", "@loop.outer" },
i = { "@block.inner", "@conditional.inner", "@loop.inner" },
}),
f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }), -- function
c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }), -- class
t = { "<([%p%w]-)%f[^<%w][^<>]->.-</%1>", "^<.->().*()</[^/]->$" }, -- tags
d = { "%f[%d]%d+" }, -- digits
e = { -- Word with case
{ "%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]" },
"^().*()$",
},
g = function(ai_type)
local start_line, end_line = 1, vim.fn.line("$")
if ai_type == "i" then
local first_nonblank, last_nonblank = vim.fn.nextnonblank(start_line), vim.fn.prevnonblank(end_line)
if first_nonblank == 0 or last_nonblank == 0 then
return { from = { line = start_line, col = 1 } }
end
start_line, end_line = first_nonblank, last_nonblank
end
local to_col = math.max(vim.fn.getline(end_line):len(), 1)
return {
from = {
line = start_line,
col = 1,
},
to = {
line = end_line,
col = to_col,
},
}
end, -- buffer
u = ai.gen_spec.function_call(), -- u for "Usage"
U = ai.gen_spec.function_call({ name_pattern = "[%w_]" }), -- without dot in function name
},
}
end
'';
settings = {
__raw =
#lua
"_M.__coding_plugin_mini_ai_opts";
};
luaConfig.post =
#lua
''
_M.on_load("which-key", function()
local opts = _M.__coding_plugin_mini_ai_opts
local objects = {
{ " ", desc = "whitespace" },
{ '"', desc = '" string' },
{ "'", desc = "' string" },
{ "(", desc = "() block" },
{ ")", desc = "() block with ws" },
{ "<", desc = "<> block" },
{ ">", desc = "<> block with ws" },
{ "?", desc = "user prompt" },
{ "U", desc = "use/call without dot" },
{ "[", desc = "[] block" },
{ "]", desc = "[] block with ws" },
{ "_", desc = "underscore" },
{ "`", desc = "` string" },
{ "a", desc = "argument" },
{ "b", desc = ")]} block" },
{ "c", desc = "class" },
{ "d", desc = "digit(s)" },
{ "e", desc = "CamelCase / snake_case" },
{ "f", desc = "function" },
{ "g", desc = "entire file" },
{ "i", desc = "indent" },
{ "o", desc = "block, conditional, loop" },
{ "q", desc = "quote `\"'" },
{ "t", desc = "tag" },
{ "u", desc = "use/call" },
{ "{", desc = "{} block" },
{ "}", desc = "{} with ws" },
}
---@type wk.Spec[]
local ret = { mode = { "o", "x" } }
---@type table<string, string>
local mappings = vim.tbl_extend("force", {}, {
around = "a",
inside = "i",
around_next = "an",
inside_next = "in",
around_last = "al",
inside_last = "il",
}, opts.mappings or {})
mappings.goto_left = nil
mappings.goto_right = nil
for name, prefix in pairs(mappings) do
name = name:gsub("^around_", ""):gsub("^inside_", "")
ret[#ret + 1] = { prefix, group = name }
for _, obj in ipairs(objects) do
local desc = obj.desc
if prefix:sub(1, 1) == "i" then
desc = desc:gsub(" with ws", "")
end
ret[#ret + 1] = { prefix .. obj[1], desc = obj.desc }
end
end
require("which-key").add(ret, { notify = false })
end)
'';
};
}

View file

@ -0,0 +1,71 @@
{...}: {
youthlic.plugins.mini-pairs = {
enable = true;
settings = {
modes = {
insert = true;
command = true;
terminal = false;
};
};
luaConfig.post =
#lua
''
do
local opts = {
skip_next = [=[[%w%%'%[%"%.%`%$]]=],
skip_ts = { "string" },
skip_unbalanced = true,
markdown = true,
}
_M.on_load("snacks", function()
vim.schedule(function()
Snacks.toggle({
name = "Mini Pairs",
get = function()
return not vim.g.minipairs_disable
end,
set = function(state)
vim.g.minipairs_disable = not state
end,
}):map("<leader>up")
end)
end)
local pairs = require("mini.pairs")
local open = pairs.open
pairs.open = function(pair, neigh_pattern)
if vim.fn.getcmdline() ~= "" then
return open(pair, neigh_pattern)
end
local o, c = pair:sub(1, 1), pair:sub(2, 2)
local line = vim.api.nvim_get_current_line()
local cursor = vim.api.nvim_win_get_cursor(0)
local next = line:sub(cursor[2] + 1, cursor[2] + 1)
local before = line:sub(1, cursor[2])
if opts.markdown and o == "`" and vim.bo.filetype == "markdown" and before:match("^%s*``") then
return "`\n``" .. vim.api.nvim_replace_termcodes("<up>", true, true, true)
end
if opts.skip_next and next ~= "" and next:match(opts.skip_next) then
return o
end
if opts.skip_ts and #opts.skip_ts > 0 then
local ok, captures = pcall(vim.treesitter.get_captures_at_pos, 0, cursor[1] - 1, math.max(cursor[2] - 1, 0))
for _, capture in ipairs(ok and captures or {}) do
if vim.tbl_contains(opts.skip_ts, capture.capture) then
return o
end
end
end
if opts.skip_unbalanced and next == c and c ~= o then
local _, count_open = line:gsub(vim.pesc(pair:sub(1, 1)), "")
local _, count_close = line:gsub(vim.pesc(pair:sub(2, 2)), "")
if count_close > count_open then
return o
end
end
return open(pair, neigh_pattern)
end
end
'';
};
}

View file

@ -0,0 +1,3 @@
{...}: {
youthlic.plugins.ts-comments.enable = true;
}