From d888dcb9baf1a3967a60045c16fb887de4288391 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 21 Apr 2024 16:00:19 +0300 Subject: [PATCH] modules: add nvim-cmp --- flake.nix | 2 ++ lib/vim.nix | 3 +++ modules/nvim-cmp.nix | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 modules/nvim-cmp.nix diff --git a/flake.nix b/flake.nix index b82ef68..bd64768 100644 --- a/flake.nix +++ b/flake.nix @@ -256,10 +256,12 @@ neoformat = { }; hop-nvim = { }; telescope-nvim = { }; + nvim-cmp = { }; }; plugins = with prev.nix2lua.lib; { editorconfig-nvim = true; + lualine-lsp-progress = true; lualine-nvim = pipe1 (require "lualine") (call "setup" { diff --git a/lib/vim.nix b/lib/vim.nix index 75610a9..5af12e4 100644 --- a/lib/vim.nix +++ b/lib/vim.nix @@ -3,6 +3,9 @@ with nix2lua.lib; { g = varName: expr: set "vim.g.${varName}" expr; + opt = varName: expr: set "vim.opt.${varName}" expr; + + fn' = fnName: args: call "vim.fn[\"${fnName}\"]" args; fn.isdirectory = file: call1 "vim.fn.isdirectory" (var file); cmd' = expr: call1 "vim.cmd" expr; diff --git a/modules/nvim-cmp.nix b/modules/nvim-cmp.nix new file mode 100644 index 0000000..781d452 --- /dev/null +++ b/modules/nvim-cmp.nix @@ -0,0 +1,41 @@ +{ nix2lua, vim, ... }: + +with nix2lua.lib; + +let + defaultCmpKeymaps = { + "" = call "cmp.mapping.scroll_docs" (- 4); + "" = call "cmp.mapping.scroll_docs" 4; + "" = call0 "cmp.mapping.complete"; + "" = call0 "cmp.mapping.abort"; + "" = call "cmp.mapping.confirm" { select = true; }; + }; +in + +{ cmpKeymaps ? defaultCmpKeymaps +, extraCmpKeymaps ? { } +, cmpSources ? { } +}: + +{ + luasnip = true; + cmp-luasnip = true; + + nvim-cmp = [ + (vim.opt "completeopt" [ "menu" "menuone" "noselect" ]) + + (local (set "cmp" (require "cmp"))) + + (pipe1 + (var "cmp") + (call "setup" { + snippet.exand = lambda [ "args" ] + (pipe1 (require "luasnip") (call "lsp_expand" (var "args"))); + + mapping = call "cmp.mapping.preset.insert" (cmpKeymaps // extraCmpKeymaps); + + sources = call "cmp.config.sources" cmpSources; + }) + ) + ]; +}