fix: cwd not set upon loading first buffer#20
Conversation
lua/resession/init.lua
Outdated
| -- Set global options before loading the first buffer | ||
| if i == 1 and not data.tab_scoped then | ||
| util.restore_global_options(data.global.options) | ||
| vim.api.nvim_set_current_dir(data.global.cwd) | ||
| end |
There was a problem hiding this comment.
This doesn't feel like the right way to do this. If the first buffer in the restore list was unloaded, then we will never restore the global options.
Could this be fixed by just adding another
if not data.tab_scoped then
vim.api.nvim_set_current_dir(data.global.cwd)
endafter the tabs and buffers are all restored?
There was a problem hiding this comment.
Yeah nvm, I found an edgecase where if one of the buffers in the restore list is not under the cwd, then the relative file path does not show correctly for all the subsequent buffers, even those buffers are under the cwd. Removing the check for the first buffer fixes this, but it feels redundant to repeatedly set global options for each buffer.
I'll try out your suggestion
There was a problem hiding this comment.
@stevearc setting the cwd again after loading all buffers/tabs seems to work
8c34f4e to
4156d71
Compare
|
Thanks for the PR! |
Problem: Normally,
<c-g>and:wwill output a message with the current buffer's filename relative the the cwd. However, when the buffer is restored from a session, the message (as well as the default statusline) show the filename relative the home directory instead. This doesn't seem to happen in tab-scoped sessions where each tab has its own cwd.Before saving session (cwd set to

~/Documents):After restoring session:

In the "after" screenshot, the cwd is set correctly, but the filename is displayed as if it were set to the home directory.
Solution: This PR resolves the issue by setting global options upon loading the first buffer. It also uses the lua api to set the cwd instead of
vim.cmd.