From cc0ad9602dcf06a7749672843fc479bfa364803e Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sat, 27 May 2023 22:57:31 +0200 Subject: [PATCH] make mzte-nv notifs use mini view --- mzte-nv/conf/lua/pluginconf/p-noice.fnl | 12 +++++++---- mzte-nv/src/main.zig | 27 ++++++------------------- mzte-nv/src/modules/utils.zig | 9 +++++++++ 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/mzte-nv/conf/lua/pluginconf/p-noice.fnl b/mzte-nv/conf/lua/pluginconf/p-noice.fnl index 22b2115..0abd13e 100644 --- a/mzte-nv/conf/lua/pluginconf/p-noice.fnl +++ b/mzte-nv/conf/lua/pluginconf/p-noice.fnl @@ -1,15 +1,19 @@ -(local noice (require :noice)) +(local (mztenv noice) (values (require :mzte_nv) (require :noice))) (local overrides [:vim.lsp.util.convert_input_to_markdown_lines :vim.lsp.util.stylize_markdown :cmp.entry.get_documentation]) +(fn show-mini? [notif] + (and notif.opts (or ;; DAP notifs + (= notif.opts.title :DAP) + ;; MZTE-NV notifications + notif.opts.mzte_nv_mini))) + (noice.setup {:messages {:view :mini} :lsp {:override (collect [_ o (ipairs overrides)] (values o true))} :routes [;; Redirect DAP messages to mini view - {:filter {:event :notify - :cond #(and $1.opts (= $.opts.title :DAP))} - :view :mini}] + {:filter {:event :notify :cond show-mini?} :view :mini}] :presets {:lsp_doc_border true}}) ;; Shift-Enter to redirect cmdline diff --git a/mzte-nv/src/main.zig b/mzte-nv/src/main.zig index db83b07..59e8a00 100644 --- a/mzte-nv/src/main.zig +++ b/mzte-nv/src/main.zig @@ -39,10 +39,12 @@ pub const std_options = struct { .err => nvim.LOGLVL_ERR, }; - var dict = znvim.Dictionary{.alloc = std.heap.c_allocator}; + var dict = znvim.Dictionary{ .alloc = std.heap.c_allocator }; defer dict.deinit(); dict.push(@constCast("title"), znvim.nvimObject(@as([]u8, title))) catch return; + // noice notficitaions recognize this and show in the mini view instead of notifs + dict.push(@constCast("mzte_nv_mini"), comptime znvim.nvimObject(true)) catch return; var e = znvim.Error{}; _ = nvim.nvim_notify( @@ -70,29 +72,12 @@ export fn luaopen_mzte_nv(l_: ?*c.lua_State) c_int { } fn lOnInit(l: *c.lua_State) !c_int { + _ = l; try @import("options.zig").initOptions(); - c.lua_getglobal(l, "vim"); // 1 - c.lua_getfield(l, 1, "version"); - c.lua_call(l, 0, 1); // 2 - - c.lua_getfield(l, 2, "major"); - const major = c.lua_tointeger(l, -1); - - c.lua_getfield(l, 2, "minor"); - const minor = c.lua_tointeger(l, -1); - - c.lua_getfield(l, 2, "patch"); - const patch = c.lua_tointeger(l, -1); - - c.lua_getfield(l, 2, "prerelease"); - const prerelease = if (c.lua_toboolean(l, -1) != 0) " (prerelease)" else ""; - - c.lua_settop(l, 1); - std.log.info( - "MZTE-NV v{s} Initialized on NVIM v{}.{}.{}{s}", - .{ version, major, minor, patch, prerelease }, + "MZTE-NV v{s} Initialized on NVIM v{s}", + .{ version, nvim.longVersion }, ); return 0; } diff --git a/mzte-nv/src/modules/utils.zig b/mzte-nv/src/modules/utils.zig index aaa4c8c..c82b0a8 100644 --- a/mzte-nv/src/modules/utils.zig +++ b/mzte-nv/src/modules/utils.zig @@ -42,3 +42,12 @@ fn lFindInPath(l: *c.lua_State) !c_int { c.lua_pushnil(l); return 1; } + +/// Starts if arg 1 starts with arg 2 +fn lStartsWith(l: *c.lua_State) !c_int { + const haystack = ffi.luaCheckstring(l, 1); + const needle = ffi.luaCheckstring(l, 1); + + c.lua_pushbool(std.mem.startsWith(u8, haystack, needle)); + return 1; +}