mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-31 15:19:26 +02:00
feat: multiple enhancements to lvim-reload (#2054)
This commit is contained in:
parent
68cdb62f87
commit
307db8936b
4 changed files with 64 additions and 32 deletions
|
@ -98,28 +98,20 @@ end
|
||||||
--- Override the configuration with a user provided one
|
--- Override the configuration with a user provided one
|
||||||
-- @param config_path The path to the configuration overrides
|
-- @param config_path The path to the configuration overrides
|
||||||
function M:reload()
|
function M:reload()
|
||||||
local lvim_modules = {}
|
package.loaded["lvim.utils.hooks"] = nil
|
||||||
for module, _ in pairs(package.loaded) do
|
local _, hooks = pcall(require, "lvim.utils.hooks")
|
||||||
if module:match "lvim.core" then
|
hooks.run_pre_reload()
|
||||||
package.loaded[module] = nil
|
|
||||||
table.insert(lvim_modules, module)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
M:init()
|
M:init()
|
||||||
M:load()
|
M:load()
|
||||||
|
|
||||||
|
require("lvim.core.autocmds").configure_format_on_save()
|
||||||
|
|
||||||
local plugins = require "lvim.plugins"
|
local plugins = require "lvim.plugins"
|
||||||
local autocmds = require "lvim.core.autocmds"
|
|
||||||
autocmds.configure_format_on_save()
|
|
||||||
local plugin_loader = require "lvim.plugin-loader"
|
local plugin_loader = require "lvim.plugin-loader"
|
||||||
plugin_loader.cache_clear()
|
|
||||||
plugin_loader.load { plugins, lvim.plugins }
|
plugin_loader.load { plugins, lvim.plugins }
|
||||||
vim.cmd ":PackerInstall"
|
hooks.run_post_reload()
|
||||||
vim.cmd ":PackerCompile"
|
|
||||||
-- vim.cmd ":PackerClean"
|
|
||||||
require("lvim.lsp").setup()
|
|
||||||
Log:info "Reloaded configuration"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -22,11 +22,12 @@ function M.get_active_clients_by_ft(filetype)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_client_capabilities(client_id)
|
function M.get_client_capabilities(client_id)
|
||||||
|
local client
|
||||||
if not client_id then
|
if not client_id then
|
||||||
local buf_clients = vim.lsp.buf_get_clients()
|
local buf_clients = vim.lsp.buf_get_clients()
|
||||||
for _, buf_client in ipairs(buf_clients) do
|
for _, buf_client in pairs(buf_clients) do
|
||||||
if buf_client.name ~= "null-ls" then
|
if buf_client.name ~= "null-ls" then
|
||||||
client_id = buf_client.id
|
client = buf_client
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,8 +37,6 @@ function M.get_client_capabilities(client_id)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local client = vim.lsp.get_client_by_id(tonumber(client_id))
|
|
||||||
|
|
||||||
local enabled_caps = {}
|
local enabled_caps = {}
|
||||||
for capability, status in pairs(client.resolved_capabilities) do
|
for capability, status in pairs(client.resolved_capabilities) do
|
||||||
if status == true then
|
if status == true then
|
||||||
|
|
|
@ -28,7 +28,13 @@ function plugin_loader.init(opts)
|
||||||
package_root = package_root,
|
package_root = package_root,
|
||||||
compile_path = compile_path,
|
compile_path = compile_path,
|
||||||
log = { level = log_level },
|
log = { level = log_level },
|
||||||
git = { clone_timeout = 300 },
|
git = {
|
||||||
|
clone_timeout = 300,
|
||||||
|
subcommands = {
|
||||||
|
-- this is more efficient than what Packer is using
|
||||||
|
fetch = "fetch --no-tags --no-recurse-submodules --update-shallow --progress",
|
||||||
|
},
|
||||||
|
},
|
||||||
max_jobs = 50,
|
max_jobs = 50,
|
||||||
display = {
|
display = {
|
||||||
open_fn = function()
|
open_fn = function()
|
||||||
|
@ -36,6 +42,8 @@ function plugin_loader.init(opts)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vim.cmd [[autocmd User PackerComplete lua require('lvim.utils.hooks').run_on_packer_complete()]]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- packer expects a space separated list
|
-- packer expects a space separated list
|
||||||
|
@ -104,4 +112,11 @@ function plugin_loader.sync_core_plugins()
|
||||||
pcall_packer_command("sync", core_plugins)
|
pcall_packer_command("sync", core_plugins)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function plugin_loader.ensure_installed()
|
||||||
|
plugin_loader.cache_clear()
|
||||||
|
local all_plugins = _G.packer_plugins or plugin_loader.get_core_plugins()
|
||||||
|
Log:trace(string.format("Syncing core plugins: [%q]", table.concat(all_plugins, ", ")))
|
||||||
|
pcall_packer_command("install", all_plugins)
|
||||||
|
end
|
||||||
|
|
||||||
return plugin_loader
|
return plugin_loader
|
||||||
|
|
|
@ -1,38 +1,64 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local plugin_loader = require "lvim.plugin-loader"
|
|
||||||
local Log = require "lvim.core.log"
|
local Log = require "lvim.core.log"
|
||||||
local in_headless = #vim.api.nvim_list_uis() == 0
|
local in_headless = #vim.api.nvim_list_uis() == 0
|
||||||
|
|
||||||
function M.run_pre_update()
|
function M.run_pre_update()
|
||||||
Log:debug "Starting pre-update hook"
|
Log:debug "Starting pre-update hook"
|
||||||
_G.__luacache.clear_cache()
|
|
||||||
if package.loaded["lspconfig"] then
|
if package.loaded["lspconfig"] then
|
||||||
vim.cmd [[ LspStop ]]
|
vim.cmd [[ LspStop ]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.run_pre_reload()
|
||||||
|
Log:debug "Starting pre-reload hook"
|
||||||
|
if package.loaded["lspconfig"] then
|
||||||
|
vim.cmd [[ LspStop ]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.run_on_packer_complete()
|
||||||
|
require("lvim.plugin-loader").recompile()
|
||||||
|
-- forcefully activate nvim-web-devicons
|
||||||
|
require("nvim-web-devicons").set_up_highlights()
|
||||||
|
Log:info "Reloaded configuration"
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.run_post_reload()
|
||||||
|
Log:debug "Starting post-reload hook"
|
||||||
|
if package.loaded["lspconfig"] then
|
||||||
|
vim.cmd [[ LspRestart ]]
|
||||||
|
end
|
||||||
|
|
||||||
|
M.reset_cache()
|
||||||
|
require("lvim.plugin-loader").ensure_installed()
|
||||||
|
end
|
||||||
|
|
||||||
---Reset any startup cache files used by Packer and Impatient
|
---Reset any startup cache files used by Packer and Impatient
|
||||||
---It also forces regenerating any template ftplugin files
|
---It also forces regenerating any template ftplugin files
|
||||||
---Tip: Useful for clearing any outdated settings
|
---Tip: Useful for clearing any outdated settings
|
||||||
function M.reset_cache()
|
function M.reset_cache()
|
||||||
_G.__luacache.clear_cache()
|
local impatient = _G.__luacache
|
||||||
require("lvim.plugin-loader").recompile()
|
if impatient then
|
||||||
package.loaded["lvim.lsp.templates"] = nil
|
impatient.clear_cache()
|
||||||
|
end
|
||||||
Log:debug "Re-generatring ftplugin template files"
|
local lvim_modules = {}
|
||||||
|
for module, _ in pairs(package.loaded) do
|
||||||
|
if module:match "lvim.core" or module:match "lvim.lsp" then
|
||||||
|
package.loaded[module] = nil
|
||||||
|
table.insert(lvim_modules, module)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Log:trace(string.format("Cache invalidated for core modules: { %s }", table.concat(lvim_modules, ", ")))
|
||||||
require("lvim.lsp.templates").generate_templates()
|
require("lvim.lsp.templates").generate_templates()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run_post_update()
|
function M.run_post_update()
|
||||||
Log:debug "Starting post-update hook"
|
Log:debug "Starting post-update hook"
|
||||||
|
M.reset_cache()
|
||||||
Log:debug "Re-generatring ftplugin template files"
|
|
||||||
package.loaded["lvim.lsp.templates"] = nil
|
|
||||||
require("lvim.lsp.templates").generate_templates()
|
|
||||||
|
|
||||||
Log:debug "Updating core plugins"
|
Log:debug "Updating core plugins"
|
||||||
plugin_loader:sync_core_plugins()
|
require("lvim.plugin-loader").ensure_installed()
|
||||||
|
|
||||||
if not in_headless then
|
if not in_headless then
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue