modules: add snippet backends
This commit is contained in:
parent
4b85dbd927
commit
b7431ca7d7
7 changed files with 157 additions and 23 deletions
|
@ -18,6 +18,10 @@
|
|||
./modules/plugins/navigation/hop-nvim.nix
|
||||
./modules/plugins/navigation/telescope.nix
|
||||
./modules/plugins/navigation/nvim-tree.nix
|
||||
./modules/plugins/snippet/luasnip.nix
|
||||
./modules/plugins/snippet/snippy.nix
|
||||
./modules/plugins/snippet/ultisnips.nix
|
||||
./modules/plugins/snippet/vsnip.nix
|
||||
./modules/plugins/style/neoformat.nix
|
||||
./modules/plugins/style/nvim-treesitter.nix
|
||||
./modules/plugins/theme/catppuccin.nix
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
let
|
||||
inherit (lib.nix2lua) pipe1 var call call0;
|
||||
cfg = config.plugins.nvim-cmp;
|
||||
|
||||
inherit (config.plugins) snippet language-server;
|
||||
in
|
||||
{
|
||||
options.plugins.nvim-cmp = with lib; {
|
||||
|
@ -16,33 +18,37 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
config = lib.mkIf cfg.enable (lib.mkMerge [
|
||||
{
|
||||
plugin.luasnip = { };
|
||||
plugin.cmp_luasnip = lib.mkDefault { isDependency = true; };
|
||||
|
||||
fn.nvim-cmp-snippet-expand = {
|
||||
args = [ "args" ];
|
||||
content = args: {
|
||||
extra = pipe1
|
||||
(var config.plugin.luasnip.varName)
|
||||
(call "lsp_expand" args);
|
||||
};
|
||||
};
|
||||
|
||||
vim.opt.completeopt = [ "menu" "menuone" "noselect" ];
|
||||
|
||||
plugin.nvim-cmp = {
|
||||
name = "cmp";
|
||||
package = cfg.package;
|
||||
setupSettings = lib.mkMerge [
|
||||
cfg.settings
|
||||
{ snippet.expand = config.fn.nvim-cmp-snippet-expand.lambda; }
|
||||
];
|
||||
};
|
||||
assertions = [
|
||||
{
|
||||
assertion = snippet.luasnip.enable || snippet.snippy.enable || snippet.vsnip.enable || snippet.ultisnips.enable;
|
||||
message = "One of snippet backend (luasnip, snippy, vsnip, ultisnip) is required to use nvim-cmp";
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
(lib.mkIf config.plugins.language-server.lspconfig.enable {
|
||||
# Backend dependencies
|
||||
|
||||
(lib.mkIf snippet.luasnip.enable {
|
||||
plugin.cmp_luasnip = {
|
||||
isDependency = true;
|
||||
};
|
||||
})
|
||||
(lib.mkIf snippet.snippy.enable {
|
||||
plugin.cmp-snippy = { isDependency = true; };
|
||||
})
|
||||
(lib.mkIf snippet.vsnip.enable {
|
||||
plugin.cmp-vsnip = { isDependency = true; };
|
||||
})
|
||||
(lib.mkIf snippet.ultisnips.enable {
|
||||
plugin.cmp-nvim-ultisnips = { isDependency = true; };
|
||||
})
|
||||
|
||||
# Lsp configuration
|
||||
|
||||
(lib.mkIf language-server.lspconfig.enable {
|
||||
plugin.cmp-nvim-lsp = {
|
||||
name = "cmp_nvim_lsp";
|
||||
};
|
||||
|
@ -52,6 +58,51 @@ in
|
|||
(var config.plugin.cmp-nvim-lsp.varName)
|
||||
(call0 "default_capabilities");
|
||||
})
|
||||
|
||||
# Base configuration
|
||||
|
||||
{
|
||||
vim.opt.completeopt = [ "menu" "menuone" "noselect" ];
|
||||
|
||||
fn.nvim-cmp-snippet-expand = {
|
||||
args = [ "args" ];
|
||||
content = { args }:
|
||||
let body = pipe1 args (var "body"); in {
|
||||
extra =
|
||||
if snippet.luasnip.enable then
|
||||
pipe1 (var config.plugin.luasnip.varName) (call "lsp_expand" body)
|
||||
else if snippet.vsnip.enable then
|
||||
call "vim.fn[\"${config.plugin.vim-vsnip.name}#anonymous\"]" body
|
||||
else if snippet.snippy.enable then
|
||||
pipe1 (var config.plugin.nvim-snippy.varName) (call "expand_snipped" body)
|
||||
else if snippet.ultisnips.enable then
|
||||
call "vim.fn[\"${config.plugin.ultisnips.name}#Anon\"]" body
|
||||
else
|
||||
call "vim.snippet.expand" body; # For native neovim snippets (Neovim v0.10+);
|
||||
};
|
||||
};
|
||||
|
||||
plugin.nvim-cmp = rec {
|
||||
name = "cmp";
|
||||
varName = name;
|
||||
package = cfg.package;
|
||||
setupSettings = lib.mkMerge [
|
||||
{
|
||||
mapping = call0 "${varName}.mapping.preset.insert";
|
||||
sources =
|
||||
lib.optional language-server.lspconfig.enable { name = "nvim_lsp"; group_index = 1; }
|
||||
++ lib.optional snippet.luasnip.enable { name = "luasnip"; group_index = 5; }
|
||||
++ lib.optional snippet.snippy.enable { name = "snippy"; group_index = 5; }
|
||||
++ lib.optional snippet.vsnip.enable { name = "vsnip"; group_index = 5; }
|
||||
++ lib.optional snippet.ultisnips.enable { name = "ultisnips"; group_index = 5; }
|
||||
++ [{ name = "buffer"; group_index = 10; max_item_count = 10; }];
|
||||
}
|
||||
cfg.settings
|
||||
{ snippet.expand = config.fn.nvim-cmp-snippet-expand.lambda; }
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
]);
|
||||
|
||||
}
|
||||
|
|
18
modules/plugins/snippet/luasnip.nix
Normal file
18
modules/plugins/snippet/luasnip.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.plugins.snippet.luasnip;
|
||||
in
|
||||
{
|
||||
options.plugins.snippet.luasnip = with lib; {
|
||||
enable = mkEnableOption "luasnip";
|
||||
|
||||
package = mkPackageOption pkgs.vimPlugins "luasnip" { };
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
plugin.luasnip = {
|
||||
inherit (cfg) package;
|
||||
};
|
||||
};
|
||||
}
|
19
modules/plugins/snippet/snippy.nix
Normal file
19
modules/plugins/snippet/snippy.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.plugins.snippet.snippy;
|
||||
in
|
||||
{
|
||||
options.plugins.snippet.snippy = with lib; {
|
||||
enable = mkEnableOption "snippy";
|
||||
|
||||
package = mkPackageOption pkgs.vimPlugins "nvim-snippy" { };
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
plugin.nvim-snippy = {
|
||||
name = "snippy";
|
||||
inherit (cfg) package;
|
||||
};
|
||||
};
|
||||
}
|
20
modules/plugins/snippet/ultisnips.nix
Normal file
20
modules/plugins/snippet/ultisnips.nix
Normal file
|
@ -0,0 +1,20 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.plugins.snippet.ultisnips;
|
||||
in
|
||||
{
|
||||
options.plugins.snippet.ultisnips = with lib; {
|
||||
enable = mkEnableOption "ultisnips";
|
||||
|
||||
package = mkPackageOption pkgs.vimPlugins "ultisnips" { };
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
plugin.ultisnips = {
|
||||
inherit (cfg) package;
|
||||
name = "UltiSnips";
|
||||
isDependency = true;
|
||||
};
|
||||
};
|
||||
}
|
20
modules/plugins/snippet/vsnip.nix
Normal file
20
modules/plugins/snippet/vsnip.nix
Normal file
|
@ -0,0 +1,20 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.plugins.snippet.vsnip;
|
||||
in
|
||||
{
|
||||
options.plugins.snippet.vsnip = with lib; {
|
||||
enable = mkEnableOption "vsnip";
|
||||
|
||||
package = mkPackageOption pkgs.vimPlugins "vim-vsnip" { };
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
plugin.vim-vsnip = {
|
||||
inherit (cfg) package;
|
||||
name = "vsnip";
|
||||
isDependency = true;
|
||||
};
|
||||
};
|
||||
}
|
|
@ -53,6 +53,8 @@ let inherit (lib.nix2lua) nf; in
|
|||
};
|
||||
};
|
||||
|
||||
snippet.luasnip.enable = lib.mkDefault true;
|
||||
|
||||
style = {
|
||||
neoformat.enable = lib.mkDefault true;
|
||||
nvim-treesitter.enable = lib.mkDefault true;
|
||||
|
|
Loading…
Reference in a new issue