From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#70724: 29.2.50; eglot-reconnect errors when the project is deleted Date: Sat, 18 May 2024 11:31:53 +0300 Message-ID: <8634qffrly.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38054"; mail-complaints-to="usenet@ciao.gmane.io" Cc: app-emacs-dev@janestreet.com, 70724@debbugs.gnu.org To: sbaugh@janestreet.com, Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 18 10:33:20 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s8FVI-0009hU-4Y for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 18 May 2024 10:33:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s8FV0-0006Wz-9d; Sat, 18 May 2024 04:33:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8FUx-0006Wh-06 for bug-gnu-emacs@gnu.org; Sat, 18 May 2024 04:32:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s8FUw-0003Oj-Nt for bug-gnu-emacs@gnu.org; Sat, 18 May 2024 04:32:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s8FV0-0007Xh-07 for bug-gnu-emacs@gnu.org; Sat, 18 May 2024 04:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 May 2024 08:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70724 X-GNU-PR-Package: emacs Original-Received: via spool by 70724-submit@debbugs.gnu.org id=B70724.171602113328977 (code B ref 70724); Sat, 18 May 2024 08:33:01 +0000 Original-Received: (at 70724) by debbugs.gnu.org; 18 May 2024 08:32:13 +0000 Original-Received: from localhost ([127.0.0.1]:60291 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8FUC-0007XJ-FA for submit@debbugs.gnu.org; Sat, 18 May 2024 04:32:12 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34258) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8FUA-0007XD-Bk for 70724@debbugs.gnu.org; Sat, 18 May 2024 04:32:11 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8FTy-00037s-JW; Sat, 18 May 2024 04:31:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=MkdSCZlip2xfXqoDkn3O9hCxFEwgfk3vhhTacP5G0NU=; b=nMZMxrpqrwqp JC7v+GU6KyYwS0q5phCdqhfEkNu4uNSC9dJ7bIfQWuzc7bqO1ldoO2tX+LGXsj1YxG40VaAcT59Wg Ky8Lwm9GDwQpb9RXbve4Zk/F1jyt+U6iA+sSRIkU4+zx5LAaniFqTM2Xlkr1QcLwgHp4jDT/+hTff firuYoluOLkG0vZN3Wmy35cq4mDMNotcYOT9wJZzw3VrkxYlL6wIfx9njLW2PuvfGdtxj+11KVY1U DO+BdAy9PlEAf1B8HglhKU24ylGZDFHQiUnBvR+F7oxEbfM31BCWTPVuxS4tbcworp4J2TmDjpJxK fyqO6E/0xLRn3a1LgcleTw==; In-Reply-To: (message from Dmitry Gutov on Sat, 4 May 2024 04:09:48 +0300) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:285291 Archived-At: Ping! Can we make some progress here? > Cc: app-emacs-dev@janestreet.com > Date: Sat, 4 May 2024 04:09:48 +0300 > From: Dmitry Gutov > > Hi Spencer, > > On 02/05/2024 22:37, Spencer Baugh wrote: > > > > In some project /home/foo/proj, with pretty much any LSP server: > > > > 1. In /home/foo/proj, M-x eglot, starting some LSP server > > > > 2. Delete the directory /home/foo/proj > > > > 3. The LSP server will crash/exit > > > > 4. The process sentinel for the server will run, running > > eglot--on-shutdown which by default will call eglot-reconnect > > > > 5. eglot-reconnect extracts the saved project instance out of the > > server, which has a root directory which no longer exists, and calls > > eglot--connect with it > > > > 6. eglot--connect calls project-name on a nonexistent project instance, > > which may fail with an error depending on the project implementation > > (I have a custom project implementation, but I think this can happen > > with project-vc too) > > > > 7. This causes the process sentinel to error. > > > > I think the right fix is probably for eglot--on-shutdown (or maybe > > eglot-reconnect) to call (project-current nil (project-root pr)) to find > > the new project instance. If that returns nil, the project has > > disappeared, and eglot should just not try to reconnect. This also > > would make eglot behave better if the project layout changes (e.g. if > > there are nested projects). > > I think I like this solution (as long as the nil value returned by > project-current on this step is appropriately handled). > > Something like: > > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el > index 6896baf30ce..7b2461c3ce6 100644 > --- a/lisp/progmodes/eglot.el > +++ b/lisp/progmodes/eglot.el > @@ -1426,11 +1426,15 @@ eglot-reconnect > (interactive (list (eglot--current-server-or-lose) t)) > (when (jsonrpc-running-p server) > (ignore-errors (eglot-shutdown server interactive nil > 'preserve-buffers))) > - (eglot--connect (eglot--major-modes server) > - (eglot--project server) > - (eieio-object-class-name server) > - (eglot--saved-initargs server) > - (eglot--language-ids server)) > + (let* ((root (project-root (eglot--project server))) > + (project (project-current nil root))) > + (if (not project) > + (eglot--error "Project in `%s' is gone!" root) > + (eglot--connect (eglot--major-modes server) > + project > + (eieio-object-class-name server) > + (eglot--saved-initargs server) > + (eglot--language-ids server)))) > (eglot--message "Reconnected!")) > > (defvar eglot--managed-mode) ; forward decl > > > Though it also raises a question about the caching strategy for VC-Aware > project backend. At the moment is associates a project with a directory > more or less indefinitely, and this is a case to watch out for. > > > Alternatively, maybe eglot--on-shutdown shouldn't automatically > > reconnect in the first place? Maybe reconnection should happen > > automatically only when some specific buffer tries to interact with the > > LSP - then it can run project-current in the context of that specific > > buffer, and see there's no project, and fail. Plus, if the user kills > > all the buffers in the project (possibly with project-kill-buffers) > > before deleting it, this approach would entirely avoid the unnecessary > > eglot reconnection attempt. > > This also sounds good, though it'd probably require more changes > overall. Additionally, perhaps I'd change the association from (server > -> project) to (server -> project-root), relying on the project > backends' internal caches to fetch the project value whenever it's > needed. That might be the most reliable approach. Perhaps the slowest in > theory, but hopefully not noticeably so. > > > >