mzte-nv: load plugins in chunked event loop callbacks

TODO: move into MZTE-NV with libUV idler
This commit is contained in:
LordMZTE 2024-04-14 16:55:23 +02:00
parent 73b009dd51
commit acf4abc8ba
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 56 additions and 44 deletions

View file

@ -7,16 +7,5 @@
:ignore false} :ignore false}
:renderer {:indent_markers {:enable true} :group_empty true}}) :renderer {:indent_markers {:enable true} :group_empty true}})
;; open on startup
(fn on-enter [data]
(local is-no-name (and (= data.file "") (= (. vim :bo data.buf :buftype) "")))
(local is-dir (= (vim.fn.isdirectory data.file) 1))
(when is-dir
(vim.cmd.cd data.file))
(when (or is-no-name is-dir)
((. (require :nvim-tree.api) :tree :open))))
(vim.api.nvim_create_autocmd [:VimEnter] {:callback on-enter})
(vim.keymap.set :n :TT #((. (require :nvim-tree.api) :tree :toggle)) (vim.keymap.set :n :TT #((. (require :nvim-tree.api) :tree :toggle))
(. (require :mzte_nv) :utils :map_opt)) (. (require :mzte_nv) :utils :map_opt))

View file

@ -34,7 +34,7 @@
(tset opt k v)) (tset opt k v))
`(do `(do
(nmap ,(.. :g suffix) ,action ,opt) (nmap ,(.. :g suffix) ,action ,opt)
(nmap ,(.. :gt suffix) ,action (nmap ,(.. :gn suffix) ,action
,(doto (collect [k v (pairs opt)] k v) ,(doto (collect [k v (pairs opt)] k v)
(tset :jump_type :tab))) (tset :jump_type :tab)))
(nmap ,(.. :gs suffix) ,action (nmap ,(.. :gs suffix) ,action

View file

@ -1,38 +1,61 @@
(local mztenv (require :mzte_nv)) (local mztenv (require :mzte_nv))
(tset mztenv.reg :plugin_load_callbacks [])
(let [path mztenv.reg.nvim_plugins] (let [path mztenv.reg.nvim_plugins]
(when path (when path
(vim.opt.runtimepath:append (.. path "/*")))) (vim.opt.runtimepath:append (.. path "/*"))))
(let [plugins [:lspconf ;; Plugins to load before nvim finishes startup
:cmp (local startup-plugins [])
:luasnip
:nullls ;; Plugins to load in the background
:catppuccin (local deferred-plugins [:lspconf
:line :cmp
:treesitter :luasnip
:devicons :nullls
:nvimtree :catppuccin
:neogit :line
:telescope :treesitter
:autopairs :nvimtree
:tterm :devicons
:ts-context :neogit
:ufo :telescope
:aerial :autopairs
:dap :tterm
:harpoon :ts-context
:recorder :ufo
:noice :aerial
:tsn-actions :dap
:lightbulb :harpoon
:dressing] :recorder
errors {}] :noice
(each [_ p (ipairs plugins)] :tsn-actions
(let [(success ret) (pcall require (.. :pluginconf/p- p))] :lightbulb
(when (not success) :dressing])
(tset errors p ret))))
(when (next errors) (local errors {})
(vim.notify (accumulate [text "Errors loading plugin configs:\n" plugin err (pairs errors)]
(.. text " - " plugin ": " err)) (fn load-plugin [plugin]
vim.log.levels.error))) (let [(success ret) (pcall require (.. :pluginconf/p- plugin))]
(when (not success)
(tset errors p ret))))
(each [_ p (ipairs startup-plugins)]
(load-plugin p))
(fn load-one-deferred [idx]
(let [plugin (. deferred-plugins idx)]
(if plugin
(do
(load-plugin plugin)
(vim.schedule #(load-one-deferred (+ idx 1))))
(do
(when (next errors)
(vim.notify (accumulate [text "Errors loading plugin configs:\n" plugin err (pairs errors)]
(.. text " - " plugin ": " err))
vim.log.levels.error))
(each [_ cb (ipairs mztenv.reg.plugin_load_callbacks)]
(pcall cb))))))
(vim.schedule #(load-one-deferred 1))