Skip to content

[Feature] Track current session without relying on vim.v.this_session in current_session_name #250

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

Closed
rosingrind opened this issue Aug 15, 2023 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@rosingrind
Copy link

Describe the bug
I'm using auto-session with lualine integration:

lualine_c = {
    { 
        function()
            return require('auto-session.lib').current_session_name()
        end
    }
}

It seems that after deleting a session with SessionDelete, current session name is not updated (re-opening nvim required)

To Reproduce
Steps to reproduce the behavior:

  1. Create a session with :SessionSave and see it immediately reflected on lualine
  2. Delete current session
  3. Session name is stuck in lualine

Expected behavior
Session name should be updated

Screenshots
If applicable, add screenshots to help explain your problem.

Baseline (please complete the following information):

  • Result of set sessionoptions?: sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions
  • OS. e.g uname -a: Darwin Benos-MacBook-Air.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103 arm64
  • Neovim version nvim --version

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

@rosingrind rosingrind added the bug Something isn't working label Aug 15, 2023
@rmagatti
Copy link
Owner

Hey, you are correct. This likely happens because vim.v.this_session is not changed when SessionDelete is called.

Meaning this implementation would still return the same value regardless of the session file being deleted or not:

function Lib.current_session_name()
  local fname = Lib.get_file_name(vim.v.this_session)
  local extension = Lib.get_file_extension(fname)
  local fname_without_extension = fname:gsub(extension:gsub("%.", "%%%.") .. "$", "")
  local fname_split = vim.split(fname_without_extension, "%%")
  local session_name = fname_split[#fname_split] or ""
  return session_name
end

@rosingrind
Copy link
Author

So, is this an intended behavior? I've thought that this is a bug 🤔
If that's how we roll, should I somehow update vim.v.this_session on a post-delete callback to reach my desired behavior? May this break anything or is it safe to do?

@rmagatti
Copy link
Owner

So, is this an intended behavior?

Not necessarily but ultimately the current session is still the one that was previously loaded according to vim, even after a SessionDelete command. For another session to show up in v.this_session one would need to load another session. The value of v.this_session also doesn't seem to be modifiable so I don't think there's much auto-session can do in this case with the current implementation.

Another way to go would be to not use this_session at all in that function and rely on something else to track which session is currently loaded, this would work but it would also require a new implementation of the current_session_name function. Happy to review a PR for this, otherwise I'll eventually get to it myself :)

@rosingrind
Copy link
Author

Much thanks for the detailed info on this topic, I think the issue may either be closed or edited as a feature request as you wish!

rely on something else to track which session is currently loaded

Implementation of this feature request probably don't really worth it and may introduce unnecessary complications, but I'm really not you to make conclusions :) In my opinion, for a proper solution, I should forward this to main vim/nvim repos. Thank you again!

@rmagatti rmagatti changed the title [BUG] current_session_name is not updated after session deletion [Feature] Track current session without relying on vim.v.this_session in current_session_name Aug 15, 2023
@rmagatti rmagatti added this to the v2.1.0 milestone Nov 21, 2023
@cameronr
Copy link
Collaborator

It looks like vim.v.this_session is now modifiable as this returns test for me:

:lua vim.v.this_session = 'test'; print(vim.v.this_session)

So i think it makes sense to clear it when if the current session is deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants