Skip to content

Commit

Permalink
fix(session): try to minimize error when switching sessions
Browse files Browse the repository at this point in the history
NOTE:
- single tab session switching now work as expected without error
- inactive tab won't be saved and restored as `scope.nvim` is making those buffer unlisted
  - also some error might occur when restoring (e.g. bufnr xxx does not exist)
- resolve incorrect cwd when loading session, which is caused by `ProjectRoot` called too fast

TODO:
- multiple tab session support
  • Loading branch information
WilliamHsieh committed Nov 20, 2024
1 parent 5c305f5 commit cacb077
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config/nvim/lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ return {

{
"ahmedkhalf/project.nvim",
event = "LazyFile",
cmd = "ProjectRoot",
config = function()
require("project_nvim").setup {
-- manual_mode = true,
manual_mode = true,
ignore_lsp = { "null-ls", "copilot" },
}
require("core.utils").on_load("telescope.nvim", function()
Expand Down
27 changes: 27 additions & 0 deletions config/nvim/lua/plugins/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@

local M = {
"Shatur/neovim-session-manager",
dependencies = "scope.nvim",
cmd = "SessionManager",
event = "LazyFile",
}

M.init = function()
vim.opt.sessionoptions = "curdir,tabpages,winsize,globals,buffers"
end

M.config = function()
-- vim.api.nvim_create_autocmd("User", {
-- pattern = "SessionLoadPost",
Expand All @@ -16,7 +22,28 @@ M.config = function()

require("session_manager").setup {
autoload_mode = require("session_manager.config").AutoloadMode.Disabled,
-- autosave_last_session = false,
}

local group = vim.api.nvim_create_augroup("dotfiles_session_manager", {})

vim.api.nvim_create_autocmd("VimLeavePre", {
group = group,
callback = function()
vim.cmd.ProjectRoot()
vim.cmd.ScopeSaveState()
require("session_manager").save_current_session()
end,
})

vim.api.nvim_create_autocmd({ "User" }, {
pattern = "SessionSavePost",
group = group,
callback = function()
-- so switching between projects doesn't mess up lsp related stuff (e.g. semantic tokens)
pcall(vim.cmd.LspStop)
end,
})
end

return M

0 comments on commit cacb077

Please sign in to comment.