Compare commits

...

5 commits

Author SHA1 Message Date
Ching Pei Yang
2dc1a7fd19
blink: auto-show docs by default 2024-12-23 20:45:17 +01:00
Ching Pei Yang
cb739be3fc
blink: re-add default sources to cmp ones 2024-12-23 20:32:48 +01:00
Ching Pei Yang
03359ac3c6
treesitter-cmp: disable on blink.cmp 2024-12-23 20:27:27 +01:00
Ching Pei Yang
5af402af98
blink: add blink.compat support 2024-12-23 20:27:03 +01:00
Ching Pei Yang
1f82c55cd9
flake: add blink.compat 2024-12-23 19:06:19 +01:00
5 changed files with 93 additions and 11 deletions

View file

@ -204,6 +204,22 @@
"type": "github"
}
},
"plugin-blink-compat": {
"flake": false,
"locked": {
"lastModified": 1734896240,
"narHash": "sha256-Rrrh+O3FbBnaAnCHwPuQyfhH+XueSkQp6ipEkn6esGY=",
"owner": "saghen",
"repo": "blink.compat",
"rev": "74b251a1e9478c4fa6d7c6bc2921d7124e6f6cbb",
"type": "github"
},
"original": {
"owner": "saghen",
"repo": "blink.compat",
"type": "github"
}
},
"plugin-bufdelete-nvim": {
"flake": false,
"locked": {
@ -2093,6 +2109,7 @@
"plugin-alpha-nvim": "plugin-alpha-nvim",
"plugin-base16": "plugin-base16",
"plugin-blink-cmp": "plugin-blink-cmp",
"plugin-blink-compat": "plugin-blink-compat",
"plugin-bufdelete-nvim": "plugin-bufdelete-nvim",
"plugin-catppuccin": "plugin-catppuccin",
"plugin-ccc": "plugin-ccc",

View file

@ -293,6 +293,11 @@
flake = false;
};
plugin-blink-compat = {
url = "github:saghen/blink.compat";
flake = false;
};
plugin-nvim-cmp = {
url = "github:hrsh7th/nvim-cmp";
flake = false;

View file

@ -1,8 +1,9 @@
{lib, ...}: let
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 int;
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.config) mkBool;
keymapType = submodule {
freeformType = attrsOf (listOf (either str luaInline));
@ -14,6 +15,16 @@
};
};
};
providerType = submodule {
freeformType = anything;
options = {
module = mkOption {
type = str;
description = "module of the provider";
};
};
};
in {
options.vim.autocomplete.blink-cmp = {
enable = mkEnableOption "blink.cmp";
@ -21,8 +32,25 @@ in {
sources = {
default = mkOption {
type = listOf str;
description = "Default list of sources to enable for completion.";
default = ["lsp" "path" "snippets" "buffer"];
description = "Default list of sources to enable for completion.";
};
providers = mkOption {
type = attrsOf providerType;
default = {};
description = "Providers";
};
};
completion = {
documentation = {
auto_show = mkBool true "Show documentation whenever an item is selected";
auto_show_delay_ms = mkOption {
type = int;
default = 200;
description = "Delay before auto show triggers";
};
};
};

View file

@ -3,26 +3,57 @@
config,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.modules) mkIf mkDefault;
inherit (lib.strings) optionalString;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) concatStringsSep typeOf tryEval attrNames mapAttrs;
cfg = config.vim.autocomplete.blink-cmp;
autocompleteCfg = config.vim.autocomplete;
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 {
vim = mkIf cfg.enable {
lazy.plugins.blink-cmp = {
package = "blink-cmp";
setupModule = "blink.cmp";
inherit (cfg) setupOpts;
# TODO: lazy disabled until lspconfig is lazy loaded
#
# event = ["InsertEnter" "CmdlineEnter"];
startPlugins = ["blink-compat"];
lazy.plugins = {
blink-cmp = {
package = "blink-cmp";
setupModule = "blink.cmp";
inherit (cfg) setupOpts;
# 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 = {
enableSharedCmpSources = true;
blink-cmp.setupOpts = {
sources = {
default = ["lsp" "path" "snippets" "buffer"] ++ (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 {
expand = mkLuaInline ''
function(snippet)

View file

@ -20,7 +20,8 @@ in {
vim = {
startPlugins = ["nvim-treesitter"];
autocomplete = {
# cmp-treesitter doesn't work on blink.cmp
autocomplete = mkIf config.vim.autocomplete.nvim-cmp.enable {
nvim-cmp.sources = {treesitter = "[Treesitter]";};
sourcePlugins = ["cmp-treesitter"];
};