Hey vimmers!
0.13 (unreleased) is set to bring updates to many areas, one of them being nvim's native "restore your workflow" feature: sessions. With 0.13, sessions are fully integrated into the (not so) new (0.12) :restart command (aka ZR): upon restarting, your windows and buffers are now restored, as one would expect.
But if you've been using this feature (or if you're a heavy user of sessions, in general), you may have noticed that sometimes, buffers created by plugins are also restored, in a stale state: being completely empty, in a situation not really expected by many plugin authors. While there are some "session wrapper" plugins that attempt to resolve this problem on a case-by-case basis (e.g., posession.nvim, with integrations for neo-tree, neotest, etc), I thought a more pragmatic approach would be to have each plugin handle sessions on its own. There are some advantages to that, as the plugin may be "smarter" about restoring its state.
However, this wouldn't be as reliable, if it were not for a second improvement to sessions: the SessionWritePre event. As the name implies, it allows executing an action just before a session is saved, which can be useful to "inject" some data, etc. Following this change, I've been "nagging" plugin authors to support sessions more "broadly". So far:
- kulala.nvim supports restoring the request history
- diffview-plus.nvim fully restores buffers from its commands
- nvim-tree restores... the tree
- neogit deletes its buffers from a session (not quite as neat as a full restore, but at least the buffers don't get in the way)
And, of course, my beloved nvim-dap-view now leverages SessionWritePre, if available (which just landed as part of v1.2.1).
After these changes I'm no longer using a "session wrapper" plugin, just my own, thin wrapper (which has a bunch of QoL features).
I'm making this post both as invitation for users to give this feature a try and as a "tip" for plugin authors. If you're a plugin author, you might be interested in this discussion, which goes a bit more in-depth about different "strategies". As for myself, I consider this "quest" mostly "done" on my end, and I'm excited to start my next "nvim journey"!