feat: improve mzte-nv

This commit is contained in:
LordMZTE 2023-04-23 18:07:38 +02:00
parent 90f55f837a
commit ca3b276b38
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
5 changed files with 51 additions and 42 deletions

View file

@ -16,6 +16,11 @@ pub fn build(b: *std.build.Builder) !void {
.optimize = mode,
});
const znvim_dep = b.dependency("znvim", .{ .target = target, .optimize = mode });
lib.addModule("nvim", znvim_dep.module("nvim_c"));
lib.addModule("znvim", znvim_dep.module("znvim"));
lib.linkLibC();
lib.linkSystemLibrary("luajit");

11
mzte-nv/build.zig.zon Normal file
View file

@ -0,0 +1,11 @@
.{
.name = "mzte-nv",
.version = "0.0.0",
.dependencies = .{
.znvim = .{
.url = "https://mzte.de/git/LordMZTE/znvim/archive/0f07217feb2ed4e0295242a7b0a157a5f7314602.tar.gz",
.hash = "12208ff8bcbed85791fc4a98063967723f351b7898b651a7a3aa75d32dec04bb4a0e",
},
},
}

View file

@ -5,16 +5,18 @@
(when client.server_capabilities.documentHighlightProvider
;; Symbol highlighting
(vim.api.nvim_create_autocmd :CursorHold
{:callback vim.lsp.buf.document_highlight})
{:buffer buf
:callback vim.lsp.buf.document_highlight})
(vim.api.nvim_create_autocmd :CursorHoldI
{:callback vim.lsp.buf.document_highlight})
{:buffer buf
:callback vim.lsp.buf.document_highlight})
(vim.api.nvim_create_autocmd :CursorMoved
{:callback vim.lsp.buf.clear_references})))
{:buffer buf
:callback vim.lsp.buf.clear_references})))
(vim.api.nvim_create_autocmd :LspAttach {:callback on-lsp-attach})
;; Highlight in bold font
(local hlgroups [:LspReferenceText :LspReferenceRead :LspReferenceWrite])
(each [_ hl (ipairs hlgroups)]
(vim.api.nvim_set_hl 0 hl {:bold true
:bg "#6272a4"}))
(vim.api.nvim_set_hl 0 hl {:bold true :bg "#6272a4"}))

View file

@ -1,4 +1,6 @@
const std = @import("std");
const nvim = @import("nvim");
const znvim = @import("znvim");
const ffi = @import("ffi.zig");
const ser = @import("ser.zig");
const c = ffi.c;
@ -13,8 +15,6 @@ const modules = struct {
const utils = @import("modules/utils.zig");
};
var lua_state: ?*c.lua_State = null;
pub const std_options = struct {
pub fn logFn(
comptime level: std.log.Level,
@ -22,50 +22,41 @@ pub const std_options = struct {
comptime format: []const u8,
args: anytype,
) void {
// if there's no lua state, we can't invoke nvim notifications.
const l = lua_state orelse return;
const stacktop = c.lua_gettop(l);
defer c.lua_settop(l, stacktop);
var fmtbuf: [2048]u8 = undefined;
c.lua_getglobal(l, "vim");
c.lua_getfield(l, -1, "log");
c.lua_getfield(l, -1, "levels");
switch (level) {
.err => c.lua_getfield(l, -1, "ERROR"),
.warn => c.lua_getfield(l, -1, "WARN"),
.info => c.lua_getfield(l, -1, "INFO"),
.debug => c.lua_getfield(l, -1, "DEBUG"),
}
const vim_lvl = c.lua_tointeger(l, -1);
c.lua_pop(l, 3);
c.lua_getfield(l, -1, "notify");
const msg = std.fmt.bufPrintZ(&fmtbuf, format, args) catch return;
c.lua_pushstring(l, msg.ptr);
c.lua_pushinteger(l, vim_lvl);
var msg_buf: [512]u8 = undefined;
const msg = std.fmt.bufPrintZ(&msg_buf, format, args) catch return;
var title_buf: [512]u8 = undefined;
const title = std.fmt.bufPrintZ(
&fmtbuf,
&title_buf,
"MZTE-NV ({s})",
.{@tagName(scope)},
) catch return;
ser.luaPushAny(l, .{
.title = title,
});
c.lua_call(l, 3, 0);
const lvl = switch (level) {
.debug => nvim.LOGLVL_DBG,
.info => nvim.LOGLVL_INF,
.warn => nvim.LOGLVL_WRN,
.err => nvim.LOGLVL_ERR,
};
var dict = znvim.Dictionary{.alloc = std.heap.c_allocator};
defer dict.deinit();
dict.push(@constCast("title"), znvim.nvimObject(@as([]u8, title))) catch return;
var e = znvim.Error{};
_ = nvim.nvim_notify(
znvim.nvimString(msg),
lvl,
dict.dict,
&e.err,
);
}
pub const log_level = .debug;
};
export fn luaopen_mzte_nv(l_: ?*c.lua_State) c_int {
lua_state = l_;
const l = l_.?;
ser.luaPushAny(l, .{
.onInit = ffi.luaFunc(lOnInit),

View file

@ -1,5 +1,5 @@
/// Module for the JDTLS java language server, including utilities
/// for setting up nvim-jdtls
//! Module for the JDTLS java language server, including utilities
//! for setting up nvim-jdtls
const std = @import("std");
const ser = @import("../ser.zig");
const ffi = @import("../ffi.zig");