mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-14 18:03:41 +01:00
feat: mzte-nv now compiles packer-compiled.lua
This commit is contained in:
parent
15fa36b24c
commit
73d251f9cf
5 changed files with 39 additions and 26 deletions
|
@ -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()
|
||||||
|
|
|
@ -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,
|
||||||
|
})
|
||||||
|
|
|
@ -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 })
|
||||||
|
|
|
@ -46,32 +46,36 @@ 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, .{});
|
|
||||||
defer dir.close();
|
|
||||||
|
|
||||||
var walker = try dir.walk(alloc);
|
|
||||||
defer walker.deinit();
|
|
||||||
|
|
||||||
// a list of lua files to compile
|
|
||||||
var files = std.ArrayList([]const u8).init(alloc);
|
|
||||||
defer files.deinit();
|
|
||||||
|
|
||||||
// an arena allocator to hold data to be used during the build
|
// an arena allocator to hold data to be used during the build
|
||||||
var build_arena = std.heap.ArenaAllocator.init(alloc);
|
var build_arena = std.heap.ArenaAllocator.init(alloc);
|
||||||
defer build_arena.deinit();
|
defer build_arena.deinit();
|
||||||
const build_alloc = build_arena.allocator();
|
const build_alloc = build_arena.allocator();
|
||||||
|
|
||||||
while (try walker.next()) |entry| {
|
// a list of lua files to compile
|
||||||
const entry_path = try std.fs.path.join(build_alloc, &.{ path, entry.path });
|
var files = std.ArrayList([]const u8).init(alloc);
|
||||||
|
defer files.deinit();
|
||||||
|
|
||||||
switch (entry.kind) {
|
if ((try std.fs.cwd().statFile(path)).kind == .Directory) {
|
||||||
.File => {
|
var dir = try std.fs.cwd().openIterableDir(path, .{});
|
||||||
if (std.mem.endsWith(u8, entry.path, ".lua")) {
|
defer dir.close();
|
||||||
try files.append(entry_path);
|
|
||||||
}
|
var walker = try dir.walk(alloc);
|
||||||
},
|
defer walker.deinit();
|
||||||
else => {},
|
|
||||||
|
while (try walker.next()) |entry| {
|
||||||
|
const entry_path = try std.fs.path.join(build_alloc, &.{ path, entry.path });
|
||||||
|
|
||||||
|
switch (entry.kind) {
|
||||||
|
.File => {
|
||||||
|
if (std.mem.endsWith(u8, entry.path, ".lua")) {
|
||||||
|
try files.append(entry_path);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
try files.append(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (files.items) |luafile| {
|
for (files.items) |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) },
|
||||||
);
|
);
|
||||||
|
|
|
@ -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");
|
||||||
|
|
Loading…
Reference in a new issue