-
Notifications
You must be signed in to change notification settings - Fork 20
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: load last cwd #63
Feature: load last cwd #63
Conversation
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.
Thanks for this work and detailed message.
I added some comments regarding the implementation.
Regarding 1.
I haven't debugged it, but it seems like there might be a lot of edge cases. Your suggestion to pass skip_autosave
down the call stack seems like a good idea to avoid some complex logic.
Regarding 2.
I would probably need to think about it some more time but my initial thoughts:
- "what should save cwd do" - I would say that everything related to cwd settings/commands should save CWD sessions (name after CWD)
autosave.current
has higher priority, so if we loaded CWD session and it happens to be the named sessionfoo
then we would savefoo
becauseautosave.current
matches; if user hasautosave.current=false
then it would save as CWD sessionPossessionLoadCwd
could probably distinguish if it uses just "the CWD session" or "last sessions that has a matching CWD" using bang (!
)- there should probably be config option to decide if autoload should only consider "the CWD session" or all sessions that match CWD, but I would have to think more about naming it
- we might also consider using
vim.ui.select
in the commands, so that a LoadCwd command would prompt user to select which session to load, but this needs some consideration where to put it and how to allow users to disable this behaviour (some may prefer just use the most recent one), so maybe:LoadCwd
- uses vim.ui.selectLoadCwd!
- always takes the most recent oneLoadAutoCwd
or something like that would be for "the CWD session"
- when thinking about it maybe it makes no sense to have the "only the CWD session" case, as you say, users would probably think that LoadCwd means "auto-generated CWD sessions and named sessions with matching CWD", and if we support vim.ui.select then they can choose anyway
Ok, I haven't addressed everything, but now it's late for me too :P
I dumped what I could and I'll try to get back to this review later.
I've had a few thoughts overnight. The main goal is try to keep it simple to understand. I'm ok with some things being a little more involved provided we include clear and understandable documentation so users can learn.
I'm not sure I like this idea. It is putting different meaning, and my basic Neovim understanding is that bang is used to bypass any prompts, which is how I think the other Possession commands use it. This new usage then becomes a one-off and goes against user intuition. I also don't have any thoughts on using I think the above would make things pretty clear and easy to understand, and is mostly how it is currently working. Edit: Noticing that there is autocomplete for |
Ok, yeah, the Github review system did not work as I was expecting. Clearly I don't know how to use this correctly ;) Hopefully you can figure it out. I was mostly just trying to add a comment to a specific commit. |
From my edit comment above:
Thinking some more, it might be that users don't have the So
Or is this overloading |
Regarding #63 (comment):
Agreed, let's leave bang for forcing things etc.
Sure, let's leave it for now. Regarding #63 (comment): I'd leave
|
Ok, so now, to summarize while looking at the latest version of the code, my suggestions would be (if I didn't forget about something):
I commented on some things in different conversations but I resolved all the non-action-point conversations to leave only what is relevant now. |
You're summary sounds fine and reasonable. I do have a question about Otherwise there is no difference between this and |
5168ab6
to
f6203b2
Compare
No, I was thinking that the argument would be a directory to use as cwd instead od the actual cwd. So:
|
So basically this would be the same as you did with |
Yes, that makes a lot more sense than what I was thinking. It should only load the I think keeping the Edit; I just reread your comment and you say
So Now I'm a bit unsure as to what the "correct" implementation should be. I doubt I'll use these commands, so I'll let you make the final choice on how loadCwd should behave. |
6d6aa1b
to
9b12c22
Compare
Thanks for all your work on this and other issues in this plugin. Let's wait some time, I'll also use this version and when you think it's ready then we can merge it. |
There is a table that is returned from I don't know what this returned table does. |
This was added as a convenience API shortcuts to allow e.g. for |
d5949f3
to
50c875f
Compare
Your explanation makes a lot of sense and I think it would be better to go your way and have In the future we could probably have a separate command As for your Neovim usage with one instance per cwd - it's probably what most people use, my workflow is probably more rare - I use tab-local cwd's and exrc.nvim to load/unload specific settings when I change directories. |
Ok, I'll make these changes tomorrow. I was also looking at what these commands currently do:
So this change will help keep this behaviour. The only remaining question is what the no argument (default) should be for |
@@ -1,4 +1,12 @@ | |||
local group = vim.api.nvim_create_augroup('Possession', {}) | |||
local nvim_received_stdin = false |
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 don't think we need to use a vim global, a module variable seems to work for all we need here.
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.
Right, that's nice
return get_last(get_sessions_for_dir(vim.fn.getcwd())) | ||
end | ||
|
||
name = name_or(name, last) |
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.
We're not validating that the user provided name matches a cwd session. If it matches any session it will load. I think this is fine.
The autocomplete only shows cwd sessions.
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.
Seems fine
I think this takes care of all the outstanding issues. So aside from any bugs, I think work on this is complete. To summarise the major changes:
Closes #59 as this now supports my immediate session needs. |
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.
Looks good to me, merging!
return get_last(get_sessions_for_dir(vim.fn.getcwd())) | ||
end | ||
|
||
name = name_or(name, last) |
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.
Seems fine
@@ -1,4 +1,12 @@ | |||
local group = vim.api.nvim_create_augroup('Possession', {}) | |||
local nvim_received_stdin = false |
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.
Right, that's nice
@josh-nz Thanks for all your work on this! This took a lot of time, but I feel like your changes are well-thought and will be useful for many users. |
Thanks for all your help and guidance with this. |
This is a proof of concept that, when
autoload.cwd = true
, instead of just loading the session named after thecwd
, will load the most recent session file for that cwd.This should work regardless of whether
autosave.cwd = true
is set. For example, a user could save manual sessions. Or it could be a combination of both. The idea behind this is that a user would want to resume whatever was the most recent session for that cwd. It could be extended to the more general idea of "load the last session regardless of cwd" if desired.I've tried to keep each commit to a particular feature or slice of work.
There are a few issues with it as it stands.
Let's discuss 1.
With
autosave.cwd = true
and this implementation ofautoload.cwd = true
, do the following.:PossessionSave foo
to save a new session.This triggers
session.lua
autosave
to run. The issue isautosave_skip
returns true when it should return false, see #60. One of the buffers has a buffertype of '' (the default[no name]
buffer I think), so hence the table is truthy andnext(table)
is true. This means theautosave.cwd
clause inautosave_info
returns true (because these expressions are negated), and since the name of this is thecwd
which doesn't matchfoo
, autosave triggers. I don't think it's appropriate to try and change theautosave.cwd
clause to use the latest cwd session name, see discussion point 2 below. I haven't yet found a way to reliably haveautosave_skip
return false when starting Neovim. I still don't quite understand the logic inautosave_skip
, in particular theor not next(unscratched_buffers)
clause.One option to solve this is to pass a
skip_autosave
flag down the call stack. It might be cleaner than trying to decide if autosave should be skipped by examining the state of buffers inautosave_skip
.Let's discuss 2.
I think this one needs a bit more time and thought. Initially there was a
save cwd
andload cwd
commands, andautosave cwd
andautoload cwd
config options. Now there is the concept of the 'last cwd' which has been thrust upon theautoload.cwd
config option. So the semantics of what acwd session
means is starting to blur. For example, if autoloading the cwd loads a session namedfoo
, what shouldsave cwd
command do?foo
is the current session, and happens to be a cwd session, but it's also not the "named" cwd session. Similarly, should:PossessionLoadCwd
load the most recent session, or only the "named" cwd session?I've left the saving the loading commands alone; I feel they should save and load the "named" cwd session. It's worth noting that otherwise to load the cwd named session via
:PossessionLoad
is very difficult due to the percent encoding name.I'm not sure there is merit in having another config to "load the last cwd" session, when the implemented behaviour is, I think, what users would naturally expect. Similarly, I don't think changing the name of the
autosave_info
cwd
clause to be the last session name is correct, it should remain as the cwd.It's late here, and I need some sleep. Apologies for a dump of information. I think there is something useful here, especially if you want a default session auto created (based on the cwd name) but then switch to a manually named session for example for different git branches. But I do think it's important to take some time and consider what these different features and options mean. It also has impacts on how the code is designed.