@@ -242,7 +242,10 @@ Because some variables are buffer local.")
242
242
(defvar-local lsp-ui-doc--from-mouse nil
243
243
" Non nil when the doc was triggered by a mouse event." )
244
244
(defvar-local lsp-ui-doc--from-mouse-current nil
245
- " Non nil when the current call is triggered by a mouse event" )
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
+
246
249
247
250
(defconst lsp-ui-doc--buffer-prefix " *lsp-ui-doc-" )
248
251
@@ -292,6 +295,10 @@ Because some variables are buffer local.")
292
295
; ; Markdown 2.3.
293
296
(defvar markdown-fontify-code-block-default-mode )
294
297
298
+ (defsubst lsp-ui-doc--inline-visible-p ()
299
+ " Return inline documentation visibility."
300
+ (and (overlayp lsp-ui-doc--inline-ov) (overlay-buffer lsp-ui-doc--inline-ov)))
301
+
295
302
(defun lsp-ui-doc--inline-wrapped-line (string )
296
303
" Wraps a line of text (STRING) for inline display."
297
304
(cond ((string-empty-p string) " " )
@@ -418,18 +425,23 @@ We don't extract the string that `lps-line' is already displaying."
418
425
(-when-let* ((xw (lsp-ui-doc--webkit-get-xwidget)))
419
426
(xwidget-webkit-execute-script-rv xw script)))
420
427
428
+ (defvar-local lsp-ui-doc--unfocus-frame-timer nil )
429
+
421
430
(defun lsp-ui-doc--hide-frame (&optional _win )
422
- " Hide the frame."
431
+ " Hide any documentation frame or overlay ."
423
432
(setq lsp-ui-doc--bounds nil
424
433
lsp-ui-doc--from-mouse nil )
425
434
(lsp-ui-util-safe-delete-overlay lsp-ui-doc--inline-ov)
426
435
(lsp-ui-util-safe-delete-overlay lsp-ui-doc--highlight-ov)
436
+ (remove-hook 'post-command-hook 'lsp-ui-doc--hide-frame )
427
437
(when-let ((frame (lsp-ui-doc--get-frame)))
428
438
(when (frame-visible-p frame)
429
- (make-frame-invisible 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 )))
430
442
431
443
(defun lsp-ui-doc--buffer-width ()
432
- " Calcul the max width of the buffer."
444
+ " Calculate the max width of the buffer."
433
445
(lsp-ui-doc--with-buffer
434
446
(save-excursion
435
447
(let ((max 0 ))
@@ -817,16 +829,18 @@ HEIGHT is the documentation number of lines."
817
829
(-let* ((height (lsp-ui-doc--inline-height))
818
830
((start . end) (lsp-ui-doc--inline-pos height))
819
831
(buffer-string (buffer-substring start end))
820
- (ov (if (overlayp lsp-ui-doc--inline-ov) lsp-ui-doc--inline-ov
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)
821
836
(setq lsp-ui-doc--inline-ov (make-overlay start end)))))
822
- (move-overlay ov start end)
823
837
(overlay-put ov 'face 'default )
824
838
(overlay-put ov 'display (lsp-ui-doc--inline-merge buffer-string))
825
839
(overlay-put ov 'lsp-ui-doc-inline t )
826
840
(overlay-put ov 'window (selected-window ))))
827
841
828
842
(defun lsp-ui-doc--inline-p ()
829
- " Return non-nil when the documentation should be display without a child frame."
843
+ " Return non-nil when the documentation should be displayed without a child frame."
830
844
(or (not lsp-ui-doc-use-childframe)
831
845
(not (display-graphic-p ))
832
846
(not (fboundp 'display-buffer-in-child-frame ))))
@@ -918,21 +932,22 @@ HEIGHT is the documentation number of lines."
918
932
(lsp--capability " hoverProvider" ))
919
933
(-if-let (bounds (or (and (symbol-at-point ) (bounds-of-thing-at-point 'symbol ))
920
934
(and (looking-at " [[:graph:]]" ) (cons (point ) (1+ (point ))))))
921
- (unless (equal lsp-ui-doc--bounds bounds)
935
+ (unless (and ( equal lsp-ui-doc--bounds bounds) ( not lsp-ui-doc--hide-on-next-command) )
922
936
(lsp-ui-doc--hide-frame)
923
937
(lsp-ui-util-safe-kill-timer lsp-ui-doc--timer)
924
938
(setq lsp-ui-doc--timer
925
939
(run-with-idle-timer
926
940
lsp-ui-doc-delay nil
927
- (let ((buf (current-buffer )))
941
+ (let ((buf (current-buffer ))
942
+ (hide lsp-ui-doc--hide-on-next-command))
928
943
(lambda nil
929
944
(when (equal buf (current-buffer ))
930
945
(lsp-request-async
931
946
" textDocument/hover"
932
947
(lsp--text-document-position-params)
933
948
(lambda (hover )
934
949
(when (equal buf (current-buffer ))
935
- (lsp-ui-doc--callback hover bounds (current-buffer ))))
950
+ (lsp-ui-doc--callback hover bounds (current-buffer ) hide )))
936
951
:mode 'tick
937
952
:cancel-token :lsp-ui-doc-hover )))))))
938
953
(lsp-ui-doc--hide-frame))))
@@ -944,17 +959,21 @@ HEIGHT is the documentation number of lines."
944
959
(end (-some-> (lsp:range-end data) lsp--position-to-point)))
945
960
(cons start end)))
946
961
947
- (lsp-defun lsp-ui-doc--callback ((hover &as &Hover? :contents ) bounds buffer)
962
+ (lsp-defun lsp-ui-doc--callback ((hover &as &Hover? :contents ) bounds buffer hide )
948
963
" Process the received documentation.
949
964
HOVER is the doc returned by the LS.
950
965
BOUNDS are points of the symbol that have been requested.
951
- BUFFER is the buffer where the request has been made."
966
+ BUFFER is the buffer where the request has been made.
967
+ When HIDE is non-nil, hide the doc on next command."
952
968
(let ((bounds (or (lsp-ui-doc--extract-bounds hover) bounds)))
953
969
(if (and hover
954
970
(>= (point ) (car bounds))
955
971
(<= (point ) (cdr bounds))
956
972
(eq buffer (current-buffer )))
957
973
(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 ))
958
977
(setq lsp-ui-doc--bounds bounds)
959
978
(lsp-ui-doc--display
960
979
(thing-at-point 'symbol t )
@@ -972,9 +991,8 @@ BUFFER is the buffer where the request has been made."
972
991
973
992
(defun lsp-ui-doc--visible-p ()
974
993
" Return whether the LSP UI doc is visible"
975
- (or (overlayp lsp-ui-doc--inline-ov)
976
- (and (lsp-ui-doc--get-frame)
977
- (frame-visible-p (lsp-ui-doc--get-frame)))))
994
+ (or (lsp-ui-doc--inline-visible-p)
995
+ (lsp-ui-doc--frame-visible-p)))
978
996
979
997
(defun lsp-ui-doc-hide-frame-on-window-change (fun window &optional no-record )
980
998
" Delete the child frame if currently selected window changes.
@@ -1006,8 +1024,7 @@ before, or if the new window is the minibuffer."
1006
1024
(or (not (eq (selected-window ) (frame-parameter frame 'lsp-ui-doc--window-origin )))
1007
1025
(not (eq (window-buffer ) (frame-parameter frame 'lsp-ui-doc--buffer-origin ))))
1008
1026
(if on-idle (lsp-ui-doc--hide-frame)
1009
- (and (timerp lsp-ui-doc--timer-on-changes)
1010
- (cancel-timer lsp-ui-doc--timer-on-changes))
1027
+ (lsp-ui-util-safe-kill-timer lsp-ui-doc--timer-on-changes)
1011
1028
(setq lsp-ui-doc--timer-on-changes
1012
1029
(run-with-idle-timer 0 nil (lambda nil (lsp-ui-doc--on-state-changed frame t ))))))))
1013
1030
@@ -1064,16 +1081,15 @@ Argument WIN is current applying window."
1064
1081
(goto-char lsp-ui-doc--last-event)
1065
1082
(let ((lsp-ui-doc-position 'at-point )
1066
1083
(lsp-ui-doc--from-mouse-current t ))
1067
- (lsp-ui-doc--callback hover bounds (current-buffer )))))
1084
+ (lsp-ui-doc--callback hover bounds (current-buffer ) nil ))))
1068
1085
:mode 'tick
1069
1086
:cancel-token :lsp-ui-doc-hover ))))))
1070
1087
1071
1088
(defun lsp-ui-doc--handle-mouse-movement (event )
1072
1089
" Show the documentation corresponding to the text under EVENT."
1073
1090
(interactive " e" )
1074
1091
(when lsp-ui-doc-show-with-mouse
1075
- (and (timerp lsp-ui-doc--timer-mouse-movement)
1076
- (cancel-timer lsp-ui-doc--timer-mouse-movement))
1092
+ (lsp-ui-util-safe-kill-timer lsp-ui-doc--timer-mouse-movement)
1077
1093
(let* ((e (cadr event))
1078
1094
(point (posn-point e))
1079
1095
(same-win (eq (selected-window ) (posn-window e))))
@@ -1155,34 +1171,20 @@ It is supposed to be called from `lsp-ui--toggle'"
1155
1171
(defun lsp-ui-doc-show ()
1156
1172
" Trigger display hover information popup."
1157
1173
(interactive )
1158
- (lsp-ui-doc--callback (lsp-request " textDocument/hover " (lsp--text-document-position-params) )
1159
- ( or ( bounds-of-thing-at-point 'symbol ) ( cons ( point ) ( 1+ ( point )) ))
1160
- ( current-buffer )))
1174
+ (let ( (lsp-ui-doc-show-with-cursor t )
1175
+ (lsp-ui-doc-delay 0 ))
1176
+ (lsp-ui-doc--make-request )))
1161
1177
1162
1178
(defun lsp-ui-doc-hide ()
1163
1179
" Hide hover information popup."
1164
1180
(interactive )
1165
1181
(lsp-ui-doc--hide-frame))
1166
1182
1167
- (defvar-local lsp-ui-doc--unfocus-frame-timer nil )
1168
- (defun lsp-ui-doc--glance-hide-frame ()
1169
- " Hook to hide hover information popup for `lsp-ui-doc-glance' ."
1170
- (when (or (overlayp lsp-ui-doc--inline-ov)
1171
- (lsp-ui-doc--frame-visible-p))
1172
- (lsp-ui-doc--hide-frame)
1173
- (remove-hook 'post-command-hook 'lsp-ui-doc--glance-hide-frame )
1174
- ; ; make sure child frame is unfocused
1175
- (setq lsp-ui-doc--unfocus-frame-timer
1176
- (run-at-time 1 nil #'lsp-ui-doc-unfocus-frame ))))
1177
-
1178
1183
(defun lsp-ui-doc-glance ()
1179
1184
" Trigger display hover information popup and hide it on next typing."
1180
1185
(interactive )
1181
- (let ((lsp-ui-doc-show-with-cursor t ))
1182
- (lsp-ui-doc--make-request))
1183
- (when lsp-ui-doc--unfocus-frame-timer
1184
- (cancel-timer lsp-ui-doc--unfocus-frame-timer))
1185
- (add-hook 'post-command-hook 'lsp-ui-doc--glance-hide-frame ))
1186
+ (let ((lsp-ui-doc--hide-on-next-command t ))
1187
+ (lsp-ui-doc-show)))
1186
1188
1187
1189
(define-minor-mode lsp-ui-doc-frame-mode
1188
1190
" Marker mode to add additional key bind for lsp-ui-doc-frame."
0 commit comments