feat!: get_current() returns custom session save directory if available#31
feat!: get_current() returns custom session save directory if available#31stevearc merged 10 commits intostevearc:masterfrom
get_current() returns custom session save directory if available#31Conversation
|
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.
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.
name should be non-nilable, and I believe directory should be as well
There was a problem hiding this comment.
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.
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.
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