modules: add nvim-cmp
This commit is contained in:
parent
538f114300
commit
4b85dbd927
12 changed files with 115 additions and 28 deletions
|
@ -22,6 +22,7 @@
|
|||
./modules/plugins/style/nvim-treesitter.nix
|
||||
./modules/plugins/theme/catppuccin.nix
|
||||
./modules/plugins/gitsigns.nix
|
||||
./modules/plugins/nvim-cmp.nix
|
||||
|
||||
##################################################
|
||||
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
||||
|
|
|
@ -34,22 +34,20 @@ in
|
|||
};
|
||||
|
||||
config.build.neovim = {
|
||||
luaConfig = with lib.nix2lua; toLua (spaceBetween (lib.flatten [
|
||||
luaConfig = with lib; with nix2lua; toLua (spaceBetween (flatten [
|
||||
# Global Opts
|
||||
(lib.flip lib.mapAttrsToList config.vim.g (k: set "vim.g.${k}"))
|
||||
(flip mapAttrsToList config.vim.g (k: set "vim.g.${k}"))
|
||||
# Opts
|
||||
(lib.flip lib.mapAttrsToList config.vim.opt (k: set "vim.opt.${k}"))
|
||||
(flip mapAttrsToList config.vim.opt (k: set "vim.opt.${k}"))
|
||||
# Plugins
|
||||
(map (v: v.genConfig) (filter (v: !v.isDependency) (attrValues config.plugin)))
|
||||
# Cmd
|
||||
(lib.optional (config.vim.cmd != "") (call "vim.cmd" config.vim.cmd))
|
||||
(optional (config.vim.cmd != "") (call "vim.cmd" config.vim.cmd))
|
||||
# Autocommands
|
||||
(lib.flip lib.mapAttrsToList config.vim.augroup (k: v: v.genConfig))
|
||||
(flip mapAttrsToList config.vim.augroup (k: v: v.genConfig))
|
||||
# Keymaps
|
||||
(lib.flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
|
||||
let
|
||||
m = if builtins.isList mode then lib.head mode else mode;
|
||||
in
|
||||
(flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
|
||||
let m = if builtins.isList mode then head mode else mode; in
|
||||
if config.vim.keymap._validate."${m}"."${lhs}" == rhs then vars.genConfig
|
||||
else abort "This case should never happen."
|
||||
))
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib.nix2lua) lambda raw;
|
||||
|
||||
fnOpts = { name, config, ... }: {
|
||||
options = with lib; {
|
||||
args = mkOption {
|
||||
|
@ -32,7 +34,7 @@ let
|
|||
};
|
||||
|
||||
config = {
|
||||
lambda = with lib.nix2lua;
|
||||
lambda =
|
||||
let
|
||||
fnArgs = builtins.listToAttrs (map (v: { name = v; value = raw v; }) config.args);
|
||||
innerCfg = config.content fnArgs;
|
||||
|
|
|
@ -61,11 +61,11 @@ let
|
|||
name = lib.mkDefault name;
|
||||
varName = lib.mkDefault (builtins.replaceStrings [ "-" "/" "." ] [ "_" "_" "_" ] config.name);
|
||||
|
||||
genConfig = with lib.nix2lua; lib.mkIf (!config.isDependency) (lib.flatten [
|
||||
genConfig = with lib; with nix2lua; mkIf (!config.isDependency) (flatten [
|
||||
(local (set config.varName (require config.name)))
|
||||
(lib.mapAttrsToList (k: v: local (set k (require v))) config.extraImports)
|
||||
(mapAttrsToList (k: v: local (set k (require v))) config.extraImports)
|
||||
config.beforeSetup
|
||||
(lib.optional (config.setupSettings != null)
|
||||
(optional (config.setupSettings != null)
|
||||
(pipe1 (var config.varName) (call config.setupFnName config.setupSettings))
|
||||
)
|
||||
config.afterSetup
|
||||
|
@ -78,9 +78,8 @@ let
|
|||
|
||||
in
|
||||
{
|
||||
options.plugin = with lib; with types; mkOption {
|
||||
type = attrsOf (submodule pluginOpts);
|
||||
options.plugin = with lib; mkOption {
|
||||
type = with types; attrsOf (submodule pluginOpts);
|
||||
default = { };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib.nix2lua) pipe pipe1 var set call;
|
||||
cfg = config.plugins.language-server.lspconfig;
|
||||
in
|
||||
{
|
||||
|
@ -12,6 +13,16 @@ in
|
|||
serverSettings = mkOption {
|
||||
type = with types; attrsOf attrs;
|
||||
default = { };
|
||||
description = ''
|
||||
Server-specific settings.
|
||||
|
||||
`:help lspconfig-setup`
|
||||
'';
|
||||
};
|
||||
|
||||
defaultServerSettings = mkOption {
|
||||
type = with types; nullOr attrs;
|
||||
default = null;
|
||||
};
|
||||
|
||||
keymap.set = mkOption {
|
||||
|
@ -23,7 +34,7 @@ in
|
|||
config = lib.mkIf cfg.enable {
|
||||
fn.lspconfig-on-attach = {
|
||||
args = [ "event" ];
|
||||
content = with lib.nix2lua; { event }: {
|
||||
content = { event }: {
|
||||
vim.keymap.set = map
|
||||
(attrs: attrs // { buffer = pipe1 event (var "buf"); })
|
||||
cfg.keymap.set;
|
||||
|
@ -35,13 +46,24 @@ in
|
|||
callback = config.fn.lspconfig-on-attach.lambda;
|
||||
};
|
||||
|
||||
plugin.nvim-lspconfig = {
|
||||
plugin.nvim-lspconfig = rec {
|
||||
name = "lspconfig";
|
||||
varName = name;
|
||||
package = cfg.package;
|
||||
afterSetup = with lib.nix2lua; lib.mapAttrsToList
|
||||
beforeSetup =
|
||||
let varDefaultConfig = var "${varName}.util.default_config"; in
|
||||
lib.optional (cfg.defaultServerSettings != null) (set
|
||||
varDefaultConfig
|
||||
(call "vim.tbl_extend" [
|
||||
"force"
|
||||
varDefaultConfig
|
||||
cfg.defaultServerSettings
|
||||
])
|
||||
);
|
||||
afterSetup = lib.mapAttrsToList
|
||||
(ls: lsSettings:
|
||||
pipe [
|
||||
(var "lspconfig")
|
||||
(var varName)
|
||||
(var ls)
|
||||
(call "setup" lsSettings)
|
||||
]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib.nix2lua) var;
|
||||
cfg = config.plugins.navigation.hop-nvim;
|
||||
in
|
||||
{
|
||||
|
@ -48,7 +49,7 @@ in
|
|||
setupSettings = cfg.settings;
|
||||
};
|
||||
|
||||
vim.keymap.set = with lib.nix2lua; cfg.keymap.set {
|
||||
vim.keymap.set = cfg.keymap.set {
|
||||
after = var "hop_hint.HintDirection.AFTER_CURSOR";
|
||||
before = var "hop_hint.HintDirection.BEFORE_CURSOR";
|
||||
};
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let cfg = config.plugins.navigation.nvim-tree; in
|
||||
|
||||
let
|
||||
inherit (lib.nix2lua) require pipe var call;
|
||||
cfg = config.plugins.navigation.nvim-tree;
|
||||
in
|
||||
{
|
||||
options.plugins.navigation.nvim-tree = with lib; {
|
||||
enable = mkEnableOption "nvim-tree";
|
||||
|
@ -40,7 +42,7 @@ let cfg = config.plugins.navigation.nvim-tree; in
|
|||
fn.nvim-tree-lua-on-attach = lib.mkIf (cfg.keymap.set != [ ]) {
|
||||
args = [ "bufnr" ];
|
||||
content = { bufnr }: {
|
||||
extra = with lib.nix2lua; lib.mkIf cfg.keymap.withDefault pipe [
|
||||
extra = lib.mkIf cfg.keymap.withDefault pipe [
|
||||
(require "nvim-tree.api")
|
||||
(var "config")
|
||||
(var "mappings")
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
let
|
||||
inherit (builtins) match isFunction attrValues;
|
||||
inherit (lib.nix2lua) pipe1 var call;
|
||||
|
||||
cfg = config.plugins.navigation.telescope;
|
||||
|
||||
|
@ -38,7 +39,7 @@ let
|
|||
|
||||
config = {
|
||||
name = lib.mkDefault name;
|
||||
loadExtension = with lib.nix2lua; lib.mkDefault (pipe1
|
||||
loadExtension = lib.mkDefault (pipe1
|
||||
(var config.plugin.telescope-nvim.varName)
|
||||
(call "load_extension" sub.config.name)
|
||||
);
|
||||
|
|
57
modules/plugins/nvim-cmp.nix
Normal file
57
modules/plugins/nvim-cmp.nix
Normal file
|
@ -0,0 +1,57 @@
|
|||
{ 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");
|
||||
})
|
||||
]);
|
||||
|
||||
}
|
|
@ -83,12 +83,12 @@ in
|
|||
name = "nvim-treesitter.configs";
|
||||
package = finalNvimTreeSitter;
|
||||
|
||||
beforeSetup = with lib.nix2lua; lib.optionals (cfg.extraGrammars != { }) (lib.flatten [
|
||||
beforeSetup = with lib; with nix2lua; optionals (cfg.extraGrammars != { }) (flatten [
|
||||
(local (set "parser_config")
|
||||
(pipe1 (require "nvim-treesitter.parsers") (call0 "get_parser_configs"))
|
||||
)
|
||||
|
||||
(lib.mapAttrsToList (k: v: set "parser_config.${v.language}" { }) cfg.extraGrammars)
|
||||
(mapAttrsToList (k: v: set "parser_config.${v.language}" { }) cfg.extraGrammars)
|
||||
]);
|
||||
|
||||
setupSettings = lib.mkMerge [
|
||||
|
|
|
@ -66,5 +66,7 @@ let inherit (lib.nix2lua) nf; in
|
|||
};
|
||||
|
||||
gitsigns.enable = lib.mkDefault true;
|
||||
|
||||
nvim-cmp.enable = lib.mkDefault true;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
|
||||
let
|
||||
inherit (lib.nix2lua) call;
|
||||
|
||||
augroupsCfg = config.vim.augroup;
|
||||
|
||||
autocmd = { name, config, ... }: {
|
||||
|
@ -86,7 +88,7 @@ let
|
|||
config = {
|
||||
group = lib.mkDefault name;
|
||||
|
||||
genConfig = with lib.nix2lua; call "vim.api.nvim_create_autocmd" [
|
||||
genConfig = call "vim.api.nvim_create_autocmd" [
|
||||
config.event
|
||||
{
|
||||
inherit (config) pattern buffer desc callback command once nested;
|
||||
|
|
Loading…
Reference in a new issue