浏览代码

nixpkgs/neovim: switch to blink.cmp

Thomas Dy 3 周之前
父节点
当前提交
7272aa38c5

+ 92 - 0
.config/nixpkgs/neovim/flake.lock

@@ -1,5 +1,67 @@
 {
   "nodes": {
+    "blink-cmp": {
+      "inputs": {
+        "fenix": "fenix",
+        "flake-parts": "flake-parts",
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1745118754,
+        "narHash": "sha256-a8OWYMmcTpjc3ir2RVQ1LWWXbu75RpmaXc/js9rno3Q=",
+        "owner": "Saghen",
+        "repo": "blink.cmp",
+        "rev": "3ce61ae041927082f962791f59e3aadc774b206c",
+        "type": "github"
+      },
+      "original": {
+        "owner": "Saghen",
+        "repo": "blink.cmp",
+        "type": "github"
+      }
+    },
+    "fenix": {
+      "inputs": {
+        "nixpkgs": [
+          "blink-cmp",
+          "nixpkgs"
+        ],
+        "rust-analyzer-src": "rust-analyzer-src"
+      },
+      "locked": {
+        "lastModified": 1734676450,
+        "narHash": "sha256-iwcxhTVe4h5TqW0HsNiOQP27eMBmbBshF+q2UjEy5aU=",
+        "owner": "nix-community",
+        "repo": "fenix",
+        "rev": "46e19fa0eb3260b2c3ee5b2cf89e73343c1296ab",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "fenix",
+        "type": "github"
+      }
+    },
+    "flake-parts": {
+      "inputs": {
+        "nixpkgs-lib": "nixpkgs-lib"
+      },
+      "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-utils": {
       "inputs": {
         "systems": "systems"
@@ -34,12 +96,42 @@
         "type": "github"
       }
     },
+    "nixpkgs-lib": {
+      "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"
+      }
+    },
     "root": {
       "inputs": {
+        "blink-cmp": "blink-cmp",
         "flake-utils": "flake-utils",
         "nixpkgs": "nixpkgs"
       }
     },
+    "rust-analyzer-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1734622712,
+        "narHash": "sha256-2Oc2LbFypF1EG3zTVIVcuT5XFJ7R3oAwu2tS8B0qQ0I=",
+        "owner": "rust-lang",
+        "repo": "rust-analyzer",
+        "rev": "fe027d79d22f2a7645da4143f5cc0f5f56239b97",
+        "type": "github"
+      },
+      "original": {
+        "owner": "rust-lang",
+        "ref": "nightly",
+        "repo": "rust-analyzer",
+        "type": "github"
+      }
+    },
     "systems": {
       "locked": {
         "lastModified": 1681028828,

+ 6 - 1
.config/nixpkgs/neovim/flake.nix

@@ -4,15 +4,20 @@
   inputs = {
     nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
     flake-utils.url = "github:numtide/flake-utils";
+    blink-cmp = {
+      url = "github:Saghen/blink.cmp";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
   };
 
-  outputs = { self, nixpkgs, flake-utils }:
+  outputs = { self, nixpkgs, flake-utils, blink-cmp }:
     flake-utils.lib.eachDefaultSystem (system:
       let
         pkgs = import nixpkgs {
           inherit system;
           overlays = [(final: prev: {
             node-lsp = final.callPackage ./node-lsp {};
+            blink-cmp = blink-cmp.packages.${system}.blink-cmp;
           })];
         };
       in

+ 0 - 4
.config/nixpkgs/neovim/lsp.lua

@@ -3,10 +3,6 @@ vim.diagnostic.config({
   virtual_text = { severity = { min = vim.diagnostic.severity.WARN } },
 })
 
-vim.lsp.config('*', {
-  capabilities = require('cmp_nvim_lsp').default_capabilities(),
-})
-
 vim.lsp.enable("bashls");
 vim.lsp.enable("eslint");
 

+ 2 - 0
.config/nixpkgs/neovim/neovim.nix

@@ -10,6 +10,7 @@
 , ripgrep
 , html-tidy
 , node-lsp
+, blink-cmp
 , fetchFromGitHub
 , fetchpatch
 , withLuadev ? false
@@ -71,6 +72,7 @@ let
     ++ (lib.attrValues treesitterPlugins)
     ++ [
       extra-treesitter-textobjects
+      blink-cmp
     ] ++ lib.optionals withLuadev [
       pinnedPlugins."bfredl/nvim-luadev"
     ];

+ 24 - 46
.config/nixpkgs/neovim/plugins.lua

@@ -279,55 +279,33 @@ require('treesitter-context').setup({
 })
 
 -- completion
-local cmp = require('cmp')
-local cmp_types = require('cmp.types')
-
-function sort_label(entry1, entry2)
-  local diff = vim.stricmp(entry1.completion_item.label, entry2.completion_item.label)
-  if diff < 0 then
-    return true
-  elseif diff > 0 then
-    return false
-  end
-end
-
-cmp.setup({
-  snippet = {
-    expand = function(args)
-      vim.fn['vsnip#anonymous'](args.body)
-    end,
+require('blink.cmp').setup({
+  cmdline = {
+    enabled = false,
   },
-  mapping = cmp.mapping.preset.insert({
-    ['<C-u>'] = cmp.mapping.scroll_docs(-4),
-    ['<C-d>'] = cmp.mapping.scroll_docs(4),
-    ['<C-Space>'] = cmp.mapping.complete(),
-    ['<C-e>'] = cmp.mapping.abort(),
-    ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
-  }),
-  sources = cmp.config.sources({
-    {
-      name = "nvim_lsp",
-      entry_filter = function(entry, ctx)
-        -- don't autocomplete keywords
-        return cmp_types.lsp.CompletionItemKind[entry:get_kind()] ~= 'Keyword'
-      end
-    },
-    { name = "vsnip" },
-  }),
   completion = {
-    autocomplete = false,
-  },
-  matching = {
-    -- disable non-prefix matching
-    disallow_fuzzy_matching = true,
-    disallow_partial_matching = true,
-    disallow_prefix_unmatching = true,
-  },
-  sorting = {
-    comparators = {
-      -- since we only have prefix matches, just sort the results
-      sort_label,
+    documentation = {
+      auto_show = true,
+      auto_show_delay_ms = 500,
     },
+    trigger = {
+      prefetch_on_insert = false,
+      show_on_keyword = false,
+      show_on_trigger_character = false,
+    },
+    menu = {
+      draw = {
+        columns = {
+          { "label", "label_description", gap = 1 },
+          { "kind" },
+        },
+      },
+    },
+  },
+  keymap = {
+    ['<Enter>'] = { 'select_and_accept', 'fallback' },
+    ['<C-u>'] = { 'scroll_documentation_up', 'fallback_to_mappings' },
+    ['<C-d>'] = { 'scroll_documentation_down', 'fallback_to_mappings' },
   },
 })
 

+ 0 - 16
.config/nixpkgs/neovim/plugins/sources.json

@@ -68,22 +68,6 @@
     "rev": "1ce984c694345f3801bc656072f9a8dd51286a04",
     "sha256": "07q3kss0f6ggil2h4jcfxkwy0gm3q7bl3p4ysy725vnnmhhhlzkx"
   },
-  "hrsh7th/cmp-nvim-lsp": {
-    "rev": "a8912b88ce488f411177fc8aed358b04dc246d7b",
-    "sha256": "08q5mf5jrqjjcl1s4h9zj2vd1kcizz0a5a6p65wv1rc5s1fa3a49"
-  },
-  "hrsh7th/nvim-cmp": {
-    "rev": "b5311ab3ed9c846b585c0c15b7559be131ec4be9",
-    "sha256": "07674djcyac9wlj08y9p5gsmdpsm8zxjfgk3fwyvvx8j7qyzx74p"
-  },
-  "hrsh7th/cmp-vsnip": {
-    "rev": "989a8a73c44e926199bfd05fa7a516d51f2d2752",
-    "sha256": "1hs1gv7q0vfn82pwdwpy46nsi4n5z6yljnzl0rpvwfp8g79hssfs"
-  },
-  "hrsh7th/vim-vsnip": {
-    "rev": "0a4b8419e44f47c57eec4c90df17567ad4b1b36e",
-    "sha256": "141abjf19l2srzniyg3xd8bv7r7zb1ns3mnxpzmqhss7id3vh5mx"
-  },
   "nvim-treesitter/nvim-treesitter": {
     "rev": "684eeac91ed8e297685a97ef70031d19ac1de25a",
     "sha256": "00ccbnnvpcf0lrpbaygzz9wdnf59ixp43z0zry1qvblnjplrlwb7"