mzte-nv: install nvim-lightbulb and create mzte-nv registry

This commit is contained in:
LordMZTE 2023-06-27 22:30:06 +02:00
parent 55c5c73a71
commit 371d13c0bb
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
6 changed files with 68 additions and 7 deletions

View file

@ -2,7 +2,9 @@
(fn on-lsp-attach [args]
(local buf args.buf)
(local client (vim.lsp.get_client_by_id args.data.client_id))
(when client.server_capabilities.documentHighlightProvider
(when (and client.server_capabilities.documentHighlightProvider
(not vim.b.mzte_reg_hl_aucmd))
(set vim.b.mzte_reg_hl_aucmd true)
;; Symbol highlighting
(vim.api.nvim_create_autocmd :CursorHold
{:buffer buf

View file

@ -1,6 +1,12 @@
(local catppuccin (require :catppuccin))
(print "catppuccin config")
(local (mztenv catppuccin palettes)
(values (require :mzte_nv) (require :catppuccin)
(require :catppuccin.palettes)))
(catppuccin.setup {;; Enable all relevant integrations
(local flavour :mocha)
(catppuccin.setup {: flavour
;; Enable all relevant integrations
:integrations {:aerial true
:harpoon true
:gitsigns true
@ -17,3 +23,11 @@
:telescope true}})
(vim.cmd.colorscheme :catppuccin)
;; Optimize this by saving the palette table
(let [get-palette palettes.get_palette]
(set mztenv.reg.catppuccin-palette (get-palette))
(set palettes.get_palette
(fn [flav]
(if (or (not flav) (= flav flavour)) mztenv.reg.catppuccin-palette
(get-palette flav)))))

View file

@ -0,0 +1,23 @@
(local lightbulb (require :nvim-lightbulb))
(local ignored-clients [:null-ls])
(lightbulb.setup {:ignore ignored-clients
;; No gutter sign
:sign {:enabled false}
;; Status bar text
:status_text {:enabled true :text "󱐌"}})
;; Create update autocmd on LSP attach
(fn on-lsp-attach [args]
(let [buf args.buf
client (vim.lsp.get_client_by_id args.data.client_id)]
(when (and client.server_capabilities.codeActionProvider
(not vim.b.mzte_reg_lighbulb_aucmd)
(not (vim.list_contains ignored-clients client.name)))
(set vim.b.mzte_reg_lighbulb_aucmd true)
(vim.api.nvim_create_autocmd :CursorHold
{:buffer buf
:callback lightbulb.update_lightbulb}))))
(vim.api.nvim_create_autocmd :LspAttach {:callback on-lsp-attach})

View file

@ -1,4 +1,5 @@
(local lline (require :lualine))
(local (mztenv lline lightbulb)
(values (require :mzte_nv) (require :lualine) (require :nvim-lightbulb)))
(lline.setup {:options {:theme :catppuccin}
:sections {:lualine_b [:filename :diff]
@ -6,5 +7,7 @@
:tabline {:lualine_a [{1 :tabs
;; show file name
:mode 1}]
:lualine_x [:searchcount]
:lualine_x [:searchcount
{1 #(lightbulb.get_status_text)
:color {:fg mztenv.reg.catppuccin-palette.teal}}]
:lualine_y [:branch]}})

View file

@ -38,7 +38,8 @@
(use {1 :lewis6991/gitsigns.nvim
:config #((. (require :gitsigns) :setup) {})})
(use :dag/vim-fish)
(use/pconf use :nvim-lualine/lualine.nvim :line)
(use/pconf use :nvim-lualine/lualine.nvim :line
{:after :catppuccin :requires :lightbulb})
(use/pconf use :nvim-treesitter/nvim-treesitter :treesitter)
(use/pconf use :nvim-tree/nvim-web-devicons :devicons)
(use/pconf use :nvim-tree/nvim-tree.lua :nvimtree
@ -72,6 +73,7 @@
{:requires :jose-elias-alvarez/null-ls.nvim})
(use :nvim-treesitter/playground)
(use {1 :Olical/conjure :setup (pconf :conjure)})
(use/pconf use :kosayoda/nvim-lightbulb :lightbulb)
(cmp-plugins use))
(packer.startup init)

View file

@ -60,10 +60,27 @@ pub const std_options = struct {
pub const log_level = .debug;
};
const reg_key = "mzte-nv-reg";
export fn luaopen_mzte_nv(l_: ?*c.lua_State) c_int {
const l = l_.?;
ser.luaPushAny(l, .{
.reg = struct {
pub fn luaPush(lua: *c.lua_State) void {
c.lua_getfield(lua, c.LUA_REGISTRYINDEX, reg_key);
// registry uninitialized
if (c.lua_isnil(lua, -1)) {
c.lua_pop(lua, 1);
c.lua_newtable(lua);
c.lua_pushvalue(lua, -1);
c.lua_setfield(lua, c.LUA_REGISTRYINDEX, reg_key);
}
}
},
.onInit = ffi.luaFunc(lOnInit),
.cmp = modules.cmp,
.compile = modules.compile,
.cpbuf = modules.cpbuf,
@ -80,7 +97,7 @@ fn lOnInit(l: *c.lua_State) !c_int {
try @import("options.zig").initOptions();
std.log.info(
"MZTE-NV v{s} Initialized on NVIM v{s}",
"MZTE-NV v{s} Initialized on {s}",
.{ version, nvim.longVersion },
);
return 0;