mzte-nv: enable inlay hints

This commit is contained in:
LordMZTE 2024-01-18 18:23:20 +01:00
parent 8b991b6728
commit e1316abe75
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 47 additions and 0 deletions

View file

@ -1,3 +1,4 @@
(local mztenv (require :mzte_nv))
(local lspc (require :lspconfig))
(local lsp-configs (require :lspconfig.configs))
@ -5,6 +6,10 @@
(var args args)
(when (not args)
(set args {}))
(tset args :on_attach (if args.on_attach
`(fn [client# bufnr#] (mztenv.lsp.onAttach client# bufnr#)
(,args.on_attach client# bufnr#))
`mztenv.lsp.onAttach))
(tset args :capabilities `caps)
`((. lspc ,conf :setup) ,args))

View file

@ -13,6 +13,7 @@ const modules = struct {
const cpbuf = @import("modules/cpbuf.zig");
const fennel = @import("modules/fennel.zig");
const jdtls = @import("modules/jdtls.zig");
const lsp = @import("modules/lsp.zig");
const telescope = @import("modules/telescope.zig");
const tsn_actions = @import("modules/tsn_actions.zig");
const utils = @import("modules/utils.zig");
@ -87,6 +88,7 @@ export fn luaopen_mzte_nv(l_: ?*c.lua_State) c_int {
.cpbuf = modules.cpbuf,
.fennel = modules.fennel,
.jdtls = modules.jdtls,
.lsp = modules.lsp,
.telescope = modules.telescope,
.tsn_actions = modules.tsn_actions,
.utils = modules.utils,

View file

@ -0,0 +1,40 @@
//! Module for nvim-lsp related utilities
const std = @import("std");
const ser = @import("../ser.zig");
const ffi = @import("../ffi.zig");
const c = ffi.c;
pub fn luaPush(l: *c.lua_State) void {
ser.luaPushAny(l, .{
.onAttach = ffi.luaFunc(lOnAttach),
});
}
fn lOnAttach(l: *c.lua_State) !c_int {
c.luaL_checkany(l, 1);
const bufnr = c.luaL_checknumber(l, 2);
const has_inlay_hints = hints: {
c.lua_getfield(l, 1, "server_capabilities");
defer c.lua_pop(l, 1);
if (c.lua_isnil(l, -1)) break :hints false;
c.lua_getfield(l, -1, "inlayHintProvider");
defer c.lua_pop(l, 1);
break :hints c.lua_toboolean(l, -1) != 0;
};
if (has_inlay_hints) {
c.lua_getglobal(l, "vim");
defer c.lua_pop(l, 1);
c.lua_getfield(l, -1, "lsp");
defer c.lua_pop(l, 1);
c.lua_getfield(l, -1, "inlay_hint");
defer c.lua_pop(l, 1);
c.lua_getfield(l, -1, "enable");
c.lua_pushnumber(l, bufnr);
c.lua_pushboolean(l, 1);
c.lua_call(l, 2, 0);
}
return 0;
}