summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/bootstrap.lua11
-rw-r--r--lua/core/which-key.lua1
-rw-r--r--lua/plugin-loader.lua20
-rw-r--r--lua/utils/init.lua26
4 files changed, 49 insertions, 9 deletions
diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua
index 695dacdc..85d39d2d 100644
--- a/lua/bootstrap.lua
+++ b/lua/bootstrap.lua
@@ -38,6 +38,8 @@ function M:init()
self.cache_path = get_cache_dir()
self.pack_dir = join_paths(self.runtime_dir, "site", "pack")
+ self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim")
+ self.packer_cache_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua")
if os.getenv "LUNARVIM_RUNTIME_DIR" then
vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site"))
@@ -57,6 +59,7 @@ function M:init()
-- FIXME: currently unreliable in unit-tests
if not os.getenv "LVIM_TEST_ENV" then
+ vim.fn.mkdir(vim.fn.stdpath "cache", "p")
require("impatient").setup {
path = vim.fn.stdpath "cache" .. "/lvim_cache",
enable_profiling = true,
@@ -69,12 +72,8 @@ function M:init()
}
require("plugin-loader"):init {
- cache_path = self.cache_path,
- runtime_dir = self.runtime_dir,
- config_dir = self.config_dir,
- install_path = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim"),
- package_root = join_paths(self.runtime_dir, "site", "pack"),
- compile_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua"),
+ package_root = self.pack_dir,
+ install_path = self.packer_install_dir,
}
return self
diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua
index ef74ee51..3379100d 100644
--- a/lua/core/which-key.lua
+++ b/lua/core/which-key.lua
@@ -209,6 +209,7 @@ M.config = function()
},
P = { "<cmd>edit ~/.cache/nvim/packer.nvim.log<cr>", "Open the Packer logfile" },
},
+ r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload configurations" },
},
s = {
name = "Search",
diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua
index 08f0e5a0..c20dd21a 100644
--- a/lua/plugin-loader.lua
+++ b/lua/plugin-loader.lua
@@ -1,11 +1,15 @@
local plugin_loader = {}
+local utils = require "utils"
+local Log = require "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"
- local compile_path = opts.compile_path or vim.fn.stdpath "config" .. "/plugin/packer_compile.lua"
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 }
@@ -32,6 +36,20 @@ function plugin_loader:init(opts)
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
diff --git a/lua/utils/init.lua b/lua/utils/init.lua
index 100ab628..5a5e4ba3 100644
--- a/lua/utils/init.lua
+++ b/lua/utils/init.lua
@@ -93,9 +93,11 @@ function utils.reload_lv_config()
vim.cmd("source " .. utils.join_paths(get_runtime_dir(), "lvim", "lua", "plugins.lua"))
local plugins = require "plugins"
utils.toggle_autoformat()
- require("plugin-loader"):load { plugins, lvim.plugins }
- vim.cmd ":PackerCompile"
+ local plugin_loader = require "plugin-loader"
+ plugin_loader:cache_reset()
+ plugin_loader:load { plugins, lvim.plugins }
vim.cmd ":PackerInstall"
+ vim.cmd ":PackerCompile"
-- vim.cmd ":PackerClean"
local null_ls = require "lsp.null-ls"
null_ls.setup(vim.bo.filetype, { force_reload = true })
@@ -118,6 +120,18 @@ function utils.gsub_args(args)
return args
end
+--- Returns a table with the default values that are missing.
+--- either paramter can be empty.
+--@param config (table) table containing entries that take priority over defaults
+--@param default_config (table) table contatining default values if found
+function utils.apply_defaults(config, default_config)
+ config = config or {}
+ default_config = default_config or {}
+ local new_config = vim.tbl_deep_extend("keep", vim.empty_dict(), config)
+ new_config = vim.tbl_deep_extend("keep", new_config, default_config)
+ return new_config
+end
+
--- Checks whether a given path exists and is a file.
--@param filename (string) path to check
--@returns (bool)
@@ -132,6 +146,14 @@ function utils.join_paths(...)
return result
end
+function utils.lvim_cache_reset()
+ _G.__luacache.clear_cache()
+ _G.__luacache.save_cache()
+ require("plugin-loader"):cache_reset()
+end
+
+vim.cmd [[ command! LvimCacheReset lua require('utils').lvim_cache_reset() ]]
+
return utils
-- TODO: find a new home for these autocommands