From 8012d0b6eec68a514a8f3e5404369e51f2b17044 Mon Sep 17 00:00:00 2001 From: buffet Date: Thu, 25 Aug 2022 16:57:02 +0000 Subject: [PATCH] Add cmp and vsnip --- flake.lock | 17 +++++++++ flake.nix | 5 +++ programs/nvim.nix | 89 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 106 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index e39e439..32bb8e3 100644 --- a/flake.lock +++ b/flake.lock @@ -20,6 +20,22 @@ "type": "github" } }, + "cmp-git": { + "flake": false, + "locked": { + "lastModified": 1659918460, + "narHash": "sha256-/fHoZxtJFG9v1sw/rQU2fa0ybO7bIovvRvY6M/mU5sc=", + "owner": "petertriho", + "repo": "cmp-git", + "rev": "fae6cdb407ad6c63a0b1928670bad1a67a55b887", + "type": "github" + }, + "original": { + "owner": "petertriho", + "repo": "cmp-git", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -91,6 +107,7 @@ "root": { "inputs": { "agenix": "agenix", + "cmp-git": "cmp-git", "home-manager": "home-manager", "impermanence": "impermanence", "lsp-trouble": "lsp-trouble", diff --git a/flake.nix b/flake.nix index 7dea385..caae3bb 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,11 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + cmp-git = { + url = "github:petertriho/cmp-git"; + flake = false; + }; + home-manager = { url = "github:nix-community/home-manager/release-22.05"; inputs.nixpkgs.follows = "nixpkgs"; diff --git a/programs/nvim.nix b/programs/nvim.nix index b41afa6..6a2cbf7 100644 --- a/programs/nvim.nix +++ b/programs/nvim.nix @@ -8,7 +8,6 @@ EDITOR = "nvim"; }; - # TODO: completion programs.neovim = let leader = ","; in { @@ -20,11 +19,22 @@ src = inputs."${name}"; }; buildPlugins = names: lib.attrsets.genAttrs names buildPlugin; - plugins = buildPlugins ["lsp-trouble"]; + plugins = buildPlugins [ + "cmp-git" + "lsp-trouble" + ]; in with pkgs.vimPlugins; with plugins; [ + {plugin = cmp-buffer;} + {plugin = cmp-calc;} + {plugin = cmp-latex-symbols;} + {plugin = cmp-nvim-lsp;} + {plugin = cmp-path;} + {plugin = cmp-treesitter;} + {plugin = cmp-vsnip;} {plugin = editorconfig-nvim;} + {plugin = friendly-snippets;} {plugin = fugitive;} {plugin = lsp-trouble;} {plugin = rust-vim;} @@ -32,6 +42,11 @@ {plugin = vim-nix;} {plugin = vim-repeat;} + { + plugin = cmp-git; + config = "lua require 'cmp_git'.setup()"; + } + { plugin = crates-nvim; config = '' @@ -100,16 +115,70 @@ config = "lua require 'nvim-autopairs'.setup {}"; } + { + plugin = nvim-cmp; + config = '' + set completeopt=menu,menuone,noselect + + lua <'] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.select_prev_item(select_opts), + [''] = cmp.mapping.select_next_item(select_opts), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.abort(), + }, + sources = cmp.config.sources { + { name = 'buffer' }, + { name = 'calc' }, + { name = 'crates' }, + { name = 'git' }, + { name = 'latex_symbols' }, + { name = 'nvim_lsp' }, + { name = 'path' }, + { name = 'treesitter' }, + { name = 'vsnip' }, + }, + } + EOF + ''; + } + { plugin = nvim-lspconfig; config = let - configure = srv: "lua require 'lspconfig'.${srv}.setup {}"; + configure = srv: '' + lspconfig.${srv}.setup { + capabilities = caps, + } + ''; servers = [ "clangd" "rust_analyzer" ]; - in - lib.strings.concatStringsSep "\n" (builtins.map configure servers); + serverConfigs = lib.strings.concatStringsSep "\n" (builtins.map configure servers); + in '' + lua < vsnip#jumpable(1) ? '(vsnip-jump-next)' : '' + smap vsnip#jumpable(1) ? '(vsnip-jump-next)' : '' + imap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' + smap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' + ''; + } + { plugin = vimwiki; # TODO: vimwiki config