Skip to content
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

Merged
merged 3 commits into from
Aug 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lua/resession/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,18 @@ M.load = function(name, opts)
-- Ignore all messages (including swapfile messages) during session load
local shortmess = vim.o.shortmess
vim.o.shortmess = "aAF"
if not data.tab_scoped then
-- Set the options immediately
util.restore_global_options(data.global.options)
vim.cmd(string.format("cd %s", data.global.cwd))
end
local scale = {
vim.o.columns / data.global.width,
(vim.o.lines - vim.o.cmdheight) / data.global.height,
}
for _, buf in ipairs(data.buffers) do
for i, buf in ipairs(data.buffers) do
local bufnr = vim.fn.bufadd(buf.name)
if buf.loaded then
-- 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
Copy link
Owner

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

vim.fn.bufload(bufnr)
vim.b[bufnr]._resession_need_edit = true
vim.api.nvim_create_autocmd("BufEnter", {
Expand Down