add conjure plugiN

This commit is contained in:
LordMZTE 2023-02-23 10:56:20 +01:00
parent 7a477ee604
commit a2f30047fa
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
6 changed files with 30 additions and 10 deletions

View file

@ -2,6 +2,7 @@
(values (require :cmp) (require :luasnip) (require :mzte_nv)))
(local sources {:buffer " ﬘"
:conjure " "
:crates " "
:luasnip " "
:nvim_lsp " "

View file

@ -27,7 +27,8 @@
(use :ray-x/cmp-treesitter)
(use/pconf use :jose-elias-alvarez/null-ls.nvim :nullls)
(use {1 :LhKipp/nvim-nu
:config #((. (require :nu) :setup) {:complete_cmd_names true})}))
:config #((. (require :nu) :setup) {:complete_cmd_names true})})
(use :PaterJason/cmp-conjure))
(fn init [use]
(use :wbthomason/packer.nvim)
@ -66,6 +67,9 @@
(use/pconf use :CKolkey/ts-node-action :tsn-actions
{:requires :jose-elias-alvarez/null-ls.nvim})
(use :nvim-treesitter/playground)
(use {1 :Olical/conjure
;; TODO: stop LSPs from attaching to conjure log
:config #(set vim.g.conjure#mapping#prefix :<F1>)})
(cmp-plugins use))
((. (require :packer) :startup) init)

View file

@ -1,5 +1,6 @@
const std = @import("std");
const c = @import("ffi.zig").c;
const ffi = @import("ffi.zig");
const c = ffi.c;
const log = std.log.scoped(.compiler);
@ -89,6 +90,15 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
c.lua_getfield(l, -1, "dump");
if (std.mem.endsWith(u8, luafile, ".fnl")) {
// this check is to prevent fennel code in aniseed plugins being unecessarily compiled.
if (std.mem.containsAtLeast(u8, luafile, 1, "/fnl/") or
// TODO: wonk
std.mem.endsWith(u8, luafile, "macros.fnl"))
{
c.lua_pop(l, 1);
continue;
}
// replace file extension
std.mem.copy(u8, outname[outname.len - 3 ..], "lua");
@ -102,6 +112,7 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
if (!std.meta.eql(res.term, .{ .Exited = 0 })) {
log.warn("error compiling fennel object {s}: {s}", .{ luafile, res.stderr });
c.lua_pop(l, 1);
continue;
}
@ -111,7 +122,7 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
if (c.luaL_loadbuffer(l, res.stdout.ptr, res.stdout.len, luafile_z) != 0) {
log.warn(
"error compiling fennel lua object {s}: {s}",
.{ luafile, c.lua_tolstring(l, -1, null) },
.{ luafile, ffi.luaToString(l, -1) },
);
c.lua_pop(l, 2);
continue;
@ -123,7 +134,7 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
if (c.luaL_loadfile(l, luafile_z) != 0) {
log.warn(
"error compiling lua object {s}: {s}",
.{ luafile, c.lua_tolstring(l, -1, null) },
.{ luafile, ffi.luaToString(l, -1) },
);
c.lua_pop(l, 2);
continue;

View file

@ -26,11 +26,16 @@ pub fn luaFunc(comptime func: fn (*c.lua_State) anyerror!c_int) c.lua_CFunction
}
/// A thin wrapper around luaL_checklstring that uses the length parameter to return a slice.
pub fn luaCheckstring(l: *c.lua_State, idx: c_int) []const u8 {
pub fn luaCheckstring(l: ?*c.lua_State, idx: c_int) []const u8 {
var len: usize = 0;
return c.luaL_checklstring(l, idx, &len)[0..len];
}
pub fn luaPushString(l: *c.lua_State, s: []const u8) void {
pub fn luaPushString(l: ?*c.lua_State, s: []const u8) void {
c.lua_pushlstring(l, s.ptr, s.len);
}
pub fn luaToString(l: ?*c.lua_State, idx: c_int) []const u8 {
var len: usize = 0;
return c.lua_tolstring(l, idx, &len)[0..len];
}

View file

@ -83,8 +83,7 @@ fn lOnTab(l: *c.lua_State) !c_int {
// get the line
c.lua_rawgeti(l, -1, 1);
var strlen: usize = 0;
const line = c.lua_tolstring(l, -1, &strlen)[0..strlen];
const line = ffi.luaToString(l, -1);
// char at the cursor is NOT whitespace
const b = std.mem.indexOfScalar(

View file

@ -13,7 +13,7 @@ pub fn luaPush(l: *c.lua_State) void {
}
fn lCompilePath(l: *c.lua_State) !c_int {
const path = c.luaL_checklstring(l, 1, null);
try compiler.doCompile(std.mem.span(path), std.heap.c_allocator);
const path = ffi.luaCheckstring(l, 1);
try compiler.doCompile(path, std.heap.c_allocator);
return 0;
}