diff --git a/flake.lock b/flake.lock index 1ec8c65..de0101a 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "blink.compat": { + "flake": false, + "locked": { + "lastModified": 1731176257, + "narHash": "sha256-/2fGykyb8gmAdchCf96udZLuBxN8feWkQ1BlCl5LsIw=", + "owner": "saghen", + "repo": "blink.compat", + "rev": "a951034404c14051129b47e09cfed83f7a306898", + "type": "github" + }, + "original": { + "owner": "saghen", + "repo": "blink.compat", + "type": "github" + } + }, "cargo2nix": { "inputs": { "flake-compat": "flake-compat_2", @@ -1295,6 +1311,7 @@ }, "root": { "inputs": { + "blink.compat": "blink.compat", "comma": "comma", "diagram.nvim": "diagram.nvim", "fioul": "fioul", diff --git a/flake.nix b/flake.nix index c9d6be3..bf0d7d8 100644 --- a/flake.nix +++ b/flake.nix @@ -97,6 +97,10 @@ url = "github:3rd/diagram.nvim/feature/toggle"; flake = false; }; + "blink.compat" = { + url = "github:saghen/blink.compat"; + flake = false; + }; }; outputs = diff --git a/neovim/completion.nix b/neovim/completion.nix index 07f02b4..0c60a13 100644 --- a/neovim/completion.nix +++ b/neovim/completion.nix @@ -1,68 +1,68 @@ +{ pkgs, ... }: { - extraConfigLuaPre = '' - local has_words_before = function() - unpack = unpack or table.unpack - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - local luasnip = require("luasnip") - ''; + extraPlugins = [ pkgs.vimPlugins.blink-compat ]; - plugins.cmp = { - enable = true; - - settings = { - snippet.expand = '' - function(args) - require('luasnip').lsp_expand(args.body) - end + plugins.blink-cmp = { + luaConfig.pre = # lua + '' + require('blink.compat').setup({debug = true}) ''; - mapping = { - "" = "cmp.mapping.confirm({select = true })"; - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.complete()"; - "" = # lua - '' - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() - -- they way you will only jump inside the snippet region - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }) - ''; - "" = # lua - '' - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }) - ''; - "" = "cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), {'i'})"; - "" = "cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), {'i'})"; - }; - sources = [ - { name = "luasnip"; } - { name = "nvim_lsp"; } - { name = "path"; } - { name = "buffer"; } - { name = "calc"; } - { name = "git"; } - { name = "omni"; } + enable = true; + settings = { + keymap = { + preset = "enter"; + "" = [ + "snippet_forward" + "fallback" + ]; + "" = [ + "snippet_backward" + "fallback" + ]; + "" = [ + "select_next" + "fallback" + ]; + "" = [ + "select_prev" + "fallback" + ]; + }; + completion.enabled_providers = [ + "lsp" + "buffer" + "path" + "git" + "calc" + "omni" ]; + # Does not seem to work + providers = { + git = { + name = "git"; + module = "blink.compat.source"; + }; + calc = { + name = "calc"; + module = "blink.compat.source"; + }; + omni = { + name = "omni"; + module = "blink.compat.source"; + }; + }; }; }; + + plugins.lsp.capabilities = # lua + '' + capabilities = require('blink.cmp').get_lsp_capabilities(capabilities) + ''; + + plugins.cmp-omni.enable = true; + plugins.cmp-git.enable = true; + plugins.cmp-calc.enable = true; + + performance.combinePlugins.standalonePlugins = [ "nvim-cmp" ]; } diff --git a/neovim/pkg.nix b/neovim/pkg.nix index a51438a..6964021 100644 --- a/neovim/pkg.nix +++ b/neovim/pkg.nix @@ -37,6 +37,11 @@ src = inputs."diagram.nvim"; version = inputs."diagram.nvim".shortRev; }; + blink-compat = prev.vimUtils.buildVimPlugin { + pname = "blink.compat"; + src = inputs."blink.compat"; + version = inputs."blink.compat".shortRev; + }; } ); }