mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-09 16:54:36 +02:00
modules/performance: add ability to byte compile lua plugins
This commit adds `performance.byteCompileLua.plugins` toggle that, if enabled, byte compiles all lua files in plugins
This commit is contained in:
parent
44849233e0
commit
55ca9d235b
3 changed files with 92 additions and 2 deletions
|
@ -18,6 +18,9 @@ in
|
|||
default = true;
|
||||
example = false;
|
||||
};
|
||||
plugins = lib.mkEnableOption "plugins" // {
|
||||
description = "Whether to byte compile lua plugins.";
|
||||
};
|
||||
};
|
||||
|
||||
combinePlugins = {
|
||||
|
|
|
@ -87,8 +87,27 @@ in
|
|||
defaultPlugin // (if p ? plugin then p else { plugin = p; });
|
||||
normalizePluginList = plugins: map normalize plugins;
|
||||
|
||||
# Normalized plugin list
|
||||
normalizedPlugins = normalizePluginList config.extraPlugins;
|
||||
# Byte compiling of normalized plugin list
|
||||
byteCompilePlugins =
|
||||
plugins:
|
||||
let
|
||||
byteCompile =
|
||||
p:
|
||||
(helpers.byteCompileLuaDrv p).overrideAttrs (
|
||||
prev: lib.optionalAttrs (prev ? dependencies) { dependencies = map byteCompile prev.dependencies; }
|
||||
);
|
||||
in
|
||||
map (p: p // { plugin = byteCompile p.plugin; }) plugins;
|
||||
|
||||
# Normalized and optionally byte compiled plugin list
|
||||
normalizedPlugins =
|
||||
let
|
||||
normalized = normalizePluginList config.extraPlugins;
|
||||
in
|
||||
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.plugins then
|
||||
byteCompilePlugins normalized
|
||||
else
|
||||
normalized;
|
||||
|
||||
# Plugin list extended with dependencies
|
||||
allPlugins =
|
||||
|
|
|
@ -183,3 +183,71 @@ in
|
|||
'';
|
||||
};
|
||||
}
|
||||
//
|
||||
# Two equal tests, one with combinePlugins.enable = true
|
||||
pkgs.lib.genAttrs
|
||||
[
|
||||
"plugins"
|
||||
"plugins-combined"
|
||||
]
|
||||
(name: {
|
||||
performance = {
|
||||
byteCompileLua = {
|
||||
enable = true;
|
||||
plugins = true;
|
||||
};
|
||||
|
||||
combinePlugins.enable = pkgs.lib.hasSuffix "combined" name;
|
||||
};
|
||||
|
||||
extraPlugins = with pkgs.vimPlugins; [
|
||||
nvim-lspconfig
|
||||
# Depends on plenary-nvim
|
||||
telescope-nvim
|
||||
# buildCommand plugin with python3 dependency
|
||||
((pkgs.writeTextDir "/plugin/test.lua" "vim.opt.tabstop = 2").overrideAttrs {
|
||||
passthru.python3Dependencies = ps: [ ps.pyyaml ];
|
||||
})
|
||||
# Plugin with invalid lua file tests/indent/lua/cond.lua (should be ignored)
|
||||
nvim-treesitter
|
||||
];
|
||||
|
||||
extraConfigLuaPost = ''
|
||||
${isByteCompiledFun}
|
||||
|
||||
-- Plugins are loadable
|
||||
require("lspconfig")
|
||||
require("telescope")
|
||||
require("plenary")
|
||||
require("nvim-treesitter")
|
||||
|
||||
-- Python modules are importable
|
||||
vim.cmd.py3("import yaml")
|
||||
|
||||
-- nvim-lspconfig
|
||||
test_rtp_file("lua/lspconfig.lua", true)
|
||||
test_rtp_file("lua/lspconfig/server_configurations/nixd.lua", true)
|
||||
test_rtp_file("plugin/lspconfig.lua", true)
|
||||
test_rtp_file("doc/lspconfig.txt", false)
|
||||
|
||||
-- telescope-nvim
|
||||
test_rtp_file("lua/telescope/init.lua", true)
|
||||
test_rtp_file("lua/telescope/builtin/init.lua", true)
|
||||
test_rtp_file("plugin/telescope.lua", true)
|
||||
test_rtp_file("autoload/health/telescope.vim", false)
|
||||
test_rtp_file("doc/telescope.txt", false)
|
||||
|
||||
-- Dependency of telescope-nvim (plenary-nvim)
|
||||
test_rtp_file("lua/plenary/init.lua", true)
|
||||
test_rtp_file("plugin/plenary.vim", false)
|
||||
|
||||
-- Test plugin
|
||||
test_rtp_file("plugin/test.lua", true)
|
||||
|
||||
-- nvim-treesitter
|
||||
test_rtp_file("lua/nvim-treesitter/health.lua", true)
|
||||
test_rtp_file("lua/nvim-treesitter/install.lua", true)
|
||||
test_rtp_file("plugin/nvim-treesitter.lua", true)
|
||||
test_rtp_file("queries/nix/highlights.scm", false)
|
||||
'';
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue