@@ -242,7 +242,10 @@ 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" 
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+ 
246249
247250(defconst  lsp-ui-doc--buffer-prefix  "  *lsp-ui-doc-" 
248251
@@ -292,6 +295,10 @@ Because some variables are buffer local.")
292295; ; Markdown 2.3.
293296(defvar  markdown-fontify-code-block-default-mode )
294297
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+ 
295302(defun  lsp-ui-doc--inline-wrapped-line  (string )
296303  " Wraps a line of text (STRING) for inline display." 
297304  (cond  ((string-empty-p  string) " " 
@@ -418,18 +425,23 @@ We don't extract the string that `lps-line' is already displaying."
418425  (-when-let* ((xw (lsp-ui-doc--webkit-get-xwidget)))
419426    (xwidget-webkit-execute-script-rv xw script)))
420427
428+ (defvar-local  lsp-ui-doc--unfocus-frame-timer nil )
429+ 
421430(defun  lsp-ui-doc--hide-frame  (&optional  _win )
422-   " Hide the  frame." 
431+   " Hide any documentation  frame or overlay ." 
423432  (setq  lsp-ui-doc--bounds nil 
424433        lsp-ui-doc--from-mouse nil )
425434  (lsp-ui-util-safe-delete-overlay lsp-ui-doc--inline-ov)
426435  (lsp-ui-util-safe-delete-overlay lsp-ui-doc--highlight-ov)
436+   (remove-hook  'post-command-hook  'lsp-ui-doc--hide-frame )
427437  (when-let  ((frame (lsp-ui-doc--get-frame)))
428438    (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  )))
430442
431443(defun  lsp-ui-doc--buffer-width  ()
432-   " Calcul  the max width of the buffer." 
444+   " Calculate  the max width of the buffer." 
433445  (lsp-ui-doc--with-buffer
434446    (save-excursion 
435447      (let  ((max  0 ))
@@ -817,16 +829,18 @@ HEIGHT is the documentation number of lines."
817829  (-let* ((height (lsp-ui-doc--inline-height))
818830          ((start .  end) (lsp-ui-doc--inline-pos height))
819831          (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)
821836                (setq  lsp-ui-doc--inline-ov (make-overlay  start end)))))
822-     (move-overlay  ov start end)
823837    (overlay-put  ov 'face  'default )
824838    (overlay-put  ov 'display  (lsp-ui-doc--inline-merge buffer-string))
825839    (overlay-put  ov 'lsp-ui-doc-inline  t )
826840    (overlay-put  ov 'window  (selected-window ))))
827841
828842(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." 
830844  (or  (not  lsp-ui-doc-use-childframe)
831845      (not  (display-graphic-p ))
832846      (not  (fboundp  'display-buffer-in-child-frame ))))
@@ -918,21 +932,22 @@ HEIGHT is the documentation number of lines."
918932             (lsp--capability " hoverProvider" 
919933    (-if-let (bounds (or  (and  (symbol-at-point ) (bounds-of-thing-at-point  'symbol ))
920934                         (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) )
922936          (lsp-ui-doc--hide-frame)
923937          (lsp-ui-util-safe-kill-timer lsp-ui-doc--timer)
924938          (setq  lsp-ui-doc--timer
925939                (run-with-idle-timer 
926940                 lsp-ui-doc-delay nil 
927-                  (let  ((buf (current-buffer )))
941+                  (let  ((buf (current-buffer ))
942+                        (hide lsp-ui-doc--hide-on-next-command))
928943                   (lambda  nil 
929944                     (when  (equal  buf (current-buffer ))
930945                       (lsp-request-async
931946                        " textDocument/hover" 
932947                        (lsp--text-document-position-params)
933948                        (lambda  (hover )
934949                          (when  (equal  buf (current-buffer ))
935-                             (lsp-ui-doc--callback hover bounds (current-buffer ))))
950+                             (lsp-ui-doc--callback hover bounds (current-buffer ) hide )))
936951                        :mode  'tick 
937952                        :cancel-token  :lsp-ui-doc-hover )))))))
938953      (lsp-ui-doc--hide-frame))))
@@ -944,17 +959,21 @@ HEIGHT is the documentation number of lines."
944959               (end (-some->  (lsp:range-end data) lsp--position-to-point)))
945960    (cons  start end)))
946961
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 )
948963  " Process the received documentation.
949964HOVER is the doc returned by the LS. 
950965BOUNDS 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."  
952968  (let  ((bounds (or  (lsp-ui-doc--extract-bounds hover) bounds)))
953969    (if  (and  hover
954970             (>=  (point ) (car  bounds))
955971             (<=  (point ) (cdr  bounds))
956972             (eq  buffer (current-buffer )))
957973        (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 ))
958977          (setq  lsp-ui-doc--bounds bounds)
959978          (lsp-ui-doc--display
960979           (thing-at-point  'symbol  t )
@@ -972,9 +991,8 @@ BUFFER is the buffer where the request has been made."
972991
973992(defun  lsp-ui-doc--visible-p  ()
974993  " 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)))
978996
979997(defun  lsp-ui-doc-hide-frame-on-window-change  (fun  window  &optional  no-record )
980998  " Delete the child frame if currently selected window changes.
@@ -1006,8 +1024,7 @@ before, or if the new window is the minibuffer."
10061024         (or  (not  (eq  (selected-window ) (frame-parameter  frame 'lsp-ui-doc--window-origin )))
10071025             (not  (eq  (window-buffer ) (frame-parameter  frame 'lsp-ui-doc--buffer-origin ))))
10081026         (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)
10111028           (setq  lsp-ui-doc--timer-on-changes
10121029                 (run-with-idle-timer  0  nil  (lambda  nil  (lsp-ui-doc--on-state-changed frame t ))))))))
10131030
@@ -1064,16 +1081,15 @@ Argument WIN is current applying window."
10641081               (goto-char  lsp-ui-doc--last-event)
10651082               (let  ((lsp-ui-doc-position 'at-point )
10661083                     (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 ))))
10681085           :mode  'tick 
10691086           :cancel-token  :lsp-ui-doc-hover ))))))
10701087
10711088(defun  lsp-ui-doc--handle-mouse-movement  (event )
10721089  " Show the documentation corresponding to the text under EVENT." 
10731090  (interactive  " e" 
10741091  (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)
10771093    (let*  ((e (cadr  event))
10781094           (point  (posn-point  e))
10791095           (same-win (eq  (selected-window ) (posn-window  e))))
@@ -1155,34 +1171,20 @@ It is supposed to be called from `lsp-ui--toggle'"
11551171(defun  lsp-ui-doc-show  ()
11561172  " Trigger display hover information popup." 
11571173  (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 )))
11611177
11621178(defun  lsp-ui-doc-hide  ()
11631179  " Hide hover information popup." 
11641180  (interactive )
11651181  (lsp-ui-doc--hide-frame))
11661182
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- 
11781183(defun  lsp-ui-doc-glance  ()
11791184  " Trigger display hover information popup and hide it on next typing." 
11801185  (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)))
11861188
11871189(define-minor-mode  lsp-ui-doc-frame-mode
11881190  " Marker mode to add additional key bind for lsp-ui-doc-frame." 
0 commit comments