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
Eglot refuses to connect to an LSP server after deleting a folder from the projects root #1198
Comments
(Commit emacs-mirror/emacs@b6a7b42 removes the intelephense support, I wonder why.) You haven't attached the communication logs to your report. Without the logs, I'm just guessing, but they might show that Eglot sends the deleted directory the second time as well, which in turn, might be the result of the caching mechanisms of project.el. |
Hi @nemethf, thanks for responding. I'm sure its not an issue with Intelephense as it works just fine in VSCode and I did also try PHPActor, and it has the exact same problem. So it seems we have the same issue in two different language servers, that both work in fine other tools. Where can I find the communication logs?
Let me look into this, thanks! |
This page has that info. I suggest you visit it and study it briefly to make sure you give us everything mentioned there, including, for example, how you started Emacs. https://joaotavora.github.io/eglot/#Troubleshooting-Eglot When you say that visiting a file makes Eglot connect, I find that surprising, because a stock Eglot doesn't do that. So you must have some user config somewhere. |
In fact, i think you found the events log already, but you called it the "error message". An error in Elisp would be something different, you normally see it and hear it. |
@joaotavora I apologize, I do have hooks configured through Let me take a look at the link, thanks! |
@joaotavora Ok, I updated the issue statement with more information. Please take a look at the backtrace, it reports Directory does not exist for the folder I deleted in the example. It seems to be related to |
If you can reproduce it with a minimal configuration, as you said, then please I urge you provide that configuration, ideally that non-configuration. Else this is just going to take longer to analyze -- if if one ever picks it up. There's a inverse relation between the size of your config and the time it takes to solve a problem. But fortunately, in the error backtrace you provided I'm starting to see glimpses of the cause for this. It has to do with the server asking Emacs/Eglot to watch files that don't exist anymore. |
I still don't understand clearly what leads to this. There are instructions in "Reproducing the issue" and more instructions in "Backtrace". But when exactly does the error happen? I need to trace the steps you take exactly in my mind or in my reproduction of your experiment. Please write the "steps taken:" like so:
|
Ok, I updated the issue statement again. This video demonstration might also be helpful. Let me know if things are more clear now. |
I'm still missing the full events buffer. It can't possible be just
It also seems like a server bug to me. The server is asking to watch a directory that doesn't exist, and Emacs complains. But this shouldn't kill the connection. Maybe the server doesn't like the reply, but it shouldn't bail just because of that. At least this is I can read in the minuscule portion of the Eglot events buffer that you posted. Can you post the full log for the second time you open Emacs? That's steps 8-10 in your recipe. Also please do consider not using
|
@joaotavora Noted, I updated the events buffer portion in the issue statement with the full log. And I also removed all
I see, but why does PHPactor, a different PHP LSP server have the exact same issue? |
Maybe it uses the same logic? maybe one was inspired by the other, or maybe it uses the same code/library? But after seeing the event log, I don't think the server is at fault here. It just asks to watch a "glob" and that is somewhat innocent. I think what happens is that the files that Emacs thinks are included in that glob isn't coming from the file system itself, but rather from project.el's idea of what the project files are. So.... @nemethf was on to something from the beginning :-D |
I had problems with project.el in the past, but my guess this time wasn't perfect as the recipe restarts Emacs. At any rate, if I read the source correctly, project.el in I'm no git expert, so I cannot suggest a substitute command, but |
Maybe we can call @dgutov, maintainer of If so, then a fix to Eglot is in order, and the matter seems easy to solve. Else, that fix can go in temporarily to At any rate I think a server shouldn't do hara-kiri over an error report from the client, but that's another matter... |
I've now fixed this in Emacs 29's Eglot, meaning it will make its way into GNU ELPA soon. In the meantime, @VernonGrant, you may try this patch: commit 86cf9fd932c654cc502bedf634458a918ee5e9cb
Author: João Távora <joaotavora@gmail.com>
Date: Sun Apr 2 23:01:29 2023 +0100
Eglot: don't watch directories that don't exist
project-files isn't guaranteed to return existing files, so better
check if they exist because placing a watcher on them.
Originally reported at:
https://github.com/joaotavora/eglot/issues/1198
* lisp/progmodes/eglot.el (eglot-register-capability
workspace/didChangeWatchedFiles): Check if directories exist.
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 8f64f849d72..4a9209ab9b4 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -3433,8 +3433,9 @@ eglot-register-capability
(unwind-protect
(progn
(dolist (dir dirs-to-watch)
- (push (file-notify-add-watch dir '(change) #'handle-event)
- (gethash id (eglot--file-watches server))))
+ (when (file-readable-p dir)
+ (push (file-notify-add-watch dir '(change) #'handle-event)
+ (gethash id (eglot--file-watches server)))))
(setq
success
`(:message ,(format "OK, watching %s directories in %s watchers" |
Thanks for the report! I'm closing this, but let me know if this doesn't fix it, in which case I'll reopen. |
In theory, it shouldn't. In practice, deletion detection might be pretty costly. E.g., in a larger project over here, the difference between This is definitely something to consider, but let's maybe see if most problems with this behavior can be solved by easier methods, and whether this comes up frequently enough. IIUC, this is a problem only when the file has been Let's keep this discussion open somewhere: maybe file it with |
project-files isn't guaranteed to return existing files, so better check if they exist because placing a watcher on them. Originally reported at: joaotavora/eglot#1198 * lisp/progmodes/eglot.el (eglot-register-capability workspace/didChangeWatchedFiles): Check if directories exist.
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=62633 is the Emacs bug report. |
@joaotavora The patch is working just fine. Thanks for all the effort 🙏🏻 |
For me, executing |
This problem is fixed/worked around in Eglot 1.14. you can add more information about the project.el problem by sending email to the bug tracker, https://debbugs.gnu.org/cgi/bugreport.cgi?bug=62633 |
I've been struggling with a strange bug the past two days. I think it's related to
Git
in some way. Let me briefly explain the issue:I would open up a PHP project and navigate to a source file in the project root. Eglot will successfully connect to the LSP server, in my case Intelephense (the same issue exists using
phpactor
). Everything works as expected, but once I delete any directory inside of the projects root folder. All future Eglot connections, meaning closing and reopening Emacs, or callingeglot-shutdown-all
and reconnecting, will just completely blow up and fail. No matter what I tried, Eglot refused to reconnect to the LSP server that was working before.Now here's the stange thing, once I commit the changes into version control or just revert back the deleted folder, Eglot reconnects and everything works again. So I'm thinking this might be related to a misuse of
git ls-files
or something.What I tried
Steps taken to reproducing this issue
Assuming you already have Intelephense installed (
npm i -g intelephense
) and you use this configuration:You can do the following:
git clone https://github.com/mattbanks/WordPress-Starter-Theme.git
cd ./WordPress-Starter-Theme && emacs ./
C-x C-f
and openfunctions.php
M-x eglot
and press enter and wait for Eglot to successfully connect to the LSP.rm -R ./lib
(in the same terminal window)emacs ./
C-x C-f
and openfunctions.php
M-x eglot
and press enter and now Eglot's connection to the LSP will now fail.Eglot events buffer output
Backtrace
I ran
toggle-debug-on-error
in Emacs. Open the sample repository and deleted the lib folder. Eglot failed to connect, resulting in:Emacs details
Installed packages
My system details:
@joaotavora Let me know if there's anything I can help with, I have some time available this week and know a little bit of Emacs lisp 🙏🏻
The text was updated successfully, but these errors were encountered: