mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
modules/performance: add ability to byte compile extraLuaPackages
This commit adds `performance.byteCompileLua.luaLib` options. When enabled it byte-compiles lua packages from extraLuaPackages option.
This commit is contained in:
parent
fac192c022
commit
404e56066f
3 changed files with 64 additions and 9 deletions
|
@ -57,6 +57,9 @@ in
|
||||||
nvimRuntime = lib.mkEnableOption "nvimRuntime" // {
|
nvimRuntime = lib.mkEnableOption "nvimRuntime" // {
|
||||||
description = "Whether to byte compile lua files in Nvim runtime.";
|
description = "Whether to byte compile lua files in Nvim runtime.";
|
||||||
};
|
};
|
||||||
|
luaLib = lib.mkEnableOption "luaLib" // {
|
||||||
|
description = "Whether to byte compile lua library.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
combinePlugins = {
|
combinePlugins = {
|
||||||
|
|
|
@ -171,11 +171,18 @@ in
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
|
# Optionally byte compile lua library
|
||||||
|
extraLuaPackages =
|
||||||
|
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.luaLib then
|
||||||
|
ps: map builders.byteCompileLuaDrv (config.extraLuaPackages ps)
|
||||||
|
else
|
||||||
|
config.extraLuaPackages;
|
||||||
|
|
||||||
neovimConfig = pkgs.neovimUtils.makeNeovimConfig (
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig (
|
||||||
{
|
{
|
||||||
|
inherit extraLuaPackages;
|
||||||
inherit (config)
|
inherit (config)
|
||||||
extraPython3Packages
|
extraPython3Packages
|
||||||
extraLuaPackages
|
|
||||||
viAlias
|
viAlias
|
||||||
vimAlias
|
vimAlias
|
||||||
withRuby
|
withRuby
|
||||||
|
|
|
@ -22,16 +22,29 @@ let
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function test_lualib_file(func, is_compiled)
|
||||||
|
-- Get the source of the func
|
||||||
|
local info = debug.getinfo(func, "S")
|
||||||
|
-- The source returned by debug.getinfo is prefixed with '@'
|
||||||
|
local file = info.source:sub(2)
|
||||||
|
assert(vim.uv.fs_stat(file))
|
||||||
|
if is_compiled then
|
||||||
|
assert(is_byte_compiled(file), file .. " is expected to be byte compiled, but it's not")
|
||||||
|
else
|
||||||
|
assert(not is_byte_compiled(file), file .. " is not expected to be byte compiled, but it is")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function assert_g_var(varname, filename)
|
local function assert_g_var(varname, filename)
|
||||||
assert(
|
assert(
|
||||||
vim.g[varname] == true or vim.g[varname] == 1,
|
vim.g[varname] == true or vim.g[varname] == 1,
|
||||||
string.format(
|
string.format(
|
||||||
"expected vim.g.%s to be truthy, got %s. File %s isn't executed?",
|
"expected vim.g.%s to be truthy, got %s. File %s isn't executed?",
|
||||||
varname,
|
varname,
|
||||||
vim.g[varname],
|
vim.g[varname],
|
||||||
filename
|
filename
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -130,6 +143,8 @@ in
|
||||||
|
|
||||||
extraPlugins = [ stubDrvPlugin ];
|
extraPlugins = [ stubDrvPlugin ];
|
||||||
|
|
||||||
|
extraLuaPackages = ps: [ ps.say ];
|
||||||
|
|
||||||
extraConfigLua = ''
|
extraConfigLua = ''
|
||||||
-- The test will search for the next string in nixvim-print-init's output: VALIDATING_STRING.
|
-- The test will search for the next string in nixvim-print-init's output: VALIDATING_STRING.
|
||||||
-- Since this is the comment, it won't appear in byte compiled file.
|
-- Since this is the comment, it won't appear in byte compiled file.
|
||||||
|
@ -180,6 +195,9 @@ in
|
||||||
|
|
||||||
-- Nvim runtime isn't byte compiled by default
|
-- Nvim runtime isn't byte compiled by default
|
||||||
test_rtp_file("lua/vim/lsp.lua", false)
|
test_rtp_file("lua/vim/lsp.lua", false)
|
||||||
|
|
||||||
|
-- Lua library isn't byte compiled by default
|
||||||
|
test_lualib_file(require("say").set, false)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -193,6 +211,8 @@ in
|
||||||
|
|
||||||
extraPlugins = [ stubDrvPlugin ];
|
extraPlugins = [ stubDrvPlugin ];
|
||||||
|
|
||||||
|
extraLuaPackages = ps: [ ps.say ];
|
||||||
|
|
||||||
extraConfigLua = ''
|
extraConfigLua = ''
|
||||||
${isByteCompiledFun}
|
${isByteCompiledFun}
|
||||||
|
|
||||||
|
@ -208,6 +228,8 @@ in
|
||||||
test_rtp_file("lua/stub_drv_plugin/init.lua", false)
|
test_rtp_file("lua/stub_drv_plugin/init.lua", false)
|
||||||
-- Neovim runtime
|
-- Neovim runtime
|
||||||
test_rtp_file("lua/vim/lsp.lua", false)
|
test_rtp_file("lua/vim/lsp.lua", false)
|
||||||
|
-- Lua library
|
||||||
|
test_lualib_file(require("say").set, false)
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -276,6 +298,29 @@ in
|
||||||
vim.cmd.py3("import yaml")
|
vim.cmd.py3("import yaml")
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lua-lib = {
|
||||||
|
performance.byteCompileLua = {
|
||||||
|
enable = true;
|
||||||
|
luaLib = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
extraLuaPackages =
|
||||||
|
ps: with ps; [
|
||||||
|
say
|
||||||
|
argparse
|
||||||
|
];
|
||||||
|
|
||||||
|
extraConfigLuaPost = ''
|
||||||
|
${isByteCompiledFun}
|
||||||
|
|
||||||
|
-- Lua modules are importable and byte compiled
|
||||||
|
local say = require("say")
|
||||||
|
test_lualib_file(say.set, true)
|
||||||
|
local argparse = require("argparse")
|
||||||
|
test_lualib_file(argparse("test").parse, true)
|
||||||
|
'';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
# Two equal tests, one with combinePlugins.enable = true
|
# Two equal tests, one with combinePlugins.enable = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue