From 581c5cbb856d83f01d3497869a91377b0c5335f2 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 02:51:53 +0100 Subject: [PATCH] blink: add luasnip integration --- .../plugins/completion/blink-cmp/config.nix | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix index 15391a24..663e19c5 100644 --- a/modules/plugins/completion/blink-cmp/config.nix +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -4,16 +4,38 @@ ... }: let inherit (lib.modules) mkIf; - cfg = config.vim.autocomplete.blink-nvim; + inherit (lib.generators) mkLuaInline; + cfg = config.vim.autocomplete.blink-cmp; in { vim = mkIf cfg.enable { - lazy.plugins = [ - { - package = "blink-cmp"; - setupModule = "blink"; - inherit (cfg) setupOpts; - event = ["InsertEnter" "CmdlineEnter"]; - } - ]; + lazy.plugins.blink-cmp = { + package = "blink-cmp"; + setupModule = "blink.cmp"; + inherit (cfg) setupOpts; + event = ["InsertEnter" "CmdlineEnter"]; + }; + + 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"; + }; + }; + }; }; }