Skip to content

Commit

Permalink
fix(config): properly handle uis connecting after startup
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 7, 2023
1 parent 457e65e commit 5ed89b5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
49 changes: 25 additions & 24 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ M.me = nil
M.mapleader = nil

function M.headless()
return #vim.api.nvim_list_uis() == 0
return #vim.api.nvim_list_uis() == 0
end

---@param opts? LazyConfig
Expand Down Expand Up @@ -204,31 +204,32 @@ function M.setup(opts)

if M.headless() then
require("lazy.view.commands").setup()
else
vim.api.nvim_create_autocmd("UIEnter", {
callback = function()
require("lazy.stats").on_ui_enter()
end,
})

vim.api.nvim_create_autocmd("User", {
pattern = "VeryLazy",
once = true,
callback = function()
require("lazy.core.cache").autosave()
require("lazy.view.commands").setup()
if M.options.change_detection.enabled then
require("lazy.manage.reloader").enable()
end
if M.options.checker.enabled then
vim.defer_fn(function()
require("lazy.manage.checker").start()
end, 10)
end
end,
})
end

vim.api.nvim_create_autocmd("UIEnter", {
once = true,
callback = function()
require("lazy.stats").on_ui_enter()
end,
})

vim.api.nvim_create_autocmd("User", {
pattern = "VeryLazy",
once = true,
callback = function()
require("lazy.core.cache").autosave()
require("lazy.view.commands").setup()
if M.options.change_detection.enabled then
require("lazy.manage.reloader").enable()
end
if M.options.checker.enabled then
vim.defer_fn(function()
require("lazy.manage.checker").start()
end, 10)
end
end,
})

Util.very_lazy()
end

Expand Down
1 change: 1 addition & 0 deletions lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ end
function M.very_lazy()
local function _load()
vim.defer_fn(function()
vim.g.did_very_lazy = true
vim.cmd("do User VeryLazy")
end, 50)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/manage/checker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function M.report(notify)
end
end
end
if #lines > 0 and notify and Config.options.checker.notify then
if #lines > 0 and notify and Config.options.checker.notify and not Config.headless() then
table.insert(lines, 1, "# Plugin Updates")
Util.info(lines)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/manage/reloader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function M.check(start)

if not (start or #changes == 0) then
vim.schedule(function()
if Config.options.change_detection.notify then
if Config.options.change_detection.notify and not Config.headless() then
local lines = { "# Config Change Detected. Reloading...", "" }
for _, change in ipairs(changes) do
table.insert(lines, "- **" .. change.what .. "**: `" .. vim.fn.fnamemodify(change.file, ":p:~:.") .. "`")
Expand Down

0 comments on commit 5ed89b5

Please sign in to comment.