Skip to content

Commit

Permalink
Merge pull request #360 from cameronr/main
Browse files Browse the repository at this point in the history
feat: add lazy load checks to checkhealth
  • Loading branch information
cameronr authored Aug 27, 2024
2 parents 5588169 + 83fd1df commit f8ccc1b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,13 @@ nvim --cmd "let g:auto_session_enabled = v:false"

## 🚧 Troubleshooting

For troubleshooting refer to the [wiki page](https://github.com/rmagatti/auto-session/wiki/Troubleshooting).
First run `:checkhealth auto-session` to see if it detects any problems.

If that doesn't help, you can:

- refer to the [wiki page](https://github.com/rmagatti/auto-session/wiki/Troubleshooting).
- check the [Discussions](https://github.com/rmagatti/auto-session/discussions)
- or file an [Issue](https://github.com/rmagatti/auto-session/issues)

# Compatibility

Expand Down
2 changes: 1 addition & 1 deletion lua/auto-session/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ local defaults = {
auto_restore = true, -- Enables/disables auto restoring session on start
auto_create = true, -- Enables/disables auto creating new session files. Can take a function that should return true/false if a new session file should be created or not
suppressed_dirs = nil, -- Suppress session restore/create in certain directories
alloweded_dirs = nil, -- Allow session restore/create in certain directories
allowed_dirs = nil, -- Allow session restore/create in certain directories
auto_restore_last_session = false, -- On startup, loads the last saved session if session for cwd does not exist
use_git_branch = false, -- Include git branch name in session name
lazy_support = true, -- Automatically detect if Lazy.nvim is being used and wait until Lazy is done to make sure session is restored correctly. Does nothing if Lazy isn't being used. Can be disabled if a problem is suspected or for debugging
Expand Down
47 changes: 47 additions & 0 deletions lua/auto-session/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,56 @@ local function check_session_options()
end
end

local function check_lazy_settings()
local success, lazy = pcall(require, "lazy")

start "Lazy.nvim settings"

if not success or not lazy then
info "Lazy.nvim not loaded"
return
end

if not Config.lazy_support then
warn(
"Lazy.nvim is present but `lazy_support` is not enabled. This will cause problems when trying\n"
.. "to auto-restore a session while the Lazy.nvim window is up. You probably want to add\n"
.. "`lazy_support = true,` to your config (or remove the line that's setting it to false)"
)
else
ok "Lazy.nvim support is enabled"
end

local plugins = lazy.plugins()
for _, plugin in ipairs(plugins) do
if plugin.name == "auto-session" then
if plugin.lazy then
warn(
"auto-session is set to lazy load. This will prevent auto-restoring.\n"
.. "You probably want to change your auto-session lazy spec to be something like\n\n"
.. [[
{
'rmagatti/auto-session',
lazy = true,
opts = {
-- your config here
}
}
]]
)
else
ok "auto-session is not lazy loaded"
end

return
end
end
end

function M.check()
start "vim options"
check_session_options()
check_lazy_settings()

start "Config"
if Config.has_old_config then
Expand Down

0 comments on commit f8ccc1b

Please sign in to comment.