From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#70724: 29.2.50; eglot-reconnect errors when the project is deleted Date: Sun, 19 May 2024 18:08:15 +0300 Message-ID: References: <8634qffrly.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15801"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: app-emacs-dev@janestreet.com, 70724@debbugs.gnu.org To: Eli Zaretskii , sbaugh@janestreet.com, =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 19 17:09:25 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 1s8iA8-0003mc-0h for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 May 2024 17:09:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s8i9k-0001Sp-2x; Sun, 19 May 2024 11:09:00 -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 1s8i9i-0001SY-Ch for bug-gnu-emacs@gnu.org; Sun, 19 May 2024 11:08:58 -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 1s8i9i-0008GI-4I for bug-gnu-emacs@gnu.org; Sun, 19 May 2024 11:08:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s8i9l-0002Qc-PP for bug-gnu-emacs@gnu.org; Sun, 19 May 2024 11:09:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 May 2024 15:09: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.17161313099307 (code B ref 70724); Sun, 19 May 2024 15:09:01 +0000 Original-Received: (at 70724) by debbugs.gnu.org; 19 May 2024 15:08:29 +0000 Original-Received: from localhost ([127.0.0.1]:36621 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8i9F-0002Q3-9p for submit@debbugs.gnu.org; Sun, 19 May 2024 11:08:29 -0400 Original-Received: from fhigh3-smtp.messagingengine.com ([103.168.172.154]:40503) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8i9D-0002Pv-W5 for 70724@debbugs.gnu.org; Sun, 19 May 2024 11:08:28 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BC0B71140065; Sun, 19 May 2024 11:08:18 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 19 May 2024 11:08:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1716131298; x=1716217698; bh=VkOS/OjQ0hb/JiR0jEEx1sD605SfVz5GWpVnjWpVS2o=; b= pw+/qw/xxJ8qJfc+SY+AzX0LfYq2SxKgbe1ThSNDslGZS0UO+jXgGpA35ho2slUF ZlugStHoK4cDAVZIRSOb9Jj7oDyatXY33G6BzIMhJlbf76k/GPpHx2vX1JLFPWXI +mr+kJKdEU+vWSlCG/obaAWnzKpy+E1nkyKZi97qjwZrUQIIxobx5cT+VcXoUCvx VSwVpBQRPI+datF1xdGmZUsNE3dMycfJnKxFMc1k8tgHR6p9bQwKiQ0AX7eIRiBo icse+9OQOHYsWTqvLcdYkefzPZZ6C3gDEFs6eKcm8svF27s/V14BESqalQKqs1s8 83VK7cE1wATVDGEhvRYJNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716131298; x= 1716217698; bh=VkOS/OjQ0hb/JiR0jEEx1sD605SfVz5GWpVnjWpVS2o=; b=N i9nitn93dn/pB0/dP7qoCY/mxmJhaHKIJ72mE2tsrKh24ENDwJ9D6s7OqzfqyFtA knFaY6hCZr5FqSKtppMtSYx+/19UAJWCpUilJ5ib1PH+amlNodX5+0JvmVqxX/Xr xjlkSlzXCpJDVFZtznxyRY10kcfBuAwF4Ov5pQugQYbOpqt09/gxFrdqtsnChmQW 9VuEamDC0Df4fPB49O98VxHUvkVd/NL4dasbBmlJ9pOULurX3MfQ3tihREF+nZIg wL8sOQh7VD8PY5RPMyvVeyD6OwjKZrVDVrto36ZS325HrKJugqj+FXFiYsCEVeVH /UK1JYvK9TR5/hq0rDcOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehkedgkedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepteduleejgeehtefgheegjeekueehvdevieekueeftddvtdevfefhvdevgedu jeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 19 May 2024 11:08:16 -0400 (EDT) Content-Language: en-US In-Reply-To: <8634qffrly.fsf@gnu.org> 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:285436 Archived-At: Seems like we could use Eglot's maintainer's input. On 18/05/2024 11:31, Eli Zaretskii wrote: > 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.