feat: mzte-nv now compiles packer-compiled.lua

This commit is contained in:
LordMZTE 2023-01-03 22:57:55 +01:00
parent 15fa36b24c
commit 73d251f9cf
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
5 changed files with 39 additions and 26 deletions

View file

@ -1,9 +1,9 @@
-- This module is responsible for loading the native mzte-nv lua module -- This module is responsible for loading the native mzte-nv lua module
package.cpath = package.cpath .. ";" .. vim.loop.os_homedir() .. "/.local/share/nvim/mzte-nv.so" package.cpath = package.cpath .. ";" .. vim.loop.os_homedir() .. "/.local/share/nvim/mzte-nv.so"
local success = pcall(require, "mzte_nv"); local success, mztenv = pcall(require, "mzte_nv")
if not success then if not success then
error "Failed to preload mzte-nv. Is it installed?" error "Failed to preload mzte-nv. Is it installed?"
end end
require("mzte_nv").onInit() mztenv.onInit()

View file

@ -186,6 +186,11 @@ require("packer").startup(function(use)
cmp_plugins(use) cmp_plugins(use)
end) end)
vim.api.nvim_create_user_command("CompilePlugins", function() -- actually compile packer-generated config after packer's "compile" step
require("mzte_nv").compile.compilePath(require("packer").config.package_root) vim.api.nvim_create_autocmd("User", {
end, { nargs = 0 }) pattern = "PackerCompileDone",
once = true,
callback = function()
require("mzte_nv").compile.compilePath(require("packer").config.compile_path)
end,
})

View file

@ -40,3 +40,7 @@ cmd "filetype plugin on"
vim.api.nvim_create_user_command("CompileConfig", function() vim.api.nvim_create_user_command("CompileConfig", function()
require("mzte_nv").compile.compilePath(vim.fn.getenv("HOME") .. "/.config/nvim") require("mzte_nv").compile.compilePath(vim.fn.getenv("HOME") .. "/.config/nvim")
end, { nargs = 0 }) end, { nargs = 0 })
vim.api.nvim_create_user_command("CompilePlugins", function()
require("mzte_nv").compile.compilePath(require("packer").config.package_root)
end, { nargs = 0 })

View file

@ -46,20 +46,21 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
// prepare state // prepare state
c.lua_getfield(l, c.LUA_GLOBALSINDEX, "string"); c.lua_getfield(l, c.LUA_GLOBALSINDEX, "string");
var dir = try std.fs.cwd().openIterableDir(path, .{}); // an arena allocator to hold data to be used during the build
defer dir.close(); var build_arena = std.heap.ArenaAllocator.init(alloc);
defer build_arena.deinit();
var walker = try dir.walk(alloc); const build_alloc = build_arena.allocator();
defer walker.deinit();
// a list of lua files to compile // a list of lua files to compile
var files = std.ArrayList([]const u8).init(alloc); var files = std.ArrayList([]const u8).init(alloc);
defer files.deinit(); defer files.deinit();
// an arena allocator to hold data to be used during the build if ((try std.fs.cwd().statFile(path)).kind == .Directory) {
var build_arena = std.heap.ArenaAllocator.init(alloc); var dir = try std.fs.cwd().openIterableDir(path, .{});
defer build_arena.deinit(); defer dir.close();
const build_alloc = build_arena.allocator();
var walker = try dir.walk(alloc);
defer walker.deinit();
while (try walker.next()) |entry| { while (try walker.next()) |entry| {
const entry_path = try std.fs.path.join(build_alloc, &.{ path, entry.path }); const entry_path = try std.fs.path.join(build_alloc, &.{ path, entry.path });
@ -73,6 +74,9 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
else => {}, else => {},
} }
} }
} else {
try files.append(path);
}
for (files.items) |luafile| { for (files.items) |luafile| {
const luafile_z = try alloc.dupeZ(u8, luafile); const luafile_z = try alloc.dupeZ(u8, luafile);
@ -80,7 +84,7 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
c.lua_getfield(l, -1, "dump"); c.lua_getfield(l, -1, "dump");
if (c.luaL_loadfile(l, luafile_z) != 0) { if (c.luaL_loadfile(l, luafile_z) != 0) {
std.log.warn( log.warn(
"error compiling lua object {s}: {s}", "error compiling lua object {s}: {s}",
.{ luafile, c.lua_tolstring(l, -1, null) }, .{ luafile, c.lua_tolstring(l, -1, null) },
); );

View file

@ -3,7 +3,7 @@ const ffi = @import("ffi.zig");
const ser = @import("ser.zig"); const ser = @import("ser.zig");
const c = ffi.c; const c = ffi.c;
pub const version = "1.1.0"; pub const version = "1.2.0";
const modules = struct { const modules = struct {
const cmp = @import("modules/cmp.zig"); const cmp = @import("modules/cmp.zig");