Skip to content

Commit

Permalink
fix(doc): Hovering tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Apr 18, 2024
1 parent 16bdff6 commit b1c1536
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions lsp-ui-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ FN is the function to call on click."
(when (< fill-column (length first-line))
(fill-region start (point-max))))))

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

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

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

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

(defun lsp-ui-doc--highlight-hover nil
(defun lsp-ui-doc--highlight-hover ()
(when lsp-ui-doc--from-mouse-current
(-let* (((start . end) lsp-ui-doc--bounds)
(ov (if (overlayp lsp-ui-doc--highlight-ov) lsp-ui-doc--highlight-ov
Expand Down Expand Up @@ -930,9 +930,10 @@ HEIGHT is the documentation number of lines."
keyboard-quit
ignore
handle-switch-frame
mwheel-scroll))
mwheel-scroll)
"List of command to ignore requests.")

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

(defun lsp-ui-doc--tooltip-mouse-motion (event)
"Default tooltip (EVENT) action."
(interactive "e")
(tooltip-hide)
(when (car (mouse-pixel-position))
(tooltip-start-delayed-tip)
(setq tooltip-last-mouse-motion-event event)))

(defun lsp-ui-doc--handle-mouse-movement (event)
"Show the documentation corresponding to the text under EVENT."
(interactive "e")
(lsp-ui-doc--tooltip-mouse-motion event)
(when lsp-ui-doc-show-with-mouse
(lsp-ui-util-safe-kill-timer lsp-ui-doc--timer-mouse-movement)
(let* ((e (cadr event))
Expand Down Expand Up @@ -1128,22 +1138,32 @@ Argument WIN is current applying window."
"Nil if `track-mouse' was set by another package.
If nil, do not prevent mouse on prefix keys.")

(defun lsp-ui-doc--setup-mouse nil
(when lsp-ui-doc-show-with-mouse
(defvar lsp-ui-doc-mode-map
(let ((map (make-sparse-keymap)))
map)
"Keymap for `lsp-ui-doc-mode'.")

(defun lsp-ui-doc--setup-mouse ()
"Setup mouse."
(cond
(lsp-ui-doc-show-with-mouse
(define-key lsp-ui-doc-mode-map (kbd "<mouse-movement>") #'lsp-ui-doc--handle-mouse-movement)
(setq lsp-ui-doc--mouse-tracked-by-us (not track-mouse))
(setq-local track-mouse t)
(unless lsp-ui-doc--timer-mouse-idle
;; Set only 1 timer for all buffers
(setq lsp-ui-doc--timer-mouse-idle
(run-with-idle-timer 0 t 'lsp-ui-doc--disable-mouse-on-prefix)))))
(run-with-idle-timer 0 t 'lsp-ui-doc--disable-mouse-on-prefix))))
(t
(define-key lsp-ui-doc-mode-map (kbd "<mouse-movement>") nil))))

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

(define-minor-mode lsp-ui-doc-mode
"Minor mode for showing hover information in child frame."
:init-value nil
:keymap `((,(kbd "<mouse-movement>") . lsp-ui-doc--handle-mouse-movement))
:keymap lsp-ui-doc-mode-map
:group lsp-ui-doc
(cond
(lsp-ui-doc-mode
Expand Down

0 comments on commit b1c1536

Please sign in to comment.