lsp-ui icon indicating copy to clipboard operation
lsp-ui copied to clipboard

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

Open thomasheartman opened this issue 1 year ago • 6 comments

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

  • OS: macOS
  • emacs version: GNU Emacs 28.1 (build 1, aarch64-apple-darwin21.3.0, NS appkit-2113.30 Version 12.2.1 (Build 21D62))
  • lsp-ui version: a94bcec2071ee196bc83e52ad92ec0881f8bcfbd
  • lsp-mode: 5e511babdeda47552e56396dd05dfb86eaabeefd

thomasheartman avatar Aug 08 '22 07:08 thomasheartman

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.

Lenbok avatar Aug 08 '22 21:08 Lenbok

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?

thomasheartman avatar Aug 09 '22 06:08 thomasheartman

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?

Lenbok avatar Aug 09 '22 19:08 Lenbok

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:

  • top: at the very top of the function, before anything else can evaluate
  • middle: before calling lsp-ui-doc--hide-frame and setting the timer
  • lambda: within the timer callback function

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?

thomasheartman avatar Aug 09 '22 21:08 thomasheartman

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.

Lenbok avatar Aug 10 '22 23:08 Lenbok

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:

  • If I idle the cursor at a symbol for n seconds (lsp-ui-doc-delay), the doc should pop up
  • If I explicitly invoke a show or glance, then the doc should pop up immediately.

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?

thomasheartman avatar Aug 11 '22 06:08 thomasheartman