From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Felician Nemeth Newsgroups: gmane.emacs.bugs Subject: bug#62116: RFE: eglot: support window.showDocument LSP RPC Date: Sat, 06 May 2023 14:46:44 +0200 Message-ID: <87ttwpbpaj.fsf@betli.tmit.bme.hu> References: <87jzznxx8f.fsf@gmail.com> <83fsabwhpg.fsf@gnu.org> <87v8j7vy48.fsf@gmail.com> <83r0tuv62t.fsf@gnu.org> <874jp8gu8a.fsf@betli.tmit.bme.hu> <838re3jowg.fsf@gnu.org> <87ttwqsow9.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14300"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: 62116@debbugs.gnu.org, adonovan@google.com, sebastian.poeplau@mailbox.org To: =?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 Sat May 06 14:47:29 2023 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 1pvHJw-0003Uf-UT for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 May 2023 14:47:29 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvHJe-0002tl-JU; Sat, 06 May 2023 08:47:10 -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 1pvHJc-0002tY-RS for bug-gnu-emacs@gnu.org; Sat, 06 May 2023 08:47:08 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvHJW-0005iY-53 for bug-gnu-emacs@gnu.org; Sat, 06 May 2023 08:47:08 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pvHJW-00075B-1V for bug-gnu-emacs@gnu.org; Sat, 06 May 2023 08:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Felician Nemeth Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 May 2023 12:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62116 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 62116-submit@debbugs.gnu.org id=B62116.168337721627214 (code B ref 62116); Sat, 06 May 2023 12:47:01 +0000 Original-Received: (at 62116) by debbugs.gnu.org; 6 May 2023 12:46:56 +0000 Original-Received: from localhost ([127.0.0.1]:59626 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pvHJP-00074r-K5 for submit@debbugs.gnu.org; Sat, 06 May 2023 08:46:56 -0400 Original-Received: from mail-wr1-f49.google.com ([209.85.221.49]:54501) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pvHJM-00074e-OW for 62116@debbugs.gnu.org; Sat, 06 May 2023 08:46:54 -0400 Original-Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3062db220a3so1831598f8f.0 for <62116@debbugs.gnu.org>; Sat, 06 May 2023 05:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683377206; x=1685969206; h=mime-version:face:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=Cnx+ol+197s/2aFgMz82nKEWzvNC3AHUa9tcrqVRk1U=; b=U04SAZ2I50Ok+O8xaezEoG6sMHSsTRTMMNHsyN5edWCfamCEdJ02HCA+IsGvQ6hHEi OSxq5Mb5i+aliIg2Rl2xjwqZvAKHhBmKvRWyxvlO89r/EGhTkG+9djuhPYwrfxlydHUk TO6p345YgBzoU+QzoLQhb6v5A83v+Si9kTZhg6dodjIh19ZnOm40sXcwyD3ANxWzZEIU LNBjT8vl12HFD750EqJzT+Aqa/0TEfPzbzqsK3vGPRyWjb3veZShj9v721Rxmz3Bvh0h byFxIXniYzTWIp2ucsEk4p5yKw1P4AxPM45azIU+QPJIplngAFzaIhkWPMEkjrWzPEtq zSNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683377206; x=1685969206; h=mime-version:face:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Cnx+ol+197s/2aFgMz82nKEWzvNC3AHUa9tcrqVRk1U=; b=RhpkzGNjwPTxHEY/tEqsG/n/gVzVHZBB+x40EW+wpyxcT+dzuVUPcXW2YaIg939Q+z G0o7glxuHz1/wk0wgJ0gdpbBM9jG80/DOKkOOnce4rcNvmbisgutH5Ou++q/PR1epFwx pmuVVG4CGC+89jQKXV3UInZu/w0P6d85KY0k8XGhMMryOkOX8WBu05uo4CXhq6RC0HSd wB7hStrf2OZK11DxK8HHIKnFxtc8HFWaRbTNm+SjNlVX+luWq+xdy8wEPwXuJwlmR8Jn HgWh1hE2UBjjIdaYo6OfZ9qeo+AW3cwYU9AC3302qV6G7OvhXunjXgSAdPR9SuFxheaX xgHw== X-Gm-Message-State: AC+VfDzjHCkxTTCfjD29o2TupDxrl9aZHmRnc6WETmZebuoSvVoddEo+ P5bVZpvBljo+Bbhyrw4wV9q0bwzkAPrKYg== X-Google-Smtp-Source: ACHHUZ5Fzq1lB45PKwxwHr0sGerixpMyG+xPgX8NVJD0Yc8R7aocbRGW2nPnjwSl9J+Jx/42qTiKAg== X-Received: by 2002:adf:e6ca:0:b0:2fa:631a:9f38 with SMTP id y10-20020adfe6ca000000b002fa631a9f38mr3652737wrm.2.1683377206119; Sat, 06 May 2023 05:46:46 -0700 (PDT) Original-Received: from betli.gmail.com (catv-89-134-210-182.catv.fixed.vodafone.hu. [89.134.210.182]) by smtp.gmail.com with ESMTPSA id v12-20020a5d678c000000b00304a876c3c1sm5363596wru.5.2023.05.06.05.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 05:46:45 -0700 (PDT) In-Reply-To: <87ttwqsow9.fsf@gmail.com> ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Fri, 05 May 2023 17:51:02 +0100") Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEWOdXElERN7LDLZs6/l 0dDQq6TepMcqAAACW0lEQVQ4jWWSzY7bMAyEaSm6mypylxjkroTRvUW8d9lavf+r7NDOZotWQHzg lyGHP0Sn5ed9qKrLWWIWos9/QJWIeCSywPNTd/AE0LtwFj7A+3WT5PwfeBrQKcsBnkfwVcNySWQr 3i34XN6gRNgis/v4uwSKHCD9lPitB0Aq9BHfHX4cgsI7cJJfLdZg/4bbCzoRmkD9MsagQSBDedZi CgNxkVSJmSOStTBUBKkywEnEoZzbwWj+ACiVJkF6pOpak2PMCqkMYDpaw+gatLR8atMOrB3JGzmm 3rSQo+tkxU+UAbhQSgtslULhsXKk6+IyQ1QTzeQB0MzjlpkCEUCeUdviWrwBcxVqpZjP+v0MYPA0 aq2rvIEZe4GRM0v+9QIB03rsABVSk5y+Mz3LSzExtJLlCCO6dV1uzDQFTBad+gO0TqqL9XE8x4ek +orvYiMJgzC8e+r6TqaPaK6QyqVNvoHtsRrooQ6tTi4vgaSkd8wIikodB3B0iIk58avsDdYNajpS bSKJ+mQnipGszB6zW4lGgsOkKHE2RWVcBpwhaIv3BYIAu3WsnC7YYKLRchp6w8fRGZIWiZuFsVai 7gbcUcJEhiDZ3K1+uzZvBlfaEO8oH4MLu6/hrKVM7QpQcIXJFuC1XjfbfKRxNslk94l9cYcEihV2 HWyNDQAXaLsvnrSyp7HaQhrAn13V6/XW11nh0XINBOEAV+tHK4EvAGNGvEwc0eZw8Vyr56imYEsV sOW9jxm/yb9AH1ufqGMviIK7A0Tc/723oM3tJ4HTOu9gDr3ftbdkxfdjsUv5AqWKwyfCYo5WAAAA AElFTkSuQmCC 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:261189 Archived-At: --=-=-= Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: quoted-printable > Felici=E1n, can you show your full patch again, perhaps with a unit test > using the ada language server? I've attached the patch. However, I failed to write a unit test. At the end of eglot-handle-request buffer-name shows the expected main.adb, but at the end of the my ert-deftest it is the old, incorrect value. This puzzles my, because if I interactively repeat the test steps, everything is OK. I copy the test code at the end of the email. > Also, can you comment on why you think Alan Donovan's patch has that > non-synchronous find-file mechanism? Since Alan, doesn't reply, what do > you conjecture is the reason his patch goes through this trouble? > > I'd also like someone to address my comments of that patch, which is > similar to yours: > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D62116#10. Among others > > 1. if you think the Emacs frame should be raised and/or focused when a > window.showDocument comes in. I always use Emacs in single frame, so I have no experience in this area, but I don't understand why x-focus-frame is necessary. The showDocument request should not come out of the blue, and if the user is actively working on a source file, the frame is already in focus. > 2. if browse-url should be used for non-file: urls (it might open a > browser window outside of Emacs, which IMO is fine.) My original patch used browse-url as well. browse-url is highly customizable, and I think it is right thing to use here. Users can customize it to relay the URL to eww, firefox, etc even for specific URLs. If I understand it correctly, you argued that if takeFocus is false, Eglot should still show the requested file, but the point should remain were it was. I think you're right, but I haven't updated my patch yet. Alan's patch also contains a recenter call, which I think is unnecessary and would probably annoy me, when the target point was already visible before the showDocument request. On the other hand, if the showDocument request contains a selection, both patches could be enhanced to better visualize this selection. Because of the timers, Alan's eglot-handle-request returns success even if the inner lambda fails. It should probably check if filename exists before calling run-with-idle-timer. However, I don't like approach of using timers. I think a better alterative is to put a modified lambda function in an event queue, and Eglot should process the queue after it sent its reply to the client request. Finally, I think Alan's copyright status is still unclear. And this is the my failed attempt at writing a test: (ert-deftest eglot-test-window/showDocument () "Test handling a window/showDocument server request." (skip-unless (executable-find "ada_language_server")) (let (server) (eglot--with-fixture '(("project" . (("project.gpr" . "Project P is\n for Main use (\"main.adb\");\nend P;") ("main.ads" . "procedure Main;") ("main.adb" . "procedure Main is null;")))) (with-current-buffer (eglot--find-file-noselect "project/main.ads") (eglot--sniffing (:server-requests s-requests :server-replies s-replies :client-requests c-requests :client-replies c-replies) (should (setq server (eglot--tests-connect))) (eglot-execute-command server "als-other-file" (vector (eglot--TextDocumentIdentifier))) (let (cmd-id show-doc-id) (eglot--wait-for (c-requests 2) (&key id method &allow-other-keys) (setq cmd-id id) (string=3D method "workspace/executeCommand")) (eglot--wait-for (s-requests 2) (&key id method &allow-other-keys) (setq show-doc-id id) (string=3D method "window/showDocument")) (eglot--wait-for (c-replies 1) (&key id error &allow-other-keys) (and (eq id show-doc-id) (null error))) (eglot--wait-for (s-replies 1) (&key id &allow-other-keys) (eq id cmd-id)))) (should (string-equal (buffer-name) "main.adb")))))) --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Eglot-support-window-showDocument-request.patch >From 468a8104183ba46f92d0a194862761c81943c505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= Date: Sat, 22 Apr 2023 10:49:17 +0200 Subject: [PATCH] Eglot: support window/showDocument request * eglot.el (eglot-client-capabilities): Add showDocument support. (eglot-handle-request window/showDocument): New cl-defmethod. --- lisp/progmodes/eglot.el | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 3134d55fc0..daabb4ff7b 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -830,7 +830,8 @@ eglot-client-capabilities `(:valueSet [,@(mapcar #'car eglot--tag-faces)]))) - :window `(:workDoneProgress t) + :window `(:showDocument (:support t) + :workDoneProgress t) :general (list :positionEncodings ["utf-32" "utf-8" "utf-16"]) :experimental eglot--{}))) @@ -2345,6 +2346,28 @@ eglot-handle-request "Handle server request workspace/workspaceFolders." (eglot-workspace-folders server)) +(cl-defmethod eglot-handle-request + (_server (_method (eql window/showDocument)) &key + uri external takeFocus selection) + "Handle request window/showDocument." + (if (eq external t) + (browse-url uri) + (let ((filename (eglot--uri-to-path uri))) + (if (eq takeFocus t) + (find-file filename) + (find-file-noselect filename)) + (when selection + (with-current-buffer (get-file-buffer filename) + (save-restriction + (widen) + (pcase-let ((`(,beg . ,end) (eglot--range-region selection))) + (if (equal beg end) + (goto-char beg) + (goto-char end) + (set-mark-command nil) + (goto-char beg)))))))) + '(:success t)) + (defun eglot--TextDocumentIdentifier () "Compute TextDocumentIdentifier object for current buffer." `(:uri ,(eglot--path-to-uri (or buffer-file-name -- 2.30.2 --=-=-=--