devos/users/modules/neovim/nvim-lsp.nix

89 lines
2.5 KiB
Nix

{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.mae.nvim;
lspLangConfigType = types.submodule {
options = {
enable = mkEnableOption "Enable named lsp lang config";
script = mkOption {
type = types.lines;
default = "{}";
};
};
};
mkLspLangConfig = name: cfg: ''
local cfg = ${cfg.script}
cfg["capabilities"] = require('cmp_nvim_lsp').default_capabilities()
require'lspconfig'["${name}"].setup(cfg)
'';
mkLspLangConfigs = cfgs: lib.strings.concatStringsSep "\n" ((lib.attrsets.mapAttrsToList mkLspLangConfig cfgs));
in
{
options.mae.nvim.lsp = {
enable = mkEnableOption "Enable lsp support in nvim with nvim-lspconfig and cmp-nvim";
servers = mkOption {
type = types.attrsOf lspLangConfigType;
default = [ ];
};
};
config = mkIf cfg.lsp.enable {
programs.neovim = {
plugins = with pkgs.vimPlugins; [
nvim-snippy
cmp-nvim-lsp
cmp-buffer
cmp-path
cmp-tmux
cmp-snippy
{
plugin = nvim-cmp;
config = ''
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
require('snippy').expand_snippet(args.body)
end,
},
window = {},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'snippy' },
{ name = 'path' }
}, {
{ name = 'buffer' },
{ name= 'tmux' }
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
'';
type = "lua";
}
{
plugin = nvim-lspconfig;
config = mkLspLangConfigs cfg.lsp.servers;
type = "lua";
}
];
};
};
}