blink: add blink.compat support

This commit is contained in:
Ching Pei Yang 2024-12-23 20:27:03 +01:00
parent 1f82c55cd9
commit 5af402af98
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
2 changed files with 56 additions and 9 deletions

View file

@ -1,6 +1,6 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption mkOption literalMD; inherit (lib.options) mkEnableOption mkOption literalMD;
inherit (lib.types) listOf str either attrsOf submodule enum; inherit (lib.types) listOf str either attrsOf submodule enum anything;
inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.nvim.types) mkPluginSetupOption luaInline;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
@ -14,6 +14,16 @@
}; };
}; };
}; };
providerType = submodule {
freeformType = anything;
options = {
module = mkOption {
type = str;
description = "module of the provider";
};
};
};
in { in {
options.vim.autocomplete.blink-cmp = { options.vim.autocomplete.blink-cmp = {
enable = mkEnableOption "blink.cmp"; enable = mkEnableOption "blink.cmp";
@ -24,6 +34,12 @@ in {
description = "Default list of sources to enable for completion."; description = "Default list of sources to enable for completion.";
default = ["lsp" "path" "snippets" "buffer"]; default = ["lsp" "path" "snippets" "buffer"];
}; };
providers = mkOption {
type = attrsOf providerType;
description = "Providers";
default = {};
};
}; };
keymap = mkOption { keymap = mkOption {

View file

@ -3,26 +3,57 @@
config, config,
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf mkDefault;
inherit (lib.strings) optionalString;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) concatStringsSep typeOf tryEval attrNames mapAttrs;
cfg = config.vim.autocomplete.blink-cmp; cfg = config.vim.autocomplete.blink-cmp;
autocompleteCfg = config.vim.autocomplete;
inherit (cfg) mappings; inherit (cfg) mappings;
getPluginName = plugin:
if typeOf plugin == "string"
then plugin
else if (plugin ? pname && (tryEval plugin.pname).success)
then plugin.pname
else plugin.name;
in { in {
vim = mkIf cfg.enable { vim = mkIf cfg.enable {
lazy.plugins.blink-cmp = { startPlugins = ["blink-compat"];
package = "blink-cmp"; lazy.plugins = {
setupModule = "blink.cmp"; blink-cmp = {
inherit (cfg) setupOpts; package = "blink-cmp";
# TODO: lazy disabled until lspconfig is lazy loaded setupModule = "blink.cmp";
# inherit (cfg) setupOpts;
# event = ["InsertEnter" "CmdlineEnter"];
# TODO: lazy disabled until lspconfig is lazy loaded
#
# event = ["InsertEnter" "CmdlineEnter"];
after = ''
${optionalString config.vim.lazy.enable
(concatStringsSep "\n" (map
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
autocompleteCfg.sourcePlugins))}
'';
};
}; };
autocomplete = { autocomplete = {
enableSharedCmpSources = true; enableSharedCmpSources = true;
blink-cmp.setupOpts = { blink-cmp.setupOpts = {
sources = {
default = mkDefault (attrNames autocompleteCfg.nvim-cmp.sources);
providers =
mapAttrs (name: _: {
inherit name;
module = "blink.compat.source";
})
autocompleteCfg.nvim-cmp.sources;
};
snippets = mkIf config.vim.snippets.luasnip.enable { snippets = mkIf config.vim.snippets.luasnip.enable {
expand = mkLuaInline '' expand = mkLuaInline ''
function(snippet) function(snippet)