-
Notifications
You must be signed in to change notification settings - Fork 25
feat!: get_current() returns custom session save directory if available
#31
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
Conversation
|
Not sure why the generate script for docs formatted the return types like this:
|
get_current() returns custom session save directory if available
stevearc
left a comment
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.
I'll admit I don't think I fully understand your problem or how this solves it, but I'm fine with an API change that supports returning more data about the current session.
I think I would prefer this to go into a new method, something like get_current_session_info that can return an object with the name & dir of the session. That makes it much easier to extend in the future if we ever add more metadata about sessions.
cfc4e52 to
fbe1885
Compare
lua/resession/types.lua
Outdated
| ---@class resession.SessionInfo | ||
| ---@field name nil|string Name of the current session | ||
| ---@field directory nil|string Name of the directory that the current session is saved in |
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.
name should be non-nilable, and I believe directory should be as well
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.
I set the directory in session_configs to the default value if it wasn't provided.
lua/resession/init.lua
Outdated
| local session_info = {} | ||
| local session = M.get_current() | ||
| if session_info[session] ~= nil then | ||
| session_info.dir = session_info[session].dir | ||
| end | ||
| return session_info | ||
| 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 will never work because the local session_info will override the global one. if session_info[session] will always be nil. Did you test this at all?
Also, you aren't setting the session name on the return value.
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.
Sorry, I don't know what I was thinking at the time. It should be fixed now.
|
Looks good, thanks! |
Currently, there is no easy way (afaik) to retrieve session data for sessions not stored in the default save directory from within the session itself. It would be nice if the API exposed a function to do exactly that. One fairly clean way of doing this might be to add this functionality to the existing
get_current(), by allowing it to have a second optional return string representing the save directory. This way, data for the current session can be retrieved (no matter the save directory) like this:If you're wondering what my use case is, I would like to have my Grapple tags specific to a session, and one way to do this by having a custom resolver that creates a scope based on the cwd of the current session. (Since
projects.nvimautochanges the directory, it's necessary to have the scope resolved to global cwd stored byresession.nvimas opposed to the vim's cwd so that the tags don't get reset). This allows Grapple's builtin resession extension to function seamlessly in this kind of workflow.Example Grapple setup