nixeovim/modules/plugins/nvim-cmp.nix

58 lines
1.3 KiB
Nix
Raw Normal View History

2024-05-09 02:28:24 +03:00
{ config, lib, pkgs, ... }:
let
inherit (lib.nix2lua) pipe1 var call call0;
cfg = config.plugins.nvim-cmp;
in
{
options.plugins.nvim-cmp = with lib; {
enable = mkEnableOption "nvim-cmp";
package = mkPackageOption pkgs.vimPlugins "nvim-cmp" { };
settings = mkOption {
type = types.attrs;
default = { };
};
};
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; }
];
};
}
(lib.mkIf config.plugins.language-server.lspconfig.enable {
plugin.cmp-nvim-lsp = {
name = "cmp_nvim_lsp";
};
plugins.language-server.lspconfig.defaultServerSettings.capabilities =
pipe1
(var config.plugin.cmp-nvim-lsp.varName)
(call0 "default_capabilities");
})
]);
}