bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#62116: RFE: eglot: support window.showDocument LSP RPC


From: João Távora
Subject: bug#62116: RFE: eglot: support window.showDocument LSP RPC
Date: Sat, 13 May 2023 12:57:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Felician Nemeth <felician.nemeth@gmail.com> 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ão





reply via email to

[Prev in Thread] Current Thread [Next in Thread]