From a5dee946a9eb749649d17a9d4cd78271600247d0 Mon Sep 17 00:00:00 2001 From: raf Date: Tue, 18 Mar 2025 20:34:34 +0000 Subject: [PATCH] blink-cmp: apply Nix patch; use new fetcher (#714) * blink-cmp: apply Nix patch; use new fetcher * completion/blink: don't break when modifying built-in sources.providers (#683) * completion/blink-cmp: add missing options **Blink breaks again, 11985891th recorded incident** --------- Co-authored-by: Alfarel --- docs/release-notes/rl-0.8.md | 5 +- flake/legacyPackages/blink-cmp.nix | 22 +++++++-- .../completion/blink-cmp/blink-cmp.nix | 48 ++++++++++++++++--- .../plugins/completion/blink-cmp/config.nix | 19 +++++++- 4 files changed, 80 insertions(+), 14 deletions(-) diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 399e2712..c84ef199 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -244,8 +244,9 @@ syncing of nvim shell environment with direnv's. - Add [blink.cmp] source options and some default-disabled sources. - Add [blink.cmp] option to add - [friendly-snippets](https://github.com/rafamadriz/friendly-snippets) so - blink.cmp can source snippets from it. + [friendly-snippets](https://github.com/rafamadriz/friendly-snippets) + so blink.cmp can source snippets from it. +- Fix [blink.cmp] breaking when built-in sources were modified. [TheColorman](https://github.com/TheColorman): diff --git a/flake/legacyPackages/blink-cmp.nix b/flake/legacyPackages/blink-cmp.nix index 924cb4cc..ba1d7424 100644 --- a/flake/legacyPackages/blink-cmp.nix +++ b/flake/legacyPackages/blink-cmp.nix @@ -5,6 +5,7 @@ git, src, version, + fetchpatch, }: let blink-fuzzy-lib = rustPlatform.buildRustPackage { pname = "blink-fuzzy-lib"; @@ -13,11 +14,10 @@ # TODO: remove this if plugin stops using nightly rust env.RUSTC_BOOTSTRAP = true; + useFetchCargoVendor = true; + cargoHash = "sha256-F1wh/TjYoiIbDY3J/prVF367MKk3vwM7LqOpRobOs7I="; + nativeBuildInputs = [git]; - cargoLock = { - lockFile = "${src}/Cargo.lock"; - allowBuiltinFetchGit = true; - }; }; libExt = @@ -34,5 +34,19 @@ in preInstall = '' mkdir -p target/release ln -s ${blink-fuzzy-lib}/lib/libblink_cmp_fuzzy.${libExt} target/release/libblink_cmp_fuzzy.${libExt} + echo -n "nix" > target/release/version ''; + + # Borrowed from nixpkgs + # TODO: Remove this patch when updating to next version + patches = [ + (fetchpatch { + name = "blink-add-bypass-for-nix.patch"; + url = "https://github.com/Saghen/blink.cmp/commit/6c83ef1ae34abd7ef9a32bfcd9595ac77b61037c.diff?full_index=1"; + hash = "sha256-304F1gDDKVI1nXRvvQ0T1xBN+kHr3jdmwMMp8CNl+GU="; + }) + ]; + + # Module for reproducing issues + nvimSkipModule = ["repro"]; } diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index 4290e1cb..f5e38ed1 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -1,6 +1,6 @@ {lib, ...}: let inherit (lib.options) mkEnableOption mkOption literalMD; - inherit (lib.types) listOf str either attrsOf submodule enum anything int nullOr; + inherit (lib.types) bool listOf str either attrsOf submodule enum anything int nullOr; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.types) mkPluginSetupOption luaInline pluginType; inherit (lib.nvim.binds) mkMappingOption; @@ -21,8 +21,9 @@ freeformType = anything; options = { module = mkOption { - type = str; - description = "module of the provider"; + type = nullOr str; + default = null; + description = "Provider module."; }; }; }; @@ -40,7 +41,7 @@ in { providers = mkOption { type = attrsOf providerType; default = {}; - description = "Settings for completion providers"; + description = "Settings for completion providers."; }; transform_items = mkOption { @@ -63,6 +64,12 @@ in { default = []; description = "List of sources to enable for cmdline. Null means use default source list."; }; + + keymap = mkOption { + type = keymapType; + default = {}; + description = "blink.cmp cmdline keymap"; + }; }; completion = { @@ -74,6 +81,16 @@ in { description = "Delay before auto show triggers"; }; }; + + menu.auto_show = mkOption { + type = bool; + default = true; + description = '' + Manages the appearance of the completion menu. You may prevent the menu + from automatically showing by this option to `false` and manually showing + it with the show keymap command. + ''; + }; }; keymap = mkOption { @@ -103,7 +120,25 @@ in { fuzzy = { prebuilt_binaries = { download = mkBool false '' - Auto-downloads prebuilt binaries. Do not enable, it doesn't work on nix + Auto-downloads prebuilt binaries. + + ::: .{warning} + Do not enable this option, as it does **not work** on Nix! + ::: + ''; + }; + + implementation = mkOption { + type = enum ["lua" "prefer_rust" "rust" "prefer_rust_with_warning"]; + default = "prefer_rust"; + description = '' + fuzzy matcher implementation for Blink. + + * `"lua"`: slower, Lua native fuzzy matcher implementation + * `"rust": use the SIMD fuzzy matcher, 'frizbee' + * `"prefer_rust"`: use the rust implementation, but fall back to lua + * `"prefer_rust_with_warning"`: use the rust implementation, and fall back to lua + if it is not available after emitting a warning. ''; }; }; @@ -122,12 +157,14 @@ in { sourcePlugins = let sourcePluginType = submodule { options = { + enable = mkEnableOption "this source"; package = mkOption { type = pluginType; description = '' `blink-cmp` source plugin package. ''; }; + module = mkOption { type = str; description = '' @@ -136,7 +173,6 @@ in { Should be present in the source's documentation. ''; }; - enable = mkEnableOption "this source"; }; }; in diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix index 875a4fd4..9302332e 100644 --- a/modules/plugins/completion/blink-cmp/config.nix +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -6,8 +6,8 @@ inherit (lib.modules) mkIf; inherit (lib.strings) optionalString; inherit (lib.generators) mkLuaInline; - inherit (lib.attrsets) attrValues filterAttrs; - inherit (lib.lists) map optional; + inherit (lib.attrsets) attrValues filterAttrs mapAttrsToList; + inherit (lib.lists) map optional elem; inherit (lib.nvim.lua) toLuaObject; inherit (builtins) concatStringsSep typeOf tryEval attrNames mapAttrs; @@ -24,7 +24,22 @@ enabledBlinkSources = filterAttrs (_source: definition: definition.enable) cfg.sourcePlugins; blinkSourcePlugins = map (definition: definition.package) (attrValues enabledBlinkSources); + + blinkBuiltins = [ + "path" + "lsp" + "snippets" + "buffer" + "omni" + ]; in { + assertions = + mapAttrsToList (provider: definition: { + assertion = elem provider blinkBuiltins || definition.module != null; + message = "`config.vim.autocomplete.blink-cmp.setupOpts.sources.providers.${provider}.module` is `null`: non-builtin providers must set `module`."; + }) + cfg.setupOpts.sources.providers; + vim = mkIf cfg.enable { startPlugins = ["blink-compat"] ++ blinkSourcePlugins ++ (optional cfg.friendly-snippets.enable "friendly-snippets"); lazy.plugins = {