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

Feature: last session filesystem time #61

Conversation

josh-nz
Copy link
Contributor

@josh-nz josh-nz commented Jun 11, 2024

Here is an attempt at implementing the last session by using the filesystem last write time, instead of a symlink.

The symlink adds a bunch of complication about keeping it in sync, and I'm pretty syre there is a bug around deleting a session from telescope not removing the symlink. I'm also unsure how well supported these are on Windows.

The second commit in the PR serves to remove the symlink for exisiting users. We may wish to incorporate this, otherwise a symlink will persist unless the users manually remove it. I'm unsure how long this feature should remain, the alternative is to mark this as a possible breaking change and have the users clean up the symlink themselves. I'll leave this decision up to @jedrzejboczar as to how you want to manage this plugin.

There might very well be a much better way to implement this, but I found that the query module did most of what was needed already, so have just leveraged that. Please disregard any or all of this PR if there are better ways to achieve this feature. Treat this as a proof of concept.

Do note that when executing :PossessionLoad I get the following error, which might be an issue with my specific Neovim config, or it could be something I've done incorrectly in the PR.

Screen Shot 2024-06-11 at 21 33 47

It's also worth noting the comment in commands.lua from line 98. Because autosave might be enabled, using mtime can trigger a flip flop effect if you run :PossessionLoad multiple times; it will toggle the last two sessions. We may or may not want this. The comment suggests ways to avoid this, but this toggling effect, or not, is open for discussion.

@jedrzejboczar jedrzejboczar force-pushed the feature/last-session-filesystem-time branch from 6231b42 to a72979f Compare June 11, 2024 20:21
@jedrzejboczar
Copy link
Owner

Thanks for implementing this! Looks good to me, really nice that you used the query module to avoid code repetition.

I added file "touching" after load to update last session as you suggested and removed your comment from commands.lua. It uses libuv so it should be portable between different systems (hopefully). For this to work I had to fix implementation of autosave not to autosave if there is a current session loaded (this is the behaviour described in the documentation but it the implementation was incorrect).

I think it's good idea to clean up the unused symlink, I just changed the implementation to avoid using plenary.path to be more lazy-loading-friendly.

Regarding the error that you get - I don't seem to experience this, so it might be a problem with your configuration or something that has been fixed/introduced in Neovim nightly (depending on which Neovim versions we use, mine is NVIM v0.11.0-dev-207+g20f22f75ee).

@jedrzejboczar jedrzejboczar merged commit 09ce7c6 into jedrzejboczar:master Jun 11, 2024
0 of 3 checks passed
@josh-nz
Copy link
Contributor Author

josh-nz commented Jun 12, 2024

My first implementation was a loop over the files reading the mtime via vim.uv.fs_stat. While I was working on the next feature, loading the latest session for the cwd, I found the query module and said to myself, oh, everything is pretty much already implemented here :)

I'll keep an eye on that error I'm having. I'm using 0.10.0 official release.

Thanks for your help with this.

@josh-nz josh-nz deleted the feature/last-session-filesystem-time branch June 12, 2024 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants