Skip to content

Commit 9f53ea2

Browse files
authored
fix(doc): Hovering tooltip (#772)
1 parent 16bdff6 commit 9f53ea2

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

Diff for: lsp-ui-doc.el

+30-10
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ FN is the function to call on click."
662662
(when (< fill-column (length first-line))
663663
(fill-region start (point-max))))))
664664

665-
(defun lsp-ui-doc--make-smaller-empty-lines nil
665+
(defun lsp-ui-doc--make-smaller-empty-lines ()
666666
"Make empty lines half normal lines."
667667
(progn ; Customize line before header
668668
(goto-char 1)
@@ -682,7 +682,7 @@ FN is the function to call on click."
682682
(forward-line))
683683
(insert (propertize "\n\n" 'face '(:height 0.3))))
684684

685-
(defun lsp-ui-doc--fix-hr-props nil
685+
(defun lsp-ui-doc--fix-hr-props ()
686686
;; We insert the right display prop after window-text-pixel-size
687687
(lsp-ui-doc--with-buffer
688688
(let (next)
@@ -767,7 +767,7 @@ FN is the function to call on click."
767767

768768
(defvar-local lsp-ui-doc--inline-width nil)
769769

770-
(defun lsp-ui-doc--inline-window-width nil
770+
(defun lsp-ui-doc--inline-window-width ()
771771
(- (min (window-text-width) (window-body-width))
772772
(if (bound-and-true-p display-line-numbers-mode)
773773
(+ 2 (line-number-display-width))
@@ -854,7 +854,7 @@ HEIGHT is the documentation number of lines."
854854
(not (display-graphic-p))
855855
(not (fboundp 'display-buffer-in-child-frame))))
856856

857-
(defun lsp-ui-doc--highlight-hover nil
857+
(defun lsp-ui-doc--highlight-hover ()
858858
(when lsp-ui-doc--from-mouse-current
859859
(-let* (((start . end) lsp-ui-doc--bounds)
860860
(ov (if (overlayp lsp-ui-doc--highlight-ov) lsp-ui-doc--highlight-ov
@@ -930,9 +930,10 @@ HEIGHT is the documentation number of lines."
930930
keyboard-quit
931931
ignore
932932
handle-switch-frame
933-
mwheel-scroll))
933+
mwheel-scroll)
934+
"List of command to ignore requests.")
934935

935-
(defun lsp-ui-doc--make-request nil
936+
(defun lsp-ui-doc--make-request ()
936937
"Request the documentation to the LS."
937938
(and (not track-mouse) lsp-ui-doc-show-with-mouse (setq-local track-mouse t))
938939
(when (and lsp-ui-doc-show-with-cursor
@@ -1094,9 +1095,18 @@ Argument WIN is current applying window."
10941095
:mode 'tick
10951096
:cancel-token :lsp-ui-doc-hover))))))
10961097

1098+
(defun lsp-ui-doc--tooltip-mouse-motion (event)
1099+
"Default tooltip (EVENT) action."
1100+
(interactive "e")
1101+
(tooltip-hide)
1102+
(when (car (mouse-pixel-position))
1103+
(tooltip-start-delayed-tip)
1104+
(setq tooltip-last-mouse-motion-event event)))
1105+
10971106
(defun lsp-ui-doc--handle-mouse-movement (event)
10981107
"Show the documentation corresponding to the text under EVENT."
10991108
(interactive "e")
1109+
(lsp-ui-doc--tooltip-mouse-motion event)
11001110
(when lsp-ui-doc-show-with-mouse
11011111
(lsp-ui-util-safe-kill-timer lsp-ui-doc--timer-mouse-movement)
11021112
(let* ((e (cadr event))
@@ -1128,22 +1138,32 @@ Argument WIN is current applying window."
11281138
"Nil if `track-mouse' was set by another package.
11291139
If nil, do not prevent mouse on prefix keys.")
11301140

1131-
(defun lsp-ui-doc--setup-mouse nil
1132-
(when lsp-ui-doc-show-with-mouse
1141+
(defvar lsp-ui-doc-mode-map
1142+
(let ((map (make-sparse-keymap)))
1143+
map)
1144+
"Keymap for `lsp-ui-doc-mode'.")
1145+
1146+
(defun lsp-ui-doc--setup-mouse ()
1147+
"Setup mouse."
1148+
(cond
1149+
(lsp-ui-doc-show-with-mouse
1150+
(define-key lsp-ui-doc-mode-map (kbd "<mouse-movement>") #'lsp-ui-doc--handle-mouse-movement)
11331151
(setq lsp-ui-doc--mouse-tracked-by-us (not track-mouse))
11341152
(setq-local track-mouse t)
11351153
(unless lsp-ui-doc--timer-mouse-idle
11361154
;; Set only 1 timer for all buffers
11371155
(setq lsp-ui-doc--timer-mouse-idle
1138-
(run-with-idle-timer 0 t 'lsp-ui-doc--disable-mouse-on-prefix)))))
1156+
(run-with-idle-timer 0 t 'lsp-ui-doc--disable-mouse-on-prefix))))
1157+
(t
1158+
(define-key lsp-ui-doc-mode-map (kbd "<mouse-movement>") nil))))
11391159

11401160
(defun lsp-ui-doc--prevent-focus-doc (e)
11411161
(not (frame-parameter (cadr e) 'lsp-ui-doc--no-focus)))
11421162

11431163
(define-minor-mode lsp-ui-doc-mode
11441164
"Minor mode for showing hover information in child frame."
11451165
:init-value nil
1146-
:keymap `((,(kbd "<mouse-movement>") . lsp-ui-doc--handle-mouse-movement))
1166+
:keymap lsp-ui-doc-mode-map
11471167
:group lsp-ui-doc
11481168
(cond
11491169
(lsp-ui-doc-mode

0 commit comments

Comments
 (0)