mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2025-01-08 10:19:48 +01:00
cmp: move source plugin into parent option
This commit is contained in:
parent
402eba80b7
commit
e6d0dde3a0
5 changed files with 77 additions and 52 deletions
34
modules/plugins/completion/config.nix
Normal file
34
modules/plugins/completion/config.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) typeOf tryEval;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||
cfg = config.vim.autocomplete;
|
||||
|
||||
getPluginName = plugin:
|
||||
if typeOf plugin == "string"
|
||||
then plugin
|
||||
else if (plugin ? pname && (tryEval plugin.pname).success)
|
||||
then plugin.pname
|
||||
else plugin.name;
|
||||
in {
|
||||
vim = mkIf cfg.enableSharedCmpSources {
|
||||
startPlugins = ["rtp-nvim"];
|
||||
lazy.plugins =
|
||||
mapListToAttrs (package: {
|
||||
name = getPluginName package;
|
||||
value = {
|
||||
inherit package;
|
||||
lazy = true;
|
||||
after = ''
|
||||
local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/${getPluginName package}')
|
||||
require("rtp_nvim").source_after_plugin_dir(path)
|
||||
'';
|
||||
};
|
||||
})
|
||||
cfg.sourcePlugins;
|
||||
};
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
./options.nix
|
||||
|
||||
./nvim-cmp
|
||||
./blink-cmp
|
||||
];
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||
inherit (builtins) attrNames typeOf tryEval concatStringsSep;
|
||||
|
||||
borders = config.vim.ui.borders.plugins.nvim-cmp;
|
||||
|
@ -24,52 +23,39 @@
|
|||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim = {
|
||||
startPlugins = ["rtp-nvim"];
|
||||
lazy.plugins = mkMerge [
|
||||
(mapListToAttrs (package: {
|
||||
name = getPluginName package;
|
||||
value = {
|
||||
inherit package;
|
||||
lazy = true;
|
||||
after = ''
|
||||
local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/${getPluginName package}')
|
||||
require("rtp_nvim").source_after_plugin_dir(path)
|
||||
'';
|
||||
};
|
||||
})
|
||||
cfg.sourcePlugins)
|
||||
{
|
||||
nvim-cmp = {
|
||||
package = "nvim-cmp";
|
||||
after = ''
|
||||
${optionalString luasnipEnable "local luasnip = require('luasnip')"}
|
||||
local cmp = require("cmp")
|
||||
autocomplete.enableSharedCmpSources = true;
|
||||
|
||||
local kinds = require("cmp.types").lsp.CompletionItemKind
|
||||
local deprio = function(kind)
|
||||
return function(e1, e2)
|
||||
if e1:get_kind() == kind then
|
||||
return false
|
||||
end
|
||||
if e2:get_kind() == kind then
|
||||
return true
|
||||
end
|
||||
return nil
|
||||
lazy.plugins = {
|
||||
nvim-cmp = {
|
||||
package = "nvim-cmp";
|
||||
after = ''
|
||||
${optionalString luasnipEnable "local luasnip = require('luasnip')"}
|
||||
local cmp = require("cmp")
|
||||
|
||||
local kinds = require("cmp.types").lsp.CompletionItemKind
|
||||
local deprio = function(kind)
|
||||
return function(e1, e2)
|
||||
if e1:get_kind() == kind then
|
||||
return false
|
||||
end
|
||||
if e2:get_kind() == kind then
|
||||
return true
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
cmp.setup(${toLuaObject cfg.setupOpts})
|
||||
cmp.setup(${toLuaObject cfg.setupOpts})
|
||||
|
||||
${optionalString config.vim.lazy.enable
|
||||
(concatStringsSep "\n" (map
|
||||
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
|
||||
cfg.sourcePlugins))}
|
||||
'';
|
||||
${optionalString config.vim.lazy.enable
|
||||
(concatStringsSep "\n" (map
|
||||
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
|
||||
cfg.sourcePlugins))}
|
||||
'';
|
||||
|
||||
event = ["InsertEnter" "CmdlineEnter"];
|
||||
};
|
||||
}
|
||||
];
|
||||
event = ["InsertEnter" "CmdlineEnter"];
|
||||
};
|
||||
};
|
||||
|
||||
autocomplete.nvim-cmp = {
|
||||
sources = {
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
...
|
||||
}: let
|
||||
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD;
|
||||
inherit (lib.types) str attrsOf nullOr either listOf;
|
||||
inherit (lib.types) str attrsOf nullOr either;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.binds) mkMappingOption;
|
||||
inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf pluginType;
|
||||
inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (builtins) isString;
|
||||
|
||||
|
@ -107,11 +107,5 @@ in {
|
|||
}
|
||||
'';
|
||||
};
|
||||
|
||||
sourcePlugins = mkOption {
|
||||
type = listOf pluginType;
|
||||
default = [];
|
||||
description = "List of source plugins used by nvim-cmp.";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib.options) mkEnableOption;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.types) listOf;
|
||||
inherit (lib.nvim.types) pluginType;
|
||||
in {
|
||||
options.vim.autocomplete = {
|
||||
enableSharedCmpSources = mkEnableOption "cmp sources that can work in nvim-cmp and blink.cmp";
|
||||
enableSharedCmpSources = mkEnableOption "cmp sources shared by nvim-cmp and blink.cmp";
|
||||
|
||||
cmpSourcePlugins = mkOption {
|
||||
type = listOf pluginType;
|
||||
default = [];
|
||||
description = "List of cmp source plugins.";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue