2024-03-24 23:39:49 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: {
|
|
|
|
options = {
|
2024-04-23 23:56:34 +02:00
|
|
|
home.nvim.enable-completions =
|
2024-03-24 23:39:49 +01:00
|
|
|
(lib.mkEnableOption "basic completion in nvim")
|
|
|
|
// {
|
2024-04-23 23:56:34 +02:00
|
|
|
default = false;
|
2024-03-24 23:39:49 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
config =
|
2024-04-23 23:56:34 +02:00
|
|
|
lib.mkIf config.home.nvim.enable-completions
|
2024-03-24 23:39:49 +01:00
|
|
|
{
|
|
|
|
programs.nixvim = {
|
|
|
|
plugins.luasnip.enable = true;
|
|
|
|
plugins.friendly-snippets.enable = true;
|
|
|
|
plugins.cmp = {
|
|
|
|
enable = true;
|
|
|
|
autoEnableSources = true;
|
|
|
|
settings = {
|
|
|
|
sources = [
|
|
|
|
{name = "luasnip";}
|
|
|
|
{name = "treesitter";}
|
|
|
|
{name = "path";}
|
|
|
|
{name = "emoji";}
|
|
|
|
{name = "buffer";}
|
|
|
|
{name = "latex_symbols";}
|
|
|
|
{name = "digraphs";}
|
|
|
|
{name = "spell";}
|
|
|
|
];
|
|
|
|
snippet = {
|
|
|
|
expand = "function(args) require('luasnip').lsp_expand(args.body) end";
|
|
|
|
};
|
|
|
|
mapping = {
|
|
|
|
"<C-Space>" = "cmp.mapping.complete()";
|
|
|
|
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
|
|
|
|
"<C-e>" = "cmp.mapping.close()";
|
|
|
|
"<C-f>" = "cmp.mapping.scroll_docs(4)";
|
|
|
|
"<CR>" = "cmp.mapping.confirm({ select = false })";
|
|
|
|
"<Tab>" = ''
|
|
|
|
function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif require("luasnip").expand_or_jumpable() then
|
|
|
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
"<S-Tab>" = ''
|
|
|
|
function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
elseif require("luasnip").jumpable(-1) then
|
|
|
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|