Skip to content

Commit 96e670a

Browse files
committed
Fix lsp-ui-doc-glance not auto-hide for inline doc
1 parent 8d4fa5a commit 96e670a

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

lsp-ui-doc.el

+30-30
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ Because some variables are buffer local.")
242242
(defvar-local lsp-ui-doc--from-mouse nil
243243
"Non nil when the doc was triggered by a mouse event.")
244244
(defvar-local lsp-ui-doc--from-mouse-current nil
245-
"Non nil when the current call is triggered by a mouse event.")
246-
(defvar-local lsp-ui-doc--hide-on-next-command nil
247-
"Non-nil when the current document should ask to hide after next command.")
248-
245+
"Non nil when the current call is triggered by a mouse event")
249246

250247
(defconst lsp-ui-doc--buffer-prefix " *lsp-ui-doc-")
251248

@@ -297,7 +294,8 @@ Because some variables are buffer local.")
297294

298295
(defsubst lsp-ui-doc--inline-visible-p ()
299296
"Return inline documentation visibility."
300-
(and (overlayp lsp-ui-doc--inline-ov) (overlay-buffer lsp-ui-doc--inline-ov)))
297+
(and (overlayp lsp-ui-doc--inline-ov)
298+
(overlay-buffer lsp-ui-doc--inline-ov)))
301299

302300
(defun lsp-ui-doc--inline-wrapped-line (string)
303301
"Wraps a line of text (STRING) for inline display."
@@ -425,20 +423,15 @@ We don't extract the string that `lps-line' is already displaying."
425423
(-when-let* ((xw (lsp-ui-doc--webkit-get-xwidget)))
426424
(xwidget-webkit-execute-script-rv xw script)))
427425

428-
(defvar-local lsp-ui-doc--unfocus-frame-timer nil)
429-
430426
(defun lsp-ui-doc--hide-frame (&optional _win)
431427
"Hide any documentation frame or overlay."
432428
(setq lsp-ui-doc--bounds nil
433429
lsp-ui-doc--from-mouse nil)
434430
(lsp-ui-util-safe-delete-overlay lsp-ui-doc--inline-ov)
435431
(lsp-ui-util-safe-delete-overlay lsp-ui-doc--highlight-ov)
436-
(remove-hook 'post-command-hook 'lsp-ui-doc--hide-frame)
437432
(when-let ((frame (lsp-ui-doc--get-frame)))
438433
(when (frame-visible-p frame)
439-
(make-frame-invisible frame)))
440-
(setq lsp-ui-doc--unfocus-frame-timer
441-
(run-at-time 0 nil #'lsp-ui-doc-unfocus-frame)))
434+
(make-frame-invisible frame))))
442435

443436
(defun lsp-ui-doc--buffer-width ()
444437
"Calculate the max width of the buffer."
@@ -829,11 +822,10 @@ HEIGHT is the documentation number of lines."
829822
(-let* ((height (lsp-ui-doc--inline-height))
830823
((start . end) (lsp-ui-doc--inline-pos height))
831824
(buffer-string (buffer-substring start end))
832-
(ov (if (overlayp lsp-ui-doc--inline-ov)
833-
(progn
834-
(move-overlay lsp-ui-doc--inline-ov start end)
835-
lsp-ui-doc--inline-ov)
836-
(setq lsp-ui-doc--inline-ov (make-overlay start end)))))
825+
(ov (if (not (overlayp lsp-ui-doc--inline-ov))
826+
(setq lsp-ui-doc--inline-ov (make-overlay start end))
827+
(move-overlay lsp-ui-doc--inline-ov start end)
828+
lsp-ui-doc--inline-ov)))
837829
(overlay-put ov 'face 'default)
838830
(overlay-put ov 'display (lsp-ui-doc--inline-merge buffer-string))
839831
(overlay-put ov 'lsp-ui-doc-inline t)
@@ -932,22 +924,21 @@ HEIGHT is the documentation number of lines."
932924
(lsp--capability "hoverProvider"))
933925
(-if-let (bounds (or (and (symbol-at-point) (bounds-of-thing-at-point 'symbol))
934926
(and (looking-at "[[:graph:]]") (cons (point) (1+ (point))))))
935-
(unless (and (equal lsp-ui-doc--bounds bounds) (not lsp-ui-doc--hide-on-next-command))
927+
(unless (equal lsp-ui-doc--bounds bounds)
936928
(lsp-ui-doc--hide-frame)
937929
(lsp-ui-util-safe-kill-timer lsp-ui-doc--timer)
938930
(setq lsp-ui-doc--timer
939931
(run-with-idle-timer
940932
lsp-ui-doc-delay nil
941-
(let ((buf (current-buffer))
942-
(hide lsp-ui-doc--hide-on-next-command))
933+
(let ((buf (current-buffer)))
943934
(lambda nil
944935
(when (equal buf (current-buffer))
945936
(lsp-request-async
946937
"textDocument/hover"
947938
(lsp--text-document-position-params)
948939
(lambda (hover)
949940
(when (equal buf (current-buffer))
950-
(lsp-ui-doc--callback hover bounds (current-buffer) hide)))
941+
(lsp-ui-doc--callback hover bounds (current-buffer))))
951942
:mode 'tick
952943
:cancel-token :lsp-ui-doc-hover)))))))
953944
(lsp-ui-doc--hide-frame))))
@@ -959,21 +950,17 @@ HEIGHT is the documentation number of lines."
959950
(end (-some-> (lsp:range-end data) lsp--position-to-point)))
960951
(cons start end)))
961952

