Add cmp and vsnip

This commit is contained in:
buffet 2022-08-25 16:57:02 +00:00
parent 107d956551
commit 8012d0b6ee
3 changed files with 106 additions and 5 deletions

View file

@ -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",

View file

@ -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";

View file

@ -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 <<EOF
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = {
['<c-space>'] = cmp.mapping.confirm({ select = true }),
['<c-p>'] = cmp.mapping.select_prev_item(select_opts),
['<c-n>'] = cmp.mapping.select_next_item(select_opts),
['<c-d>'] = cmp.mapping.scroll_docs(4),
['<c-u>'] = cmp.mapping.scroll_docs(-4),
['<c-e>'] = 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 <<EOF
local lspconfig = require 'lspconfig'
local caps = require 'cmp_nvim_lsp'.update_capabilities(
vim.lsp.protocol.make_client_capabilities()
)
${serverConfigs}
EOF
'';
}
{
@ -161,6 +230,16 @@
'';
}
{
plugin = vim-vsnip;
config = ''
imap <expr> <c-k> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
smap <expr> <c-k> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
imap <expr> <c-j> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
smap <expr> <c-j> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
'';
}
{
plugin = vimwiki;
# TODO: vimwiki config