-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
end
after the tabs and buffers are all restored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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:w
will 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
.