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

91 lines
2.5 KiB
Nix
Raw Permalink Normal View History

2022-08-17 22:02:19 +02:00
{ 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: ''
2022-11-19 17:03:50 +01:00
local cfg = ${cfg.script}
cfg["capabilities"] = require('cmp_nvim_lsp').default_capabilities()
require'lspconfig'["${name}"].setup(cfg)
2022-08-17 22:02:19 +02:00
'';
mkLspLangConfigs = cfgs: lib.strings.concatStringsSep "\n" ((lib.attrsets.mapAttrsToList mkLspLangConfig cfgs));
in
{
options.mae.nvim.lsp = {
2023-03-19 14:36:16 +01:00
2022-08-17 22:02:19 +02:00
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; [
2022-11-19 17:03:50 +01:00
nvim-snippy
cmp-nvim-lsp
cmp-buffer
cmp-path
cmp-tmux
cmp-snippy
2022-08-17 22:02:19 +02:00
{
2022-11-19 17:03:50 +01:00
plugin = nvim-cmp;
2022-08-17 22:02:19 +02:00
config = ''
2022-11-19 17:03:50 +01:00
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' },
})
})
2022-08-17 22:02:19 +02:00
'';
type = "lua";
}
{
plugin = nvim-lspconfig;
config = mkLspLangConfigs cfg.lsp.servers;
type = "lua";
}
];
};
};
}