2024-12-23 01:24:06 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit (lib.modules) mkIf;
|
2024-12-23 02:51:53 +01:00
|
|
|
inherit (lib.generators) mkLuaInline;
|
2024-12-23 03:59:57 +01:00
|
|
|
|
2024-12-23 02:51:53 +01:00
|
|
|
cfg = config.vim.autocomplete.blink-cmp;
|
2024-12-23 03:59:57 +01:00
|
|
|
inherit (cfg) mappings;
|
2024-12-23 01:24:06 +01:00
|
|
|
in {
|
|
|
|
vim = mkIf cfg.enable {
|
2024-12-23 02:51:53 +01:00
|
|
|
lazy.plugins.blink-cmp = {
|
|
|
|
package = "blink-cmp";
|
|
|
|
setupModule = "blink.cmp";
|
|
|
|
inherit (cfg) setupOpts;
|
2024-12-23 04:02:20 +01:00
|
|
|
# TODO: lazy disabled until lspconfig is lazy loaded
|
|
|
|
#
|
|
|
|
# event = ["InsertEnter" "CmdlineEnter"];
|
2024-12-23 02:51:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
autocomplete = {
|
|
|
|
enableSharedCmpSources = true;
|
|
|
|
|
|
|
|
blink-cmp.setupOpts = {
|
|
|
|
snippets = mkIf config.vim.snippets.luasnip.enable {
|
|
|
|
expand = mkLuaInline ''
|
|
|
|
function(snippet)
|
|
|
|
return require("luasnip").lsp_expand(snippet)
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
active = mkLuaInline ''
|
|
|
|
function(filter)
|
|
|
|
if filter and filter.direction then
|
|
|
|
return require('luasnip').jumpable(filter.direction)
|
|
|
|
end
|
|
|
|
return require('luasnip').in_snippet()
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
jump = mkLuaInline "function(direction) require('luasnip').jump(direction) end";
|
|
|
|
};
|
2024-12-23 03:59:57 +01:00
|
|
|
|
|
|
|
keymap = {
|
|
|
|
${mappings.complete} = ["show" "fallback"];
|
|
|
|
${mappings.close} = ["hide" "fallback"];
|
|
|
|
${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"];
|
|
|
|
${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"];
|
|
|
|
${mappings.confirm} = ["accept" "fallback"];
|
|
|
|
|
|
|
|
${mappings.next} = [
|
|
|
|
"select_next"
|
|
|
|
"snippet_forward"
|
|
|
|
(mkLuaInline ''
|
|
|
|
function(cmp)
|
|
|
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
|
|
|
has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
|
|
|
|
|
|
|
if has_words_before then
|
|
|
|
return cmp.show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
'')
|
|
|
|
"fallback"
|
|
|
|
];
|
|
|
|
${mappings.previous} = [
|
|
|
|
"select_prev"
|
|
|
|
"snippet_backward"
|
|
|
|
"fallback"
|
|
|
|
];
|
|
|
|
};
|
2024-12-23 02:51:53 +01:00
|
|
|
};
|
|
|
|
};
|
2024-12-23 01:24:06 +01:00
|
|
|
};
|
|
|
|
}
|