diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lvim/config/init.lua | 18 | ||||
| -rw-r--r-- | lua/lvim/core/info.lua | 2 | ||||
| -rw-r--r-- | lua/lvim/core/log.lua | 3 | ||||
| -rw-r--r-- | lua/lvim/lsp/providers/sumneko_lua.lua | 2 | ||||
| -rw-r--r-- | lua/lvim/plugin-loader.lua | 65 | ||||
| -rw-r--r-- | lua/lvim/plugins.lua | 8 | ||||
| -rw-r--r-- | lua/lvim/utils/hooks.lua | 25 | 
7 files changed, 63 insertions, 60 deletions
| diff --git a/lua/lvim/config/init.lua b/lua/lvim/config/init.lua index c3fe0438..6927d52a 100644 --- a/lua/lvim/config/init.lua +++ b/lua/lvim/config/init.lua @@ -124,18 +124,20 @@ end  --- Override the configuration with a user provided one  -- @param config_path The path to the configuration overrides  function M:reload() -  require_clean("lvim.utils.hooks").run_pre_reload() +  vim.schedule(function() +    require_clean("lvim.utils.hooks").run_pre_reload() -  M:init() -  M:load() +    M:init() +    M:load() -  require("lvim.core.autocmds").configure_format_on_save() +    require("lvim.core.autocmds").configure_format_on_save() -  local plugins = require "lvim.plugins" -  local plugin_loader = require "lvim.plugin-loader" +    local plugins = require "lvim.plugins" +    local plugin_loader = require "lvim.plugin-loader" -  plugin_loader.load { plugins, lvim.plugins } -  require_clean("lvim.utils.hooks").run_post_reload() +    plugin_loader.reload { plugins, lvim.plugins } +    require_clean("lvim.utils.hooks").run_post_reload() +  end)  end  return M diff --git a/lua/lvim/core/info.lua b/lua/lvim/core/info.lua index da295b95..9c9652da 100644 --- a/lua/lvim/core/info.lua +++ b/lua/lvim/core/info.lua @@ -120,7 +120,7 @@ local function make_override_info(ft)  end  function M.toggle_popup(ft) -  local clients = vim.lsp.get_active_clients(ft) +  local clients = vim.lsp.get_active_clients()    local client_names = {}    local bufnr = vim.api.nvim_get_current_buf()    local ts_active_buffers = vim.tbl_keys(vim.treesitter.highlighter.active) diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index e5a6d5db..d0e74f18 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -19,6 +19,9 @@ function Log:init()      return nil    end +  package.loaded["packer.log"] = nil +  require("packer.log").new { level = lvim.log.level } +    local log_level = Log.levels[(lvim.log.level):upper() or "WARN"]    local lvim_log = {      lvim = { diff --git a/lua/lvim/lsp/providers/sumneko_lua.lua b/lua/lvim/lsp/providers/sumneko_lua.lua index 7c0030c1..fa0d2d31 100644 --- a/lua/lvim/lsp/providers/sumneko_lua.lua +++ b/lua/lvim/lsp/providers/sumneko_lua.lua @@ -2,7 +2,7 @@ local opts = {    settings = {      Lua = {        diagnostics = { -        globals = { "vim", "lvim" }, +        globals = { "vim", "lvim", "packer_plugins" },        },        workspace = {          library = { diff --git a/lua/lvim/plugin-loader.lua b/lua/lvim/plugin-loader.lua index 7612bc37..e42be52e 100644 --- a/lua/lvim/plugin-loader.lua +++ b/lua/lvim/plugin-loader.lua @@ -3,6 +3,7 @@ local plugin_loader = {}  local utils = require "lvim.utils"  local Log = require "lvim.core.log"  local join_paths = utils.join_paths +local in_headless = #vim.api.nvim_list_uis() == 0  -- we need to reuse this outside of init()  local compile_path = join_paths(get_config_dir(), "plugin", "packer_compiled.lua") @@ -22,10 +23,6 @@ function plugin_loader.init(opts)      log = { level = "warn" },      git = {        clone_timeout = 300, -      subcommands = { -        -- this is more efficient than what Packer is using -        fetch = "fetch --no-tags --no-recurse-submodules --update-shallow --progress", -      },      },      display = {        open_fn = function() @@ -34,14 +31,8 @@ function plugin_loader.init(opts)      },    } -  local in_headless = #vim.api.nvim_list_uis() == 0    if in_headless then      init_opts.display = nil - -    -- NOTE: `lvim.log.level` may not be loaded from the user's config yet -    init_opts.log.level = lvim.log and lvim.log.level or "info" -  else -    vim.cmd [[autocmd User PackerComplete lua require('lvim.utils.hooks').run_on_packer_complete()]]    end    if vim.fn.empty(vim.fn.glob(install_path)) > 0 then @@ -54,6 +45,9 @@ function plugin_loader.init(opts)    local status_ok, packer = pcall(require, "packer")    if status_ok then +    packer.on_complete = vim.schedule_wrap(function() +      require("lvim.utils.hooks").run_on_packer_complete() +    end)      packer.init(init_opts)    end  end @@ -83,6 +77,18 @@ function plugin_loader.recompile()    end  end +function plugin_loader.reload(configurations) +  _G.packer_plugins = _G.packer_plugins or {} +  for k, v in pairs(_G.packer_plugins) do +    if k ~= "packer.nvim" then +      _G.packer_plugins[v] = nil +    end +  end +  plugin_loader.load(configurations) + +  pcall_packer_command "sync" +end +  function plugin_loader.load(configurations)    Log:debug "loading plugins configuration"    local packer_available, packer = pcall(require, "packer") @@ -120,31 +126,22 @@ function plugin_loader.get_core_plugins()    return list  end -function plugin_loader.sync_core_plugins(opts) -  opts = opts or {} -  Log:debug(string.format("Syncing core plugins with snapshot file [%s]", default_snapshot)) -  local packer = require "packer" -  local a = require "packer.async" -  local async = a.sync -  local await = a.wait -  local main = a.main +function plugin_loader.load_snapshot(snapshot_file) +  snapshot_file = snapshot_file or default_snapshot +  if not in_headless then +    vim.notify("Syncing core plugins is in progress..", vim.log.levels.INFO, { title = "lvim" }) +  end +  Log:debug(string.format("Using snapshot file [%s]", snapshot_file))    local core_plugins = plugin_loader.get_core_plugins() -  async(function() -    await(packer.rollback(default_snapshot, unpack(core_plugins))) -      :map_ok(function(ok) --NOTE: these may not be doing anything, use PackerComplete for now -        await(main) -        Log:debug(string.format("Rollback snapshot file [%s] completed", default_snapshot)) -        if next(ok.failed) then -          Log:warn(string.format("Couldn't rollback %s", vim.inspect(ok.failed))) -        end -        pcall(opts.on_complete, ok) -      end) -      :map_err(function(err) -        await(main) -        Log:error(err) -        pcall(opts.on_error, err) -      end) -  end)() +  require("packer").rollback(snapshot_file, unpack(core_plugins)) +end + +function plugin_loader.sync_core_plugins() +  -- problem: rollback() will get stuck if a plugin directory doesn't exist +  -- solution: call sync() beforehand +  -- see https://github.com/wbthomason/packer.nvim/issues/862 +  vim.cmd [[autocmd User PackerComplete ++once lua require("lvim.plugin-loader").load_snapshot() ]] +  pcall_packer_command "sync"  end  return plugin_loader diff --git a/lua/lvim/plugins.lua b/lua/lvim/plugins.lua index 9ead83d2..519a203a 100644 --- a/lua/lvim/plugins.lua +++ b/lua/lvim/plugins.lua @@ -13,8 +13,12 @@ local core_plugins = {    {      "lunarvim/onedarker.nvim",      config = function() -      require("onedarker").setup() -      lvim.builtin.lualine.options.theme = "onedarker" +      pcall(function() +        if lvim and lvim.colorscheme == "onedarker" then +          require("onedarker").setup() +          lvim.builtin.lualine.options.theme = "onedarker" +        end +      end)      end,      disable = lvim.colorscheme ~= "onedarker",    }, diff --git a/lua/lvim/utils/hooks.lua b/lua/lvim/utils/hooks.lua index 8b057884..932f9c3d 100644 --- a/lua/lvim/utils/hooks.lua +++ b/lua/lvim/utils/hooks.lua @@ -12,25 +12,22 @@ function M.run_pre_reload()  end  function M.run_on_packer_complete() -  vim.schedule(function() -    if not in_headless then -      -- colorscheme must get called after plugins are loaded or it will break new installs. -      vim.g.colors_name = lvim.colorscheme -      vim.cmd("colorscheme " .. lvim.colorscheme) -    else -      Log:debug "Packer operation complete" -    end -  end) +  Log:debug "Packer operation complete" +  vim.cmd [[doautocmd User PackerComplete]] + +  vim.g.colors_name = lvim.colorscheme +  pcall(vim.cmd, "colorscheme " .. lvim.colorscheme) + +  if M._reload_triggered then +    Log:info "Reloaded configuration" +    M._reload_triggered = nil +  end  end  function M.run_post_reload()    Log:debug "Starting post-reload hook"    M.reset_cache() -  vim.schedule(function() -    if not in_headless then -      Log:info "Reloaded configuration" -    end -  end) +  M._reload_triggered = true  end  ---Reset any startup cache files used by Packer and Impatient | 
