From cab0610450c0dab2b4e5baa36335c288d70ae375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 19 Dec 2024 13:59:35 +0100 Subject: [PATCH] feat(nvim): replace nvim.cmp with blink.cmp --- flake.lock | 213 ++++++++++++++---- flake.nix | 4 + .../programs/nvim/new_plugins/blink-cmp.nix | 63 ++++++ modules/programs/nvim/new_plugins/cmp.nix | 77 ------- 4 files changed, 235 insertions(+), 122 deletions(-) create mode 100644 modules/programs/nvim/new_plugins/blink-cmp.nix delete mode 100644 modules/programs/nvim/new_plugins/cmp.nix diff --git a/flake.lock b/flake.lock index 9c2186d..8991ec2 100644 --- a/flake.lock +++ b/flake.lock @@ -89,6 +89,42 @@ "type": "github" } }, + "blink-cmp": { + "inputs": { + "fenix": "fenix", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1734540692, + "narHash": "sha256-ti83I5Xkou/D+O6oN47OqlZf3zAnAd0a8SwPcQ4gVcQ=", + "owner": "Saghen", + "repo": "blink.cmp", + "rev": "46eb5f3fd3dba0a3bb3d026fb2b7462f4a0656b7", + "type": "github" + }, + "original": { + "owner": "Saghen", + "repo": "blink.cmp", + "type": "github" + } + }, + "blink-compat": { + "flake": false, + "locked": { + "lastModified": 1733256820, + "narHash": "sha256-QW5QG7nqdHdyOodac06Cnq8/WKfbg3YyX/yPh87ENJQ=", + "owner": "Saghen", + "repo": "blink.compat", + "rev": "73249d35c8737b614bed64c2f33277387035f8ec", + "type": "github" + }, + "original": { + "owner": "Saghen", + "repo": "blink.compat", + "type": "github" + } + }, "darwin": { "inputs": { "nixpkgs": [ @@ -113,7 +149,7 @@ }, "devshell": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs_2" }, "locked": { "lastModified": 1728330715, @@ -131,7 +167,7 @@ }, "disko": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1734088167, @@ -147,6 +183,28 @@ "type": "github" } }, + "fenix": { + "inputs": { + "nixpkgs": [ + "blink-cmp", + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1733380458, + "narHash": "sha256-H+IQB6cJ7ji/YD537pcSUWlwGGJ49RoYylBonyNW9hk=", + "owner": "nix-community", + "repo": "fenix", + "rev": "08c9e4e29865b60cb81189f8e4de0dccaf297865", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -244,6 +302,24 @@ } }, "flake-parts_2": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib_2" + }, + "locked": { + "lastModified": 1733312601, + "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_3": { "inputs": { "nixpkgs-lib": [ "neovim-nightly-overlay", @@ -264,7 +340,7 @@ "type": "github" } }, - "flake-parts_3": { + "flake-parts_4": { "inputs": { "nixpkgs-lib": [ "neovim-nightly-overlay", @@ -285,7 +361,7 @@ "type": "indirect" } }, - "flake-parts_4": { + "flake-parts_5": { "inputs": { "nixpkgs-lib": [ "nur", @@ -544,7 +620,7 @@ }, "hercules-ci-effects": { "inputs": { - "flake-parts": "flake-parts_3", + "flake-parts": "flake-parts_4", "nixpkgs": [ "neovim-nightly-overlay", "nixpkgs" @@ -607,7 +683,7 @@ }, "hypr-contrib": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4" }, "locked": { "lastModified": 1733056338, @@ -691,7 +767,7 @@ "hyprlang": "hyprlang", "hyprutils": "hyprutils", "hyprwayland-scanner": "hyprwayland-scanner", - "nixpkgs": "nixpkgs_4", + "nixpkgs": "nixpkgs_5", "pre-commit-hooks": "pre-commit-hooks", "systems": "systems_4", "xdph": "xdph" @@ -954,11 +1030,11 @@ "neovim-nightly-overlay": { "inputs": { "flake-compat": "flake-compat_2", - "flake-parts": "flake-parts_2", + "flake-parts": "flake-parts_3", "git-hooks": "git-hooks", "hercules-ci-effects": "hercules-ci-effects", "neovim-src": "neovim-src", - "nixpkgs": "nixpkgs_5", + "nixpkgs": "nixpkgs_6", "treefmt-nix": "treefmt-nix" }, "locked": { @@ -1127,15 +1203,15 @@ }, "nixpkgs": { "locked": { - "lastModified": 1722073938, - "narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=", - "owner": "NixOS", + "lastModified": 1733229606, + "narHash": "sha256-FLYY5M0rpa5C2QAE3CKLYAM6TwbKicdRK6qNrSHlNrE=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae", + "rev": "566e53c2ad750c84f6d31f9ccb9d00f823165550", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "nixos", "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" @@ -1153,6 +1229,18 @@ "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" } }, + "nixpkgs-lib_2": { + "locked": { + "lastModified": 1733096140, + "narHash": "sha256-1qRH7uAUsyQI7R1Uwl4T+XvdNv778H0Nb5njNrqvylY=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + } + }, "nixpkgs-stable": { "locked": { "lastModified": 1733423277, @@ -1234,6 +1322,22 @@ } }, "nixpkgs_10": { + "locked": { + "lastModified": 1730768919, + "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_11": { "locked": { "lastModified": 1733212471, "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", @@ -1249,7 +1353,7 @@ "type": "github" } }, - "nixpkgs_11": { + "nixpkgs_12": { "locked": { "lastModified": 1692934111, "narHash": "sha256-9EEE59v/esKNMR5zKbLRV9NoRPYvERw5jHQOnfr47bk=", @@ -1266,6 +1370,22 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1722073938, + "narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1733749988, "narHash": "sha256-+5qdtgXceqhK5ZR1YbP1fAUsweBIrhL38726oIEAtDs=", @@ -1281,7 +1401,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1712163089, "narHash": "sha256-Um+8kTIrC19vD4/lUCN9/cU9kcOsD1O1m+axJqQPyMM=", @@ -1297,7 +1417,7 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_5": { "locked": { "lastModified": 1733392399, "narHash": "sha256-kEsTJTUQfQFIJOcLYFt/RvNxIK653ZkTBIs4DG+cBns=", @@ -1313,7 +1433,7 @@ "type": "github" } }, - "nixpkgs_5": { + "nixpkgs_6": { "locked": { "lastModified": 1733749988, "narHash": "sha256-+5qdtgXceqhK5ZR1YbP1fAUsweBIrhL38726oIEAtDs=", @@ -1329,7 +1449,7 @@ "type": "github" } }, - "nixpkgs_6": { + "nixpkgs_7": { "locked": { "lastModified": 1733935885, "narHash": "sha256-xyiHLs6KJ1fxeGmcCxKjJE4yJknVJxbC8Y/ZRYyC8WE=", @@ -1345,7 +1465,7 @@ "type": "github" } }, - "nixpkgs_7": { + "nixpkgs_8": { "locked": { "lastModified": 1733392399, "narHash": "sha256-kEsTJTUQfQFIJOcLYFt/RvNxIK653ZkTBIs4DG+cBns=", @@ -1361,7 +1481,7 @@ "type": "github" } }, - "nixpkgs_8": { + "nixpkgs_9": { "locked": { "lastModified": 1733940404, "narHash": "sha256-Pj39hSoUA86ZePPF/UXiYHHM7hMIkios8TYG29kQT4g=", @@ -1377,22 +1497,6 @@ "type": "github" } }, - "nixpkgs_9": { - "locked": { - "lastModified": 1730768919, - "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "nixvim": { "inputs": { "devshell": [ @@ -1407,7 +1511,7 @@ "home-manager" ], "nix-darwin": "nix-darwin", - "nixpkgs": "nixpkgs_7", + "nixpkgs": "nixpkgs_8", "nuschtosSearch": "nuschtosSearch", "treefmt-nix": "treefmt-nix_2" }, @@ -1427,8 +1531,8 @@ }, "nur": { "inputs": { - "flake-parts": "flake-parts_4", - "nixpkgs": "nixpkgs_8", + "flake-parts": "flake-parts_5", + "nixpkgs": "nixpkgs_9", "treefmt-nix": "treefmt-nix_3" }, "locked": { @@ -1496,7 +1600,7 @@ "inputs": { "flake-compat": "flake-compat_5", "gitignore": "gitignore_4", - "nixpkgs": "nixpkgs_9", + "nixpkgs": "nixpkgs_10", "nixpkgs-stable": "nixpkgs-stable_4" }, "locked": { @@ -1536,9 +1640,11 @@ "agenix": "agenix", "arkenfox-userjs": "arkenfox-userjs", "asus-touchpad-numpad-driver": "asus-touchpad-numpad-driver", + "blink-cmp": "blink-cmp", + "blink-compat": "blink-compat", "devshell": "devshell", "disko": "disko", - "flake-parts": "flake-parts", + "flake-parts": "flake-parts_2", "flake-utils": "flake-utils", "ghostty": "ghostty", "home-manager": "home-manager_2", @@ -1551,7 +1657,7 @@ "nix-index-database": "nix-index-database", "nix-monitored": "nix-monitored", "nixos-facter-modules": "nixos-facter-modules", - "nixpkgs": "nixpkgs_6", + "nixpkgs": "nixpkgs_7", "nixvim": "nixvim", "nur": "nur", "pre-commit-hooks": "pre-commit-hooks_2", @@ -1561,11 +1667,28 @@ "timers": "timers" } }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1733330394, + "narHash": "sha256-1jwtAQYtErSsfkEQFvZJ9wJBrLGltzlvZKZzPXhpfpE=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "f499faf72bcd2abbfbf3d7171e5191100547a3df", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, "search": { "inputs": { "flake-utils": "flake-utils_4", "ixx": "ixx_2", - "nixpkgs": "nixpkgs_10" + "nixpkgs": "nixpkgs_11" }, "locked": { "lastModified": 1733773348, @@ -1705,7 +1828,7 @@ "timers": { "inputs": { "naersk": "naersk", - "nixpkgs": "nixpkgs_11", + "nixpkgs": "nixpkgs_12", "utils": "utils" }, "locked": { diff --git a/flake.nix b/flake.nix index c6a7356..7f925ce 100644 --- a/flake.nix +++ b/flake.nix @@ -45,6 +45,10 @@ nixvim.inputs.flake-parts.follows = "flake-parts"; nixvim.inputs.home-manager.follows = "home-manager"; + blink-cmp.url = "github:Saghen/blink.cmp"; + blink-compat.url = "github:Saghen/blink.compat"; + blink-compat.flake = false; + # river river.url = "git+https://github.com/riverwm/river?submodules=1"; river.flake = false; diff --git a/modules/programs/nvim/new_plugins/blink-cmp.nix b/modules/programs/nvim/new_plugins/blink-cmp.nix new file mode 100644 index 0000000..0a3900c --- /dev/null +++ b/modules/programs/nvim/new_plugins/blink-cmp.nix @@ -0,0 +1,63 @@ +{ lib, pkgs, inputs, ... }: + +{ + home-manager.users.moritz.programs.nixvim = { + extraPlugins = [ + (pkgs.vimUtils.buildVimPlugin { + pname = "blink-compat"; + src = inputs.blink-compat; + version = lib.my.mkVersionInput inputs.blink-compat; + }) + ]; + extraConfigLuaPre = '' + require("blink.compat").setup({ + impersonate_nvim_cmp = true + }) + ''; + plugins.blink-cmp = { + enable = true; + package = inputs.blink-cmp.packages.${pkgs.system}.blink-cmp; + settings = { + keymap = { + "" = [ "hide" ]; + "" = [ "show" "show_documentation" "hide_documentation" ]; + "" = [ "select_next" "fallback" ]; + "" = [ "select_prev" "fallback" ]; + "" = [ "snippet_forward" "fallback" ]; + "" = [ "snippet_backward" "fallback" ]; + "" = [ "accept" "fallback" ]; + cmdline.preset = "super-tab"; + }; + appearance.nerd_font_variant = "mono"; + sources = { + default = [ + "lsp" + "path" + "luasnip" + "buffer" + "vimtex" + ]; + providers.vimtex = { + name = "vimtex"; + module = "blink.compat.source"; + }; + }; + signature.enabled = true; + completion.documentation.auto_show = true; + completion.accept.auto_brackets.enabled = true; + snippets = { + expand.__raw = ''require("luasnip").lsp_expand''; + active.__raw = '' + function(filter) + if filter and filter.direction then + return require('luasnip').jumpable(filter.direction) + end + return require('luasnip').in_snippet() + end + ''; + jump.__raw = ''require("luasnip").jump''; + }; + }; + }; + }; +} diff --git a/modules/programs/nvim/new_plugins/cmp.nix b/modules/programs/nvim/new_plugins/cmp.nix deleted file mode 100644 index b496b6d..0000000 --- a/modules/programs/nvim/new_plugins/cmp.nix +++ /dev/null @@ -1,77 +0,0 @@ -{ config, lib, pkgs, inputs, ... }: - -let - inherit (lib) mkEnableOption mkIf readFile; -in -{ - home-manager.users.moritz.programs.nixvim = { - extraConfigLuaPre = '' - local has_words_before = function() - if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then - return false - end - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_text(0, line-1, 0, line-1, col, {})[1]:match("^%s@*$") == nil - end - ''; - plugins.cmp = { - autoEnableSources = true; - enable = true; - settings.sources = [ - { priority = 1; name = "async_path"; } - { priority = 1; name = "buffer"; } - { priority = 2; name = "nvim_lsp"; } - { priority = 3; name = "nvim_lsp_signature_help"; } - { priority = 4; name = "luasnip"; } - { priority = 4; name = "vimtex"; } - ]; - settings.mapping = { - __raw = '' - cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) - elseif require("luasnip").locally_jumpable(1) and has_words_before() then - require("luasnip").jump(1) - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) - elseif require("luasnip").locally_jumpable(-1) then - require("luasnip").jump(-1) - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if require("luasnip").choice_active() then - require("luasnip").change_choice(1) - elseif require("luasnip").locally_jumpable(1) then - require("luasnip").jump(1) - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if require("luasnip").choice_active() then - require("luasnip").change_choice(-1) - elseif require("luasnip").locally_jumpable(-1) then - require("luasnip").jump(-1) - else - fallback() - end - end, { "i", "s" }), - }) - ''; - }; - }; - }; -}