2025-05-11 18:34:41 +03:00
|
|
|
{ lib, pkgs, ... }:
|
2024-07-14 17:46:01 +03:00
|
|
|
let
|
2025-05-11 18:34:41 +03:00
|
|
|
pluginStubs = pkgs.callPackage ../../../utils/plugin-stubs.nix { };
|
2024-07-19 16:35:17 +03:00
|
|
|
|
2025-04-28 16:59:09 +03:00
|
|
|
# Assertion for a number of plugins of given type defined in nvimPackage.packpathDirs
|
|
|
|
expectNPlugins =
|
|
|
|
config: type: n:
|
|
|
|
let
|
|
|
|
# 'build.extraFiles' must not be combined, so exclude it from counting
|
|
|
|
plugins = builtins.filter (
|
|
|
|
p: p != config.build.extraFiles
|
|
|
|
) config.build.nvimPackage.packpathDirs.myNeovimPackages.${type};
|
|
|
|
numPlugins = builtins.length plugins;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
assertion = numPlugins == n;
|
|
|
|
message = "Expected ${toString n} '${type}' plugins defined in 'nvimPackage.packpathDirs', got ${toString numPlugins}: ${
|
|
|
|
lib.concatMapStringsSep ", " lib.getName plugins
|
|
|
|
}.";
|
|
|
|
};
|
|
|
|
# Assertion that exactly one start plugin is defined in nvimPackage.packpathDirs
|
|
|
|
expectOneStartPlugin = config: expectNPlugins config "start" 1;
|
2024-07-14 17:46:01 +03:00
|
|
|
in
|
2024-07-07 20:22:39 +03:00
|
|
|
{
|
|
|
|
# Test basic functionality
|
2024-08-20 00:54:50 +01:00
|
|
|
default =
|
2024-07-07 20:22:39 +03:00
|
|
|
{ config, ... }:
|
|
|
|
{
|
|
|
|
performance.combinePlugins.enable = true;
|
2025-05-11 18:34:41 +03:00
|
|
|
extraPlugins = pluginStubs.pluginPack;
|
|
|
|
extraConfigLuaPost = ''
|
|
|
|
${pluginStubs.pluginChecks}
|
2024-07-07 20:22:39 +03:00
|
|
|
|
2025-05-11 18:34:41 +03:00
|
|
|
-- No separate plugin entry in vim.api.nvim_list_runtime_paths()
|
|
|
|
${lib.concatMapStrings (
|
|
|
|
name: # lua
|
|
|
|
''
|
|
|
|
assert(not vim.iter(vim.api.nvim_list_runtime_paths()):any(function(entry)
|
|
|
|
return entry:find("${name}", 1, true)
|
|
|
|
end), "plugin '${name}' found in runtime, expected to be combined")
|
|
|
|
'') pluginStubs.pluginNames}
|
|
|
|
'';
|
2024-07-07 20:22:39 +03:00
|
|
|
assertions = [
|
2025-04-28 16:59:09 +03:00
|
|
|
(expectOneStartPlugin config)
|
2024-07-07 20:22:39 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Test disabled option
|
2024-08-20 00:54:50 +01:00
|
|
|
disabled =
|
2024-07-07 20:22:39 +03:00
|
|
|
{ config, ... }:
|
|
|
|
{
|
|
|
|
performance.combinePlugins.enable = false;
|
2025-05-11 18:34:41 +03:00
|
|
|
extraPlugins = pluginStubs.pluginPack;
|
2025-04-27 17:49:29 +03:00
|
|
|
extraConfigLuaPost = lib.concatMapStringsSep "\n" (
|
|
|
|
name:
|
|
|
|
# lua
|
|
|
|
''
|
|
|
|
-- Separate plugin entry in vim.api.nvim_list_runtime_paths()
|
|
|
|
assert(vim.iter(vim.api.nvim_list_runtime_paths()):any(function(entry)
|
|
|
|
return entry:find("${name}", 1, true)
|
|
|
|
end), "plugin '${name}' isn't found in runtime as a separate entry, expected not to be combined")
|
2025-05-11 18:34:41 +03:00
|
|
|
'') pluginStubs.pluginNames;
|
2024-07-07 20:22:39 +03:00
|
|
|
assertions = [
|
2025-05-11 18:34:41 +03:00
|
|
|
(expectNPlugins config "start" (builtins.length pluginStubs.pluginPack))
|
2024-07-07 20:22:39 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Test that pathsToLink option works
|
2024-08-20 00:54:50 +01:00
|
|
|
paths-to-link =
|
2024-07-07 20:22:39 +03:00
|
|
|
{ config, ... }:
|
|
|
|
{
|
|
|
|
performance.combinePlugins = {
|
|
|
|
enable = true;
|
2025-04-27 17:49:29 +03:00
|
|
|
pathsToLink = [ "/_extra" ];
|
2024-07-07 20:22:39 +03:00
|
|
|
};
|
2025-05-11 18:34:41 +03:00
|
|
|
extraPlugins = [
|
|
|
|
# A plugin with extra directory
|
|
|
|
(pluginStubs.mkPlugin "extra" {
|
|
|
|
postInstall = ''
|
|
|
|
mkdir $out/_extra
|
|
|
|
touch $out/_extra/test
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
2024-07-07 20:22:39 +03:00
|
|
|
extraConfigLuaPost = ''
|
2025-05-11 18:34:41 +03:00
|
|
|
${pluginStubs.pluginChecksFor [ "extra" ]}
|
|
|
|
|
2025-04-27 17:49:29 +03:00
|
|
|
-- Test file is in runtime
|
2024-07-07 20:22:39 +03:00
|
|
|
assert(
|
2025-04-27 17:49:29 +03:00
|
|
|
vim.api.nvim_get_runtime_file("_extra/test", false)[1],
|
|
|
|
"'_extra/test' file isn't found in runtime, expected to be found"
|
2024-07-07 20:22:39 +03:00
|
|
|
)
|
|
|
|
'';
|
|
|
|
assertions = [
|
2025-04-28 16:59:09 +03:00
|
|
|
(expectOneStartPlugin config)
|
2024-07-07 20:22:39 +03:00
|
|
|
];
|
|
|
|
};
|
2024-07-14 11:38:41 +03:00
|
|
|
|
2024-07-14 16:10:58 +03:00
|
|
|
# Test that optional plugins are handled
|
2024-08-20 00:54:50 +01:00
|
|
|
optional-plugins =
|
2024-07-14 16:10:58 +03:00
|
|
|
{ config, ... }:
|
|
|
|
{
|
|
|
|
performance.combinePlugins.enable = true;
|
2025-05-11 18:34:41 +03:00
|
|
|
extraPlugins = with pluginStubs; [
|
2024-07-14 16:10:58 +03:00
|
|
|
# Start plugins
|
2025-05-11 18:34:41 +03:00
|
|
|
plugin1
|
|
|
|
plugin3
|
2024-07-14 16:10:58 +03:00
|
|
|
# Optional plugin
|
|
|
|
{
|
2025-05-11 18:34:41 +03:00
|
|
|
plugin = plugin2;
|
2024-07-14 16:10:58 +03:00
|
|
|
optional = true;
|
|
|
|
}
|
2025-05-11 18:34:41 +03:00
|
|
|
# Optional plugin with dependencies on plugin3 and plugin4
|
2024-07-14 16:10:58 +03:00
|
|
|
# Dependencies should not be duplicated
|
|
|
|
{
|
2025-05-11 18:34:41 +03:00
|
|
|
plugin = pluginWithDep4;
|
2024-07-14 16:10:58 +03:00
|
|
|
optional = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
extraConfigLuaPost = ''
|
2025-05-11 18:34:41 +03:00
|
|
|
-- Start plugins are working. Dependencies of the optional plugins are also available.
|
|
|
|
${pluginStubs.pluginChecksFor [
|
|
|
|
"plugin1"
|
|
|
|
"plugin3"
|
|
|
|
"plugin4" # Dependency of the optional plugin
|
|
|
|
]}
|
2024-07-14 16:10:58 +03:00
|
|
|
|
2025-05-11 18:34:41 +03:00
|
|
|
-- Lua libraries are available. Libs of the optional plugins are also available.
|
|
|
|
${pluginStubs.libChecksFor [
|
|
|
|
"lib1"
|
|
|
|
"lib2" # Dependency of the optional plugin
|
|
|
|
"lib3"
|
|
|
|
]}
|
2024-07-14 16:10:58 +03:00
|
|
|
|
2025-05-11 18:34:41 +03:00
|
|
|
${lib.concatMapStrings
|
|
|
|
(
|
|
|
|
name: # lua
|
|
|
|
''
|
|
|
|
-- Optional plugin is not loadable
|
|
|
|
local ok = pcall(require, "${name}")
|
|
|
|
assert(not ok, "${name} is loadable, expected it to be an opt plugin")
|
2024-07-14 16:10:58 +03:00
|
|
|
|
2025-05-11 18:34:41 +03:00
|
|
|
-- Load plugin
|
|
|
|
vim.cmd.packadd("${name}")
|
2024-07-14 16:10:58 +03:00
|
|
|
|
2025-05-11 18:34:41 +03:00
|
|
|
-- Now opt plugin is working
|
|
|
|
${pluginStubs.pluginChecksFor [ name ]}
|
|
|
|
'')
|
|
|
|
[
|
|
|
|
"plugin2"
|
|
|
|
"plugin_with_dep4"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Only one copy of dependent plugin should be available
|
|
|
|
${lib.concatMapStrings
|
|
|
|
(
|
|
|
|
name: # lua
|
|
|
|
''
|
|
|
|
local num_plugins = #vim.api.nvim_get_runtime_file("lua/${name}/init.lua", true)
|
|
|
|
assert(num_plugins == 1, "expected 1 copy of ${name}, got " .. num_plugins)
|
|
|
|
'')
|
|
|
|
[
|
|
|
|
"plugin3"
|
|
|
|
"plugin4"
|
|
|
|
]
|
|
|
|
}
|
2024-07-14 16:10:58 +03:00
|
|
|
'';
|
2024-07-14 17:46:01 +03:00
|
|
|
assertions = [
|
2025-04-28 16:59:09 +03:00
|
|
|
(expectOneStartPlugin config)
|
2025-05-11 18:34:41 +03:00
|
|
|
# plugin2 plugin_with_dep4
|
2025-04-28 16:59:09 +03:00
|
|
|
(expectNPlugins config "opt" 2)
|
2024-07-14 17:46:01 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Test that plugin configs are handled
|
2024-08-20 00:54:50 +01:00
|
|
|
configs =
|
2024-07-14 17:46:01 +03:00
|
|
|
{ config, ... }:
|
|
|
|
{
|
|
|
|
performance.combinePlugins.enable = true;
|
2025-05-11 18:34:41 +03:00
|
|
|
extraPlugins = with pluginStubs; [
|
2024-07-14 17:46:01 +03:00
|
|
|
# A plugin without config
|
2025-05-11 18:34:41 +03:00
|
|
|
plugin1
|
|
|
|
# A plugin with config
|
2024-07-14 17:46:01 +03:00
|
|
|
{
|
2025-05-11 18:34:41 +03:00
|
|
|
plugin = plugin2;
|
|
|
|
config = "let g:plugin2_var = 1";
|
2024-07-14 17:46:01 +03:00
|
|
|
}
|
|
|
|
# Optional plugin with config
|
|
|
|
{
|
2025-05-11 18:34:41 +03:00
|
|
|
plugin = plugin3;
|
2024-07-14 17:46:01 +03:00
|
|
|
optional = true;
|
2025-05-11 18:34:41 +03:00
|
|
|
config = "let g:plugin3_var = 1";
|
2024-07-14 17:46:01 +03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
extraConfigLuaPost = ''
|
|
|
|
-- Configs are evaluated
|
2025-05-11 18:34:41 +03:00
|
|
|
assert(vim.g.plugin2_var == 1, "plugin2's config isn't evaluated")
|
|
|
|
assert(vim.g.plugin3_var == 1, "plugin3's config isn't evaluated")
|
2024-07-14 17:46:01 +03:00
|
|
|
'';
|
|
|
|
assertions = [
|
2025-04-28 16:59:09 +03:00
|
|
|
(expectOneStartPlugin config)
|
2024-07-19 16:35:17 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-09-24 07:02:22 +01:00
|
|
|
# Test that config.build.extraFiles is not combined
|
2024-08-20 00:54:50 +01:00
|
|
|
files-plugin =
|
2024-07-19 16:35:17 +03:00
|
|
|
{ config, ... }:
|
|
|
|
{
|
|
|
|
performance.combinePlugins.enable = true;
|
2025-05-11 18:34:41 +03:00
|
|
|
extraPlugins = with pluginStubs; [
|
|
|
|
plugin1
|
|
|
|
plugin2
|
2024-07-19 16:35:17 +03:00
|
|
|
];
|
2025-04-27 17:49:29 +03:00
|
|
|
# Ensure that build.extraFiles is added to extraPlugins
|
2024-07-19 16:35:17 +03:00
|
|
|
wrapRc = true;
|
|
|
|
# Extra user files colliding with plugins
|
|
|
|
extraFiles = {
|
2025-05-11 18:34:41 +03:00
|
|
|
"lua/plugin1/init.lua".text = "return 1";
|
2024-07-19 16:35:17 +03:00
|
|
|
};
|
|
|
|
# Another form of user files
|
|
|
|
files = {
|
2025-05-11 18:34:41 +03:00
|
|
|
"lua/plugin2/init.lua" = {
|
2025-04-27 17:49:29 +03:00
|
|
|
extraConfigLua = "return 1";
|
2024-07-19 16:35:17 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
extraConfigLuaPost = ''
|
2025-05-11 18:34:41 +03:00
|
|
|
for _, file in ipairs({"lua/plugin1/init.lua", "lua/plugin2/init.lua"}) do
|
2025-04-27 17:49:29 +03:00
|
|
|
local paths_found = vim.api.nvim_get_runtime_file(file, true)
|
|
|
|
local num_found = #paths_found
|
2024-07-19 16:35:17 +03:00
|
|
|
|
2025-04-27 17:49:29 +03:00
|
|
|
-- Both plugin and user version are available
|
|
|
|
assert(num_found == 2, "expected exactly 2 versions of '" .. file .. "', got " .. num_found)
|
2024-07-19 16:35:17 +03:00
|
|
|
|
2025-04-27 17:49:29 +03:00
|
|
|
-- First found file is from build.extraFiles
|
|
|
|
assert(
|
|
|
|
paths_found[1]:find("${lib.getName config.build.extraFiles}", 1, true),
|
|
|
|
"expected first found '" .. file .. "' to be from build.extraFiles, got " .. paths_found[1]
|
|
|
|
)
|
|
|
|
end
|
2024-07-19 16:35:17 +03:00
|
|
|
'';
|
|
|
|
assertions = [
|
2025-04-28 16:59:09 +03:00
|
|
|
(expectOneStartPlugin config)
|
2024-07-14 17:46:01 +03:00
|
|
|
];
|
2024-07-14 16:10:58 +03:00
|
|
|
};
|
2024-07-19 16:31:12 +03:00
|
|
|
|
|
|
|
# Test that standalonePlugins option works
|
2024-08-20 00:54:50 +01:00
|
|
|
standalone-plugins =
|
2024-07-19 16:31:12 +03:00
|
|
|
{ config, ... }:
|
2025-05-11 18:34:41 +03:00
|
|
|
let
|
|
|
|
standalonePlugins = [
|
|
|
|
# By plugin name
|
|
|
|
"plugin1"
|
|
|
|
# By package itself. Its dependency, plugin4, not in this list, so will be combined
|
|
|
|
pluginStubs.pluginWithDep4
|
|
|
|
# Dependency of other plugin
|
|
|
|
"plugin5"
|
|
|
|
# Both dependency and top-level plugin
|
|
|
|
"plugin3"
|
|
|
|
];
|
|
|
|
in
|
2024-07-19 16:31:12 +03:00
|
|
|
{
|
|
|
|
performance.combinePlugins = {
|
|
|
|
enable = true;
|
2025-05-11 18:34:41 +03:00
|
|
|
inherit standalonePlugins;
|
2024-07-19 16:31:12 +03:00
|
|
|
};
|
2025-05-11 18:34:41 +03:00
|
|
|
extraPlugins = pluginStubs.pluginPack;
|
2024-07-19 16:31:12 +03:00
|
|
|
extraConfigLuaPost = ''
|
2025-05-11 18:34:41 +03:00
|
|
|
${pluginStubs.pluginChecks}
|
2024-07-19 16:31:12 +03:00
|
|
|
|
2025-05-11 18:34:41 +03:00
|
|
|
${lib.concatMapStringsSep "\n" (
|
|
|
|
name:
|
|
|
|
let
|
|
|
|
isStandalone = builtins.elem name (
|
|
|
|
map (x: if builtins.isString x then x else lib.getName x) standalonePlugins
|
|
|
|
);
|
|
|
|
expectedText = if isStandalone then "standalone" else "combined";
|
|
|
|
in
|
|
|
|
# lua
|
|
|
|
''
|
|
|
|
-- Check that ${name} plugin is ${expectedText}
|
|
|
|
local paths = vim.api.nvim_get_runtime_file("lua/${name}", true)
|
|
|
|
-- Plugins shouldn't be duplicated
|
|
|
|
assert(#paths == 1, "expected exactly 1 copy of '${name}' in runtime, got ", #paths)
|
|
|
|
-- Test if plugin is standalone. This matches directory name before '/lua/'.
|
|
|
|
local is_standalone = paths[1]:match("^(.+)/lua/"):find("${name}", 1, true) ~= nil
|
|
|
|
assert(
|
|
|
|
is_standalone == ${lib.nixvim.toLuaObject isStandalone},
|
|
|
|
"expected '${name}' to be ${expectedText}, found path: " .. paths[1]
|
|
|
|
)
|
|
|
|
''
|
|
|
|
) pluginStubs.pluginNames}
|
2024-07-19 16:31:12 +03:00
|
|
|
'';
|
|
|
|
assertions = [
|
2025-05-11 18:34:41 +03:00
|
|
|
# plugin-pack and 'standalonePlugins'
|
|
|
|
(expectNPlugins config "start" (builtins.length standalonePlugins + 1))
|
2024-07-19 16:31:12 +03:00
|
|
|
];
|
|
|
|
};
|
2024-07-16 14:45:12 +03:00
|
|
|
|
|
|
|
# Test if plenary.filetype is working
|
|
|
|
plenary-nvim = {
|
|
|
|
performance.combinePlugins.enable = true;
|
|
|
|
extraPlugins = [ pkgs.vimPlugins.plenary-nvim ];
|
|
|
|
extraConfigLuaPost = ''
|
|
|
|
-- Plenary filetype detection is usable
|
|
|
|
assert(require("plenary.filetype").detect(".bashrc") == "sh", "plenary.filetype is not working")
|
|
|
|
'';
|
|
|
|
};
|
2024-07-07 20:22:39 +03:00
|
|
|
}
|