fix(blink-cmp): Fix broken default sources

Currently, regardless of whether nvim-cmp is enabled, nvim-cmp's sources
are added as providers. If the nvim-cmp sources "buffer" or "path" are
enabled they will override and break blink.cmp's default "path" and
"buffer" sources.

This fixes the issue by only configuring nvim-cmp sources and providers
when nvim-cmp is enabled and, if nvim-cmp is enabled, only configuring
nvim-cmp compat providers that are not in the blink.cmp default sources.
This commit is contained in:
Joshua Manchester 2025-07-28 20:16:50 +01:00
commit 626ad99297
No known key found for this signature in database
2 changed files with 22 additions and 10 deletions

View file

@ -486,3 +486,9 @@
- Add [nvim-biscuits] to show block context. Available at - Add [nvim-biscuits] to show block context. Available at
`vim.utility.nvim-biscuits`. `vim.utility.nvim-biscuits`.
[JManch](https://github.com/JManch):
- Fix default [blink.cmp] sources "path" and "buffer" not working when
`autocomplete.nvim-cmp.enable` was disabled and
`autocomplete.nvim-cmp.sources` had not been modified.

View file

@ -5,11 +5,12 @@
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.attrsets) optionalAttrs;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.attrsets) attrValues filterAttrs mapAttrsToList; inherit (lib.attrsets) attrValues filterAttrs mapAttrsToList;
inherit (lib.lists) map optional elem; inherit (lib.lists) map optional optionals elem;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) concatStringsSep typeOf tryEval attrNames mapAttrs; inherit (builtins) concatStringsSep typeOf tryEval attrNames mapAttrs removeAttrs;
cfg = config.vim.autocomplete.blink-cmp; cfg = config.vim.autocomplete.blink-cmp;
cmpCfg = config.vim.autocomplete.nvim-cmp; cmpCfg = config.vim.autocomplete.nvim-cmp;
@ -55,7 +56,7 @@ in {
after = after =
# lua # lua
'' ''
${optionalString config.vim.lazy.enable ${optionalString (config.vim.lazy.enable && cmpCfg.enable)
(concatStringsSep "\n" (map (concatStringsSep "\n" (map
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
cmpCfg.sourcePlugins))} cmpCfg.sourcePlugins))}
@ -66,7 +67,10 @@ in {
autocomplete = { autocomplete = {
enableSharedCmpSources = true; enableSharedCmpSources = true;
blink-cmp.setupOpts = { blink-cmp.setupOpts = {
sources = { sources = let
# We do not want nvim-cmp compat sources overriding built-in blink sources
filteredCmpSources = removeAttrs cmpCfg.sources blinkBuiltins;
in {
default = default =
[ [
"lsp" "lsp"
@ -74,14 +78,16 @@ in {
"snippets" "snippets"
"buffer" "buffer"
] ]
++ (attrNames cmpCfg.sources) ++ optionals cmpCfg.enable (attrNames filteredCmpSources)
++ (attrNames enabledBlinkSources); ++ (attrNames enabledBlinkSources);
providers = providers =
mapAttrs (name: _: { optionalAttrs cmpCfg.enable (
inherit name; mapAttrs (name: _: {
module = "blink.compat.source"; inherit name;
}) module = "blink.compat.source";
cmpCfg.sources })
filteredCmpSources
)
// (mapAttrs (name: definition: { // (mapAttrs (name: definition: {
inherit name; inherit name;
inherit (definition) module; inherit (definition) module;