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

Option to autoshutdown after killing last buffer #309

Merged
merged 3 commits into from
Oct 5, 2019

Conversation

ilohmar
Copy link
Collaborator

@ilohmar ilohmar commented Oct 2, 2019

This got messy, sorry.. rewriting a branch prevents reopening the PR, so here's a new one.

The old discussion is at #305.

ilohmar pushed a commit to ilohmar/eglot that referenced this pull request Oct 2, 2019
This should close issue joaotavora#217, also cf. joaotavora#270.

* eglot.el: New defcustom `eglot-autoshutdown' (default t).
(eglot--managed-mode): Signal didClose before possibly triggering
autoshutdown.
(eglot--managed-mode-onoff): Shutdown if so configured and no managed
buffers left.
@ilohmar ilohmar changed the title Option to autoshutdown after killing last buffer (#308) Option to autoshutdown after killing last buffer (#309) Oct 2, 2019
@ilohmar ilohmar changed the title Option to autoshutdown after killing last buffer (#309) Option to autoshutdown after killing last buffer Oct 2, 2019
@joaotavora
Copy link
Owner

This got messy, sorry.. rewriting a branch prevents reopening the PR, so here's a new one.

Didn't know about that. But I would advise against closing your own PR, even if you think it's somehow "wrong". Just let it be and you can always rewrite the commtis of the branch. For me the PR is the idea. The implementation is a separate thing.

@ilohmar
Copy link
Collaborator Author

ilohmar commented Oct 2, 2019

Yeah, good advice, will heed that in the future.

@joaotavora
Copy link
Owner

In all these years, it's the first time I see an actual use for the "depth" arg to add-hook.

The PR looks reasonably clean. You've obviously investigated enough, and this is one of the trickiest, if not the trickiest, part of Eglot. Two things:

  • first, a question: is it so, that currently, before your PR, we first tear down eglot-managed-mode and only then send the didClose notification for the just-killed buffer? If so, am I surprised. The natural order would be reverse, as you seem to propose in the PR. But if it isn't, I don't understand how didCloses' eglot--current-server call can succeed in these conditions. Can you explain?

  • once we figure out the natural order, I think we can change switch the order of the add-hook statements since we control both locally. They're always done in tandem, there's no way to do one and not the other.

  • this will need tests. and the CI system has been broken for a while and I haven't had the courage to look at it. :-) But I will :-)

@ilohmar
Copy link
Collaborator Author

ilohmar commented Oct 2, 2019

In all these years, it's the first time I see an actual use for the "depth" arg to add-hook.

Same here :) Relating that to your second point, I chose the depth argument on purpose, to make the order explicit from the call itself. Otherwise one has to think "backwards" (as in "this is added later, so it is prepended to the hook, so it runs first"). If you think re-ordering is clearer, go ahead, of course.

As for your first item: Yes, that is my understanding. AFAICS, the --onoff call only clears the cache, but the server stays in the hash eglot--servers-by-project, that's why (eglot--current-server) still returns it (and until this PR, it was still running, so everything worked).

This is a great example of the intricacies that I mentioned in the old PR: it's a bit tough to follow the logic, b/c the cache and the hash lose sync unnecessarily. As I said there, stuff for another PR.

Regarding tests: if you spend time on the testing setup, a mock language server (in elisp, preferably) would be great. This way, we could test eglot against the spec (or explicit deviations), in contrast to testing it against implementations beyond eglot's control. Unfortunately, I cannot commit time to look into that soon myself. My lack of familiarity with testing in Elisp would make that much more time-consuming than the kind of PR I am doing now.

Anyway, eglot is great and I am looking forward to more hacking on it.

@joaotavora
Copy link
Owner

Same here :) Relating that to your second point, I chose the depth argument on purpose, to make the order explicit from the call itself. Otherwise one has to think "backwards" (as in "this is added later, so it is prepended to the hook, so it runs first"). If you think re-ordering is clearer, go ahead, of course.

You have a point, but we'll see. The depth argument has its subtleties too, and nobody knows it. A comment stating "this is the order because blabla" would also work, imo.

As for your first item: Yes, that is my understanding. AFAICS, the --onoff call only clears the cache, but the server stays in the hash eglot--servers-by-project, that's why (eglot--current-server) still returns it (and until this PR, it was still running, so everything worked).

Oh I missed that last part, which makes sense. So I think this PR could be split into two commits bugfix/optimization + the new feature itself.

This is a great example of the intricacies that I mentioned in the old PR: it's a bit tough to follow the logic, b/c the cache and the hash lose sync unnecessarily. As I said there, stuff for another PR.

The onoff is a bit hacky, indeed. It is mostly there to reuse code but it could be broken off. Don't see an enormous need for it, though.

Regarding tests: if you spend time on the testing setup, a mock language server (in elisp, preferably) would be great. This way, we could test eglot against the spec (or explicit deviations), in contrast to testing it against implementations beyond eglot's control. Unfortunately, I cannot commit time to look into that soon myself. My lack of familiarity with testing in Elisp would make that much more time-consuming than the kind of PR I am doing now.

This is a good idea, but still so many things happen off-spec that I don't think it would be enough to abandon server-specific tests.

Nevertheless, you'll find in eglot-tests.el there are macros that help test the shutdown and project mechanics. These should, in principle, not be the ones completley broken, though they probably rely on either the rls or pyls servers that I had installed back when I was doing more intensive eglot dev.

Anyway, eglot is great and I am looking forward to more hacking on it.

This is much appreciated!

@ilohmar
Copy link
Collaborator Author

ilohmar commented Oct 2, 2019

As for your first item: Yes, that is my understanding. AFAICS, the --onoff call only clears the cache, but the server stays in the hash eglot--servers-by-project, that's why (eglot--current-server) still returns it (and until this PR, it was still running, so everything worked).

Oh I missed that last part, which makes sense. So I think this PR could be split into two commits bugfix/optimization + the new feature itself.

Sure. What would you consider the bugfix, the re-ordering in kill-buffer-hook? I would rather not touch the cache stuff itself.

This is a great example of the intricacies that I mentioned in the old PR: it's a bit tough to follow the logic, b/c the cache and the hash lose sync unnecessarily. As I said there, stuff for another PR.

The onoff is a bit hacky, indeed. It is mostly there to reuse code but it could be broken off. Don't see an enormous need for it, though.

My goal would be to get rid of it entirely (without code duplication). If I can do that (I think I know how), there'll be a PR for that soon..

@joaotavora
Copy link
Owner

What would you consider the bugfix, the re-ordering in kill-buffer-hook?

yes.

@ilohmar
Copy link
Collaborator Author

ilohmar commented Oct 2, 2019

Ok, which solution do you prefer: depth or re-ordering (with comment)? If it's the same to you, I would keep it as posted.

@ilohmar
Copy link
Collaborator Author

ilohmar commented Oct 2, 2019

Come to think of it, re-ordering is better, else the didClose will usually go to the start of the hook and might be separated from onoff call..

ilohmar pushed a commit to ilohmar/eglot that referenced this pull request Oct 2, 2019
This should close issue joaotavora#217, also cf. joaotavora#270.

* eglot.el: New defcustom `eglot-autoshutdown' (default t).
(eglot--managed-mode-onoff): Shutdown if so configured and no managed
buffers left.
@joaotavora
Copy link
Owner

I prefer reorderning, but if you feel strongly about the -1 we can keep it, of course.

Come to think of it, re-ordering is better, else the didClose will usually go to the start of the hook and might be separated from onoff call..

The thing is there is some subtletly to the depth argument that I don't yet understand. It's not there only to express ordering, but to express layering. I would say, if we can get by without using it, better, unless we perfectly understand it.

joaotavora added a commit to ilohmar/eglot that referenced this pull request Oct 5, 2019
…otavora#309)

This should close issue joaotavora#217, also cf. joaotavora#270.

* eglot.el (eglot-autoshutdown): New defcustom.
(eglot--managed-mode-onoff): Shutdown if so configured and
no managed buffers left.

Co-authored-by: João Távora <[email protected]>
ilohmar and others added 3 commits October 5, 2019 09:47
It used to be the reverse way around, which doesn't make sense.

* eglot.el (eglot-managed-mode): Fix order in `kill-buffer-hook'

Co-authored-by: João Távora <[email protected]>
…otavora#309)

This should close issue joaotavora#217, also cf. joaotavora#270.

* eglot.el (eglot-autoshutdown): New defcustom.
(eglot--managed-mode-onoff): Shutdown if so configured and
no managed buffers left.

Co-authored-by: João Távora <[email protected]>
* eglot-tests.el (auto-shutdown): New test.
@joaotavora joaotavora merged commit c3bae0a into joaotavora:master Oct 5, 2019
joaotavora added a commit that referenced this pull request Oct 5, 2019
This should close issue #217, also cf. #270.

* eglot.el (eglot-autoshutdown): New defcustom.
(eglot--managed-mode-onoff): Shutdown if so configured and
no managed buffers left.

Co-authored-by: João Távora <[email protected]>
@joaotavora
Copy link
Owner

Merged after some housekeeping. Crucially, kept the default. If you can gather the votes again from the other issue and come um with a tally, then we can make another commit to set the default value.

@ilohmar
Copy link
Collaborator Author

ilohmar commented Oct 5, 2019 via email

bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
This should close issue #217, also cf. #270.

* eglot.el (eglot-autoshutdown): New defcustom.
(eglot--managed-mode-onoff): Shutdown if so configured and
no managed buffers left.

Co-authored-by: João Távora <[email protected]>

(#309: joaotavora/eglot#309
#217: joaotavora/eglot#217
#270: joaotavora/eglot#270
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this pull request Oct 12, 2022
This should close issue joaotavora/eglot#217, also cf. joaotavora/eglot#270.

* eglot.el (eglot-autoshutdown): New defcustom.
(eglot--managed-mode-onoff): Shutdown if so configured and
no managed buffers left.

Co-authored-by: João Távora <[email protected]>
GitHub-reference: joaotavora/eglot#309
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