summaryrefslogtreecommitdiff
path: root/lua/lvim/plugin-loader.lua
diff options
context:
space:
mode:
authorkylo252 <[email protected]>2021-10-10 21:07:41 +0200
committerGitHub <[email protected]>2021-10-10 21:07:41 +0200
commit52b74557415eb757ad4b7481b0aec8a3f98dd58d (patch)
tree9a05ec71a46c99fbdf8df0043be652b528c7c04e /lua/lvim/plugin-loader.lua
parente2c85df440564a62fd804555747b1652a6844a5e (diff)
feat: add an independent lvim namespace (#1699)
Diffstat (limited to 'lua/lvim/plugin-loader.lua')
-rw-r--r--lua/lvim/plugin-loader.lua63
1 files changed, 63 insertions, 0 deletions
diff --git a/lua/lvim/plugin-loader.lua b/lua/lvim/plugin-loader.lua
new file mode 100644
index 00000000..feef7ea7
--- /dev/null
+++ b/lua/lvim/plugin-loader.lua
@@ -0,0 +1,63 @@
+local plugin_loader = {}
+
+local utils = require "lvim.utils"
+local Log = require "lvim.core.log"
+-- we need to reuse this outside of init()
+local compile_path = get_config_dir() .. "/plugin/packer_compiled.lua"
+
+function plugin_loader:init(opts)
+ opts = opts or {}
+
+ local install_path = opts.install_path or vim.fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim"
+ local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack"
+
+ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
+ vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
+ vim.cmd "packadd packer.nvim"
+ end
+
+ local packer_ok, packer = pcall(require, "packer")
+ if not packer_ok then
+ return
+ end
+
+ packer.init {
+ package_root = package_root,
+ compile_path = compile_path,
+ git = { clone_timeout = 300 },
+ display = {
+ open_fn = function()
+ return require("packer.util").float { border = "rounded" }
+ end,
+ },
+ }
+
+ self.packer = packer
+ return self
+end
+
+function plugin_loader:cache_clear()
+ if vim.fn.delete(compile_path) == 0 then
+ Log:debug "deleted packer_compiled.lua"
+ end
+end
+
+function plugin_loader:cache_reset()
+ self.cache_clear()
+ require("packer").compile()
+ if utils.is_file(compile_path) then
+ Log:debug "generated packer_compiled.lua"
+ end
+end
+
+function plugin_loader:load(configurations)
+ return self.packer.startup(function(use)
+ for _, plugins in ipairs(configurations) do
+ for _, plugin in ipairs(plugins) do
+ use(plugin)
+ end
+ end
+ end)
+end
+
+return plugin_loader