emacs-lsp / lsp-ui

UI integrations for lsp-mode
https://emacs-lsp.github.io/lsp-ui
GNU General Public License v3.0
1.03k stars 141 forks source link

`lsp-ui-doc-delay` also applies to `lsp-ui-doc-glance`/`-show` #728

Open thomasheartman opened 1 year ago

thomasheartman commented 1 year ago

Description and expectations

The variable lsp-ui-doc-delay controls how long you need to idle before the lsp-ui-doc popup shows up. However, it also seems to affect how long it takes before the doc pops up when you explicitly trigger the doc, which is unexpected.

So for instance, if I run lsp-ui-doc-glance in a buffer, it'll only show after lsp-ui-doc-delay seconds. This seems like strange behavior. I would expect that when you manually trigger it, it'd show immediately.

Additional info

I did some digging, and I found this defun which is used by both lsp-ui-doc-glance and lsp-ui-doc-show. It should (as far as I can tell), set lsp-ui-doc-delay to 0 for the lsp-ui-doc--make-request function.

(defun lsp-ui-doc-show ()
  "Trigger display hover information popup."
  (interactive)
  (let ((lsp-ui-doc-show-with-cursor t)
        (lsp-ui-doc-delay 0))
    (lsp-ui-doc--make-request)))

I'm not very experienced at debugging elisp, but I put a message call within the lsp-ui-doc--make-request function and evaluated the defun. Whenever I invoked the lsp-ui-doc-glance function, it would tell me that lsp-ui-doc-delay was whatever it was usually set to (and definitely not 0). So for some reason, it seems that this variable doesn't apply correctly.


Do you know what's going on here? I'd be happy to share any other details if you need anything. Thank you!

System details

Lenbok commented 1 year ago

Can you double check you are actually using lsp-ui version https://github.com/emacs-lsp/lsp-ui/commit/a94bcec2071ee196bc83e52ad92ec0881f8bcfbd or higher? Prior to that version I would expect the delay you are seeing, but that commit fixed the issue, and indeed it works correctly for me.

thomasheartman commented 1 year ago

Thanks for the response 😄 As far as I can tell, I am indeed using version 494bcec or higher. At least M-x find-library lsp-ui takes me to a straight repo currently on version 8d4fa5a14f5b5c6f57bc69f454eba6861ed2ba9f. I closed and reopened emacs to make sure I didn't have an older version lying around, but no dice, I'm afraid. Would you like me to double check in some other way?

Lenbok commented 1 year ago

Perhaps put a similar message inside the lets in both lsp-ui-doc-glance and lsp-ui-doc-show to trace a little more. Does directly calling lsp-ui-doc-show also exhibit the delay before the doc appears?

thomasheartman commented 1 year ago

Sure thing! And yeah, calling lsp-ui-doc-show directly gives the same delay.

Logs

Here's some 'log' output. For glance and show, the log message is within their let blocks, before calling their final function. For the make-request function, I added three different log lines:

lsp-ui-doc-glance

lsp-ui-doc-glance | lsp-ui-doc-delay: 2
lsp-ui-doc-show | lsp-ui-doc-delay: 0
lsp-ui-doc--make-request (top) | lsp-ui-doc-delay: 0
lsp-ui-doc--make-request (middle) | lsp-ui-doc-delay: 0
lsp-ui-doc--make-request (top) | lsp-ui-doc-delay: 2
lsp-ui-doc--make-request (middle) | lsp-ui-doc-delay: 2
lsp-ui-doc--make-request (top) | lsp-ui-doc-delay: 2
lsp-ui-doc--make-request (lambda) | lsp-ui-doc-delay: 2

Interestingly, it seems as if lsp-ui-doc--make-request is called multiple times with different doc delay values.

lsp-ui-doc-show

lsp-ui-doc-show | lsp-ui-doc-delay: 0
lsp-ui-doc--make-request (top) | lsp-ui-doc-delay: 0
lsp-ui-doc--make-request (middle) | lsp-ui-doc-delay: 0
lsp-ui-doc--make-request (top) | lsp-ui-doc-delay: 2
lsp-ui-doc--make-request (middle) | lsp-ui-doc-delay: 2
lsp-ui-doc--make-request (lambda) | lsp-ui-doc-delay: 2

This seems to work the exact same as with glance, except it doesn't have the initial glance call.


From what I can make out, there is something that happens after the first request has started, which invokes make-request again with a different timeout. Presumably this also resets the popup, so it doesn't show. Does this sound familiar at all?

Lenbok commented 1 year ago

The trace suggests that the show/glance popup is getting dismissed immediately and then you are seeing a popup initiated via lsp-ui-doc-mode cursor hover (since that also triggers calls to lsp-ui-doc--make-request, but without overriding the delay). Are you using lsp-ui-doc-show-with-cursor? Try turning it and/or lsp-ui-doc-mode off.

thomasheartman commented 1 year ago

Ah, okay, that might explain it indeed. And yeah, I am using lsp-ui-doc-show-with-cursor. Turning that off fixes the removes the delay when called directly. Thanks!

I realize I wasn't completely clear about this in my opening post, so sorry for the confusion. A bit late, but here's my use case / what I want to achieve:

In other words, I'd like to leave lsp-ui-doc-show-with-cursor on, so that the doc pops up automatically after a timeout. At the same time, I'd like to be able to invoke it explicitly and have it show up immediately.

Is that possible at the moment or is that not supported?