Skip to content

Commit

Permalink
πŸš€ feat(core): Add lazy loading support for Neovim plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Syuq committed Mar 7, 2024
1 parent db2ddc0 commit c07a7b2
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lua/core/lazy_nvim.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local uv, api, fn = vim.uv, vim.api, vim.fnlocal helper = require('core.helper')local global = require('core.global')local win = global.is_windowslocal lazy = {}lazy.__index = lazylocal start = global.startlocal sep = global.path_sepfunction lazy.add(repo) if not repo then return end if not lazy then lazy = { plug = {} } end if not lazy.plug then lazy.plug = {} end if repo.lazy == nil then repo.lazy = true end table.insert(lazy.plug, repo)endlocal createdir = function() local data_dir = { global.cache_dir .. global.path_sep .. 'backup', global.cache_dir .. global.path_sep .. 'sessions', global.cache_dir .. global.path_sep .. 'swap', global.cache_dir .. global.path_sep .. 'tags', global.cache_dir .. global.path_sep .. 'undo', } -- There only check once that If cache_dir exists -- Then I don't want to check subs dir exists for _, v in pairs(data_dir) do if vim.fn.isdirectory(v) == 0 then os.execute('mkdir -p ' .. v) end endendfunction lazy:load_modules_lazy() createdir() if not win then vim.loader.enable() end local modules_dir = helper.get_config_path() .. sep .. 'lua' .. sep .. 'modules' self.repos = {} -- stylua: ignore local plugins_list = { modules_dir .. sep .. 'completion' .. sep .. 'plugins.lua', modules_dir .. sep .. 'lang' .. sep .. 'plugins.lua', modules_dir .. sep .. 'ui' .. sep .. 'plugins.lua', modules_dir .. sep .. 'editor' .. sep .. 'plugins.lua', modules_dir .. sep .. 'tools' .. sep .. 'plugins.lua', } if vim.g.vscode then -- stylua: ignore plugins_list = { modules_dir .. sep .. 'editor' .. sep .. 'plugins.lua', modules_dir .. sep .. 'tools' .. sep .. 'plugins.lua', } end local disable_modules = {} if fn.exists('g:disable_modules') == 1 then disable_modules = vim.split(vim.g.disable_modules, ',') end for _, f in pairs(plugins_list) do if win then f = string.gsub(f, '/', '\\') end local _, pos = f:find(modules_dir) if pos then f = f:sub(pos - 6, #f - 4) end -- lprint(f) -- modules/completion/plugins ... if not vim.tbl_contains(disable_modules, f) then local plugins = require(f) plugins(lazy.add) lprint('loaded ' .. f, vim.uv.now() - start) end end lprint('lazy modules loaded', vim.loop.now() - start)endfunction lazy:boot_strap() local fsize = vim.fn.getfsize(vim.fn.expand('%:p:f')) if fsize == nil or fsize < 0 then fsize = 1 end if fsize >= 10*1024*1024 then return fsize end local start = uv.now() local lazy_path = string.format('%s%slazy%slazy.nvim', helper.get_data_path(), sep, sep) local state = uv.fs_stat(lazy_path) if not state then local cmd = '!git clone https://github.com/folke/lazy.nvim ' .. lazy_path vim.cmd(cmd) end vim.opt.runtimepath:prepend(lazy_path) local lz = require('lazy') local opts = { lockfile = helper.get_data_path() .. sep .. 'lazy-lock.json', dev = { path = win and global.home .. '\\github\\ray-x' or '~/github/ray-x' }, } self:load_modules_lazy() lz.setup(self.plug, opts) lprint(' lazy boot_strap ', vim.uv.now() - start) -- setup luarock (image.nvim) -- stylua: ignore package.path = package.path .. ';' .. vim.fn.expand('$HOME') .. '/.luarocks/share/lua/5.1/?/init.lua' package.path = package.path .. ';' .. vim.fn.expand('$HOME') .. '/.luarocks/share/lua/5.1/?.lua'endreturn lazy
Expand Down

0 comments on commit c07a7b2

Please sign in to comment.