962-
(lsp-defun lsp-ui-doc--callback ((hover &as &Hover? :contents) bounds buffer hide)
953+
(lsp-defun lsp-ui-doc--callback ((hover &as &Hover? :contents) bounds buffer)
963954
"Process the received documentation.
964955
HOVER is the doc returned by the LS.
965956
BOUNDS are points of the symbol that have been requested.
966-
BUFFER is the buffer where the request has been made.
967-
When HIDE is non-nil, hide the doc on next command."
957+
BUFFER is the buffer where the request has been made."
968958
(let ((bounds (or (lsp-ui-doc--extract-bounds hover) bounds)))
969959
(if (and hover
970960
(>= (point) (car bounds))
971961
(<= (point) (cdr bounds))
972962
(eq buffer (current-buffer)))
973963
(progn
974-
(lsp-ui-util-safe-kill-timer lsp-ui-doc--unfocus-frame-timer)
975-
(when hide
976-
(add-hook 'post-command-hook 'lsp-ui-doc--hide-frame))
977964
(setq lsp-ui-doc--bounds bounds)
978965
(lsp-ui-doc--display
979966
(thing-at-point 'symbol t)
@@ -1024,7 +1011,8 @@ before, or if the new window is the minibuffer."
10241011
(or (not (eq (selected-window) (frame-parameter frame 'lsp-ui-doc--window-origin)))
10251012
(not (eq (window-buffer) (frame-parameter frame 'lsp-ui-doc--buffer-origin))))
10261013
(if on-idle (lsp-ui-doc--hide-frame)
1027-
(lsp-ui-util-safe-kill-timer lsp-ui-doc--timer-on-changes)
1014+
(and (timerp lsp-ui-doc--timer-on-changes)
1015+
(cancel-timer lsp-ui-doc--timer-on-changes))
10281016
(setq lsp-ui-doc--timer-on-changes
10291017
(run-with-idle-timer 0 nil (lambda nil (lsp-ui-doc--on-state-changed frame t))))))))
10301018

@@ -1081,7 +1069,7 @@ Argument WIN is current applying window."
10811069
(goto-char lsp-ui-doc--last-event)
10821070
(let ((lsp-ui-doc-position 'at-point)
10831071
(lsp-ui-doc--from-mouse-current t))
1084-
(lsp-ui-doc--callback hover bounds (current-buffer) nil))))
1072+
(lsp-ui-doc--callback hover bounds (current-buffer)))))
10851073
:mode 'tick
10861074
:cancel-token :lsp-ui-doc-hover))))))
10871075

@@ -1180,11 +1168,23 @@ It is supposed to be called from `lsp-ui--toggle'"
11801168
(interactive)
11811169
(lsp-ui-doc--hide-frame))
11821170

1171+
(defvar-local lsp-ui-doc--unfocus-frame-timer nil)
1172+
(defun lsp-ui-doc--glance-hide-frame ()
1173+
"Hook to hide hover information popup for `lsp-ui-doc-glance'."
1174+
(when (lsp-ui-doc--visible-p)
1175+
(lsp-ui-doc--hide-frame)
1176+
(remove-hook 'post-command-hook 'lsp-ui-doc--glance-hide-frame)
1177+
;; make sure child frame is unfocused
1178+
(setq lsp-ui-doc--unfocus-frame-timer
1179+
(run-at-time 1 nil #'lsp-ui-doc-unfocus-frame))))
1180+
11831181
(defun lsp-ui-doc-glance ()
11841182
"Trigger display hover information popup and hide it on next typing."
11851183
(interactive)
1186-
(let ((lsp-ui-doc--hide-on-next-command t))
1187-
(lsp-ui-doc-show)))
1184+
(remove-hook 'post-command-hook 'lsp-ui-doc--glance-hide-frame)
1185+
(lsp-ui-doc-show)
1186+
(lsp-ui-util-safe-kill-timer lsp-ui-doc--unfocus-frame-timer)
1187+
(add-hook 'post-command-hook 'lsp-ui-doc--glance-hide-frame))
11881188

11891189
(define-minor-mode lsp-ui-doc-frame-mode
11901190
"Marker mode to add additional key bind for lsp-ui-doc-frame."

0 commit comments

Comments
 (0)