From 55525c2732c0143f716c450250d9878606fca13b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 02:51:21 +0100 Subject: [PATCH] blink: basic keymap option --- .../completion/blink-cmp/blink-cmp.nix | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index 65abbdf9..8b1aeb9c 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -1,15 +1,37 @@ {lib, ...}: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) listOf string; - inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.options) mkEnableOption mkOption literalMD; + inherit (lib.types) listOf str either oneOf attrsOf; + inherit (lib.nvim.types) mkPluginSetupOption luaInline; in { options.vim.autocomplete.blink-cmp = { enable = mkEnableOption "blink.cmp"; setupOpts = mkPluginSetupOption "blink.cmp" { - sources = mkOption { - type = listOf string; - description = "List of sources to enable for completion."; - default = ["lsp" "path" "snippets" "buffer"]; + sources = { + default = mkOption { + type = listOf str; + description = "Default list of sources to enable for completion."; + default = ["lsp" "path" "snippets" "buffer"]; + }; + }; + + keymap = mkOption { + type = attrsOf (oneOf [luaInline str (listOf (either str luaInline))]); + default = {}; + description = "blink.cmp keymap"; + example = literalMD '' + ```nix + "" = ["select_prev" "fallback"]; + "" = [ + (lib.generators.mkLuaInline '''' + function(cmp) + if some_condition then return end -- runs the next command + return true -- doesn't run the next command + end, + '''') + "select_next" + ]; + ``` + ''; }; }; };