From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#62116: RFE: eglot: support window.showDocument LSP RPC Date: Sat, 13 May 2023 12:57:38 +0100 Message-ID: <87wn1c4f65.fsf@gmail.com> 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> <87ttwpbpaj.fsf@betli.tmit.bme.hu> <875y93arek.fsf@betli.tmit.bme.hu> <87h6sla14k.fsf@betli.tmit.bme.hu> <871qjm5pzk.fsf@gmail.com> <877ctc8rc9.fsf@betli.tmit.bme.hu> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10871"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: sebastian.poeplau@mailbox.org, adonovan@google.com, 62116@debbugs.gnu.org To: Felician Nemeth Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 13 13:56:10 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 1pxnr8-0002e8-Je for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 May 2023 13:56:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxnr0-00086J-Tv; Sat, 13 May 2023 07:56: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 1pxnr0-00086B-9R for bug-gnu-emacs@gnu.org; Sat, 13 May 2023 07:56:02 -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 1pxnr0-0001Qd-0K for bug-gnu-emacs@gnu.org; Sat, 13 May 2023 07:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pxnqz-0001Bu-K9 for bug-gnu-emacs@gnu.org; Sat, 13 May 2023 07:56:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 May 2023 11:56: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.16839789334508 (code B ref 62116); Sat, 13 May 2023 11:56:01 +0000 Original-Received: (at 62116) by debbugs.gnu.org; 13 May 2023 11:55:33 +0000 Original-Received: from localhost ([127.0.0.1]:36160 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxnqW-0001Ab-HR for submit@debbugs.gnu.org; Sat, 13 May 2023 07:55:32 -0400 Original-Received: from mail-wr1-f43.google.com ([209.85.221.43]:54275) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxnqV-00019w-9X for 62116@debbugs.gnu.org; Sat, 13 May 2023 07:55:31 -0400 Original-Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3062db220a3so7095662f8f.0 for <62116@debbugs.gnu.org>; Sat, 13 May 2023 04:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683978925; x=1686570925; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HJ+sf3yeL56hR1uAmKJulbGwnUZ/jH42l7jsE45wGdM=; b=m+vcsy8E2oUdX/7NWFy3UK3c2e9/4I5UNwaS8O9cEzv+PmHsX1YTjImjVIxLRywLj+ qEDxtpW6qIm6oLx1n7mVYC07nK+VoRE2XHgSbiUxaBeqkDD4O8abEYr/tU04sYlycnkd okO6zD+0oXAUKtJKd6Jd8NasyUFsiof40VlkR/YHllSaH8Sv4IBFaDxzz8myGs+V7hRG OS3iUVTkXSjrbmoZ37UhYZFbMQI+xClkOOdqi/LgbNp07VhDbPP2bLFY40YMZ5xbt+1p NV3xWrCV7DZRmMV0KYHdDq0S1GJi2xulf6CvWFrd7DtxwJqrata9Ynu/WSyqyL5pyywL 7gPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683978925; x=1686570925; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HJ+sf3yeL56hR1uAmKJulbGwnUZ/jH42l7jsE45wGdM=; b=AwX713mE/yfzFihE9l/OSR5BKSYFn/3d3B/yZvs6Eev3fvxzxDduBxkJRr/tX+5qV+ vQfe3+EYUCpqf2+b8A37VAksNgWq/nhx14JM3Pv15Df4Qbh5NpreZogyLaI01gVzldPW avaZHh2xzGIz4LTlCw2xCjqkXB/NLRoBbNt9F0JaL8sf7T0o1XSvIyCqV5vvEgQddE4f cLDEIywAKfv/6L5PfeeD6aFUTyDPOlfIMLetgYt8AJJd5K85cDS/T13TeDDvjlQPct3O uISKDW0H5mdp0P3qnT9thRUqkZK7Xr+YICp+GqD2+L1CMWgJNhDoK4g61jdDIvbjGm3A 3vkA== X-Gm-Message-State: AC+VfDzdhrGVaP5wXyeNdrwpLwIIPCLQPchsKwc/Heh14AtHbJqweotx o6caYzX8JynK1ANmssAawFA= X-Google-Smtp-Source: ACHHUZ6blyN/uKzgW8myMyfRrh8F7e5/Y8l0l5j5iBTikTD84dbOK+BN9YNmdcHiaZcSdcj4IjwtFg== X-Received: by 2002:a05:6000:104b:b0:2e4:eebe:aee3 with SMTP id c11-20020a056000104b00b002e4eebeaee3mr17525135wrx.60.1683978925092; Sat, 13 May 2023 04:55:25 -0700 (PDT) Original-Received: from krug (87-196-72-49.net.novis.pt. [87.196.72.49]) by smtp.gmail.com with ESMTPSA id z9-20020a05600c114900b003f4069417absm28747507wmz.24.2023.05.13.04.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 May 2023 04:55:24 -0700 (PDT) In-Reply-To: <877ctc8rc9.fsf@betli.tmit.bme.hu> (Felician Nemeth's message of "Sat, 13 May 2023 12:21:10 +0200") 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:261679 Archived-At: Felician Nemeth writes: >> + uri external takeFocus selection) >> + "Handle request window/showDocument." >> + (if (eq external t) (browse-url uri) >> + (let* (;; requests run with a let-bound `eglot--cached-server', >> + ;; but when finding files from handlers, this fools >> + ;; `eglot--maybe-activate-editing-mode'. >> + (eglot--cached-server nil)) > > (I don't understand this part.) If you look up to near line 1308, you'll notice that the client handlers for server requests run with `eglot--cached-server` let-bound. This, in turn makes every subsequent call to `eglot--maybe-a-e-m` activate the eglot--managed-mode minor mode. There are, unexpectedly, a couple of calls to `eglot--maybe-a-e-m` but that's due to find-file's logic which surprisingly temporarily activates another major mode when finding a file. Apparently this is how it's always been. That first mode is activated by a call to `major-mode` and then is replaced by a call to the actual major-mode function, in this case `go-mode`. >> + (with-current-buffer (find-file-noselect (eglot--uri-to-path uri)) >> + (cond (takeFocus >> + (pop-to-buffer (current-buffer)) > > Somehow switch-to-buffer feels more natural to me. But pop-to-buffer is > probably a better choice. I think you can do `display-buffer-alist` things to control it. >> + (select-frame-set-input-focus (selected-frame))) >> + ((display-buffer (current-buffer)))) > > Even when takeFous is nil, shouldn't we still at least raise the frame? > Otherwise Emacs might not show the document. I don't understand. Can you show this problem. , I think display-buffer ensures the buffer is displayed. It doesn't guarantee that it is visible in the context of the windowing system, but that's another matter. > >> + '(:success t)) > > Regarding Alan's problem, one could argue that it can also be fixed on > the server-side. However, there might be a general, but complex fix on > Emacs' side as well: imenu can be modified to asynchronously generate > its index when it just wants to show it in the menu (and not to users' > direct request). Then the request of :textDocument/documentSymbol can > be non-blocking as well. A simpler fix is to delay the opening of the > file. Yes, right. Making imenu or textDocument/documentSymbol asynchronous would be too complex and async doesn't really fit in there. I think Alan's problem indeed arises with something like imenu being in the major-mode's hook, perhaps on behalf of which-func-mode. But that was never confirmed. In the latest version of the patch I've just put a run-with-timer in the Eglot request handler. It should solve the conjectured Alan problem and also doesn't require the obscure eglot--cached-server hack above. >> I was about to push it, but let's hear your opinions first > It is great, and I'd be happy if it went in as is. Thank you. I pushed a version with the above adjustments to master, as we're converging anyway and it's easier than trading patches. Jo=C3=A3